From 9d33105970cb2bae4aefc2c9f09f0aaf02800a83 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 22 Jun 2022 22:05:56 +0300 Subject: [PATCH] Switch from json to yaml configs --- configs/blacklist.json | 3 --- configs/blacklist.yaml | 2 ++ configs/slpkg.json | 23 ----------------------- configs/slpkg.yaml | 22 ++++++++++++++++++++++ slpkg/blacklist.py | 6 +++--- slpkg/configs.py | 12 ++++++++---- slpkg/main.py | 7 +++---- 7 files changed, 38 insertions(+), 37 deletions(-) delete mode 100644 configs/blacklist.json create mode 100644 configs/blacklist.yaml delete mode 100644 configs/slpkg.json create mode 100644 configs/slpkg.yaml diff --git a/configs/blacklist.json b/configs/blacklist.json deleted file mode 100644 index 550bdb9c..00000000 --- a/configs/blacklist.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "blacklist": [] -} \ No newline at end of file diff --git a/configs/blacklist.yaml b/configs/blacklist.yaml new file mode 100644 index 00000000..348c014f --- /dev/null +++ b/configs/blacklist.yaml @@ -0,0 +1,2 @@ +blacklist: + packages: [] diff --git a/configs/slpkg.json b/configs/slpkg.json deleted file mode 100644 index 438d5512..00000000 --- a/configs/slpkg.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "os_arch": "x86_64", - "tmp_path": "/tmp", - "tmp_slpkg": "/tmp/slpkg", - "build_path": "/tmp/slpkg/build", - "lib_path": "/var/lib/slpkg", - "etc_path": "/etc/slpkg", - "db_path": "/var/lib/slpkg/database", - "sbo_repo_path": "/var/lib/slpkg/repository", - "log_packages": "/var/log/packages", - "database": "database.slpkg", - "repo_version": "15.0", - "sbo_url": "http://slackbuilds.org/slackbuilds/15.0", - "sbo_txt": "SLACKBUILDS.TXT", - "tar_suffix": ".tar.gz", - "pkg_suffix": ".tgz", - "repo_tag": "_SBo", - "installpkg": "upgradepkg --install-new", - "reinstall": "upgradepkg --reinstall", - "removepkg": "removepkg", - "colors": "on", - "wget_options": "-c -N" -} diff --git a/configs/slpkg.yaml b/configs/slpkg.yaml new file mode 100644 index 00000000..0d3da6a8 --- /dev/null +++ b/configs/slpkg.yaml @@ -0,0 +1,22 @@ +config: + os_arch: x86_64 + tmp_path: /tmp + tmp_slpkg: /tmp/slpkg + build_path: /tmp/slpkg/build + lib_path: /var/lib/slpkg + etc_path: /etc/slpkg + db_path: /var/lib/slpkg/database + sbo_repo_path: /var/lib/slpkg/repository + log_packages: /var/log/packages + database: database.slpkg + repo_version: 15.0 + sbo_url: http://slackbuilds.org/slackbuilds/15.0 + sbo_txt: SLACKBUILDS.TXT + tar_suffix: .tar.gz + pkg_suffix: .tgz + repo_tag: _SBo + installpkg: upgradepkg --install-new + reinstall: upgradepkg --reinstall + removepkg: removepkg + colors: on + wget_options: -c -N diff --git a/slpkg/blacklist.py b/slpkg/blacklist.py index 3b9f3cfb..3f950fb2 100644 --- a/slpkg/blacklist.py +++ b/slpkg/blacklist.py @@ -3,7 +3,7 @@ import os -import json +import yaml from dataclasses import dataclass from slpkg.configs import Configs @@ -15,7 +15,7 @@ class Blacklist: etc_path: str = Configs.etc_path def get(self): - file = f'{self.etc_path}/blacklist.json' + file = f'{self.etc_path}/blacklist.yaml' if os.path.isfile(file): with open(file, 'r') as black: - return json.load(black)['blacklist'] + return yaml.safe_load(black)['blacklist']['packages'] diff --git a/slpkg/configs.py b/slpkg/configs.py index 6e53cee9..095de564 100644 --- a/slpkg/configs.py +++ b/slpkg/configs.py @@ -3,7 +3,7 @@ import os -import json +import yaml from dataclasses import dataclass @@ -49,11 +49,14 @@ class Configs: wget_options = '-c -N' ''' Overwrite with user configuration. ''' - config_file: str = f'{etc_path}/{prog_name}.json' + config_file: str = f'{etc_path}/{prog_name}.yaml' + if os.path.isfile(config_file): with open(config_file, 'r') as conf: - config = json.load(conf) + configs = yaml.safe_load(conf) + + config = configs['configs'] # OS architecture by default os_arch: str = config['os_arch'] @@ -91,6 +94,7 @@ class Configs: @classmethod def colour(cls): color = { + 'BOLD': '', 'RED': '', 'GREEN': '', 'YELLOW': '', @@ -100,7 +104,7 @@ class Configs: 'ENDC': '' } - if cls.colors in ['on', 'ON']: + if cls.colors: color = { 'BOLD': '\033[1m', 'RED': '\x1b[91m', diff --git a/slpkg/main.py b/slpkg/main.py index 8709040d..7016bbac 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -25,7 +25,7 @@ class Argparse: self.flag() self.check = Check() - if len(self.args) <= 0: + if len(self.args) == 0: usage(1) def flag(self): @@ -98,7 +98,6 @@ class Argparse: usage(1) def search(self): - # Search package if len(self.args) >= 2: packages = list(set(self.args[1:])) packages = self.check.blacklist(packages) @@ -124,7 +123,7 @@ class Argparse: folder = Configs.prog_name utils = Utilities() utils.remove_folder_if_exists(path, folder) - utils.create_folder(tmp_slpkg, 'build/') + utils.create_folder(tmp_slpkg, 'build') raise SystemExit() usage(1) @@ -146,7 +145,7 @@ def main(): 'remove': argparse.remove, 'search': argparse.search, 'clean-logs': argparse.clean_logs, - 'clean-tmp': argparse.clean_tmp, + 'clean-tmp': argparse.clean_tmp } try: