Switch from json to yaml configs

This commit is contained in:
Dimitris Zlatanidis 2022-06-22 22:05:56 +03:00
parent cf17321c01
commit 9d33105970
7 changed files with 38 additions and 37 deletions

View file

@ -1,3 +0,0 @@
{
"blacklist": []
}

2
configs/blacklist.yaml Normal file
View file

@ -0,0 +1,2 @@
blacklist:
packages: []

View file

@ -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"
}

22
configs/slpkg.yaml Normal file
View file

@ -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

View file

@ -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']

View file

@ -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',

View file

@ -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: