packaging: various smaller fixes and corrections

- remove placeholder print statements
* replace wildcard import with a direct one
* rename main class to blimp
* optimized imports
This commit is contained in:
nico 2021-03-28 16:39:58 +02:00
parent 3e8a728fe7
commit c9e689b3f3
Signed by: mightyBroccoli
GPG Key ID: 1F6495B44DABCE6E
5 changed files with 19 additions and 25 deletions

View File

@ -4,11 +4,11 @@
# version # version
__version__ = "0.1" __version__ = "0.1"
# main
from .main import BlacklistImporter
# modules # modules
from .bl_process import ProcessBlocklist from .bl_process import ProcessBlocklist
# main
from .main import Blimp
# utils # utils
from .misc import * from .misc import *

View File

@ -6,7 +6,12 @@ from ruamel.yaml import YAML, scalarstring
from .misc import * from .misc import *
class ProcessBlocklist: class ProcessBlocklist:
def __init__(self):
pass
@classmethod
def process(self, blacklist, outfile, dryrun: bool): def process(self, blacklist, outfile, dryrun: bool):
""" """
function to build and compare the local yaml file to the remote file function to build and compare the local yaml file to the remote file
@ -19,8 +24,6 @@ class ProcessBlocklist:
with open(outfile, "r", encoding="utf-8") as local_file: with open(outfile, "r", encoding="utf-8") as local_file:
local_blacklist = local_file.read() local_blacklist = local_file.read()
print("step local file")
except TypeError: except TypeError:
# no local copy use empty one instead # no local copy use empty one instead
local_blacklist = YAML(typ="safe") local_blacklist = YAML(typ="safe")

View File

@ -3,7 +3,7 @@
import argparse import argparse
from .main import BlacklistImporter from .main import Blimp
def cli(): def cli():
@ -13,4 +13,4 @@ def cli():
args = parser.parse_args() args = parser.parse_args()
# run # run
BlacklistImporter(args).main() Blimp(args).main()

View File

@ -1,16 +1,14 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import argparse
import requests import requests
from appdirs import * from appdirs import user_cache_dir
from .bl_process import ProcessBlocklist from .bl_process import ProcessBlocklist
from .misc import * from .misc import *
class BlacklistImporter: class Blimp:
def __init__(self, args): def __init__(self, args):
self.outfile = args.outfile self.outfile = args.outfile
self.dryrun = args.dry_run self.dryrun = args.dry_run
@ -89,9 +87,10 @@ class BlacklistImporter:
self.start_request() self.start_request()
# blacklist processing # blacklist processing
ProcessBlocklist().process(self.blacklist, self.outfile, self.dryrun) ProcessBlocklist.process(self.blacklist, self.outfile, self.dryrun)
"""# reload config if changes have been applied """
# reload config if changes have been applied
if self.change: if self.change:
# catch ejabberdctl missing # catch ejabberdctl missing
if Path("/usr/sbin/ejabberdctl").is_file(): if Path("/usr/sbin/ejabberdctl").is_file():
@ -106,10 +105,5 @@ class BlacklistImporter:
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser() from .cli import cli
parser.add_argument("-out", "--outfile", help="set path to output file", action="store", default=None) cli()
parser.add_argument("-dr", "--dry-run", help="perform a dry run", action="store_true", default=False)
args = parser.parse_args()
# run
BlacklistImporter(args).main()

View File

@ -5,13 +5,10 @@ from pathlib import Path
def local_file_present(somepath) -> bool: def local_file_present(somepath) -> bool:
""" """
check local etag copy check if a given local filepath exists
:return: true if present :return: true if present
""" """
if not Path(somepath).is_file(): if not Path(somepath).is_file():
return False return False
return True return True
def asd():
print("yo")