From dcd950b1d4bbeedd1245f3677d995f18cf6656e2 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 00:04:58 +0200 Subject: [PATCH 01/30] Added configs command --- ChangeLog.txt | 4 ++++ man/slpkg.1 | 7 +++++- slpkg/configs.py | 10 ++++---- slpkg/dialog_box.py | 46 +++++++++++++++++++++++++++++++++++ slpkg/main.py | 53 +++++++++++++++++++++++------------------ slpkg/utilities.py | 2 ++ slpkg/views/cli_menu.py | 4 +++- 7 files changed, 96 insertions(+), 30 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index e14d1d8e..1fb87d02 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,7 @@ +4.4.1 - 28/12/2022 +Added: +- configs command to read and edit configuration file + 4.4.0 - 23/12/2022 Added: - New command to tracking the dependencies diff --git a/man/slpkg.1 b/man/slpkg.1 index 93e0aef7..3e409ed4 100644 --- a/man/slpkg.1 +++ b/man/slpkg.1 @@ -4,7 +4,7 @@ slpkg - [OPTIONS] [COMMAND] .SH SYNAPSES .P -slpkg [-h|-v] [update] [upgrade] [check-updates] [clean-logs] [clean-tmp] [-b, build] [-i, install] [-d, download] +slpkg [-h|-v] [update] [upgrade] [check-updates] [configs] [clean-logs] [clean-tmp] [-b, build] [-i, install] [-d, download] [-r, remove] [-f, find] [-w, view] [-s, search] [-e, dependees] [-t, tracking] --yes, --jobs, --resolve-off, --reinstall, --skip-installed, --full-reverse, --search .SH DESCRIPTION @@ -32,6 +32,11 @@ check-updates Check if there is any news on the SlackBuild's ChangeLog.txt file. .RE .P +configs +.RS +Edit the configuration /etc/slpkg/slpkg.toml file. +.RE +.P clean-logs .RS Cleans dependencies log tracking. After that procedure you should remove dependencies by hand. diff --git a/slpkg/configs.py b/slpkg/configs.py index 18efcb80..5b477def 100644 --- a/slpkg/configs.py +++ b/slpkg/configs.py @@ -57,10 +57,10 @@ class Configs: # Overwrite with user configuration. config_file: str = f'{etc_path}/{prog_name}.toml' if os.path.isfile(config_file): - with open(config_file, 'rb') as conf: - configs = tomli.load(conf) - try: + with open(config_file, 'rb') as conf: + configs = tomli.load(conf) + config = configs['configs'] # OS architecture by default @@ -96,8 +96,8 @@ class Configs: # Dialog utility dialog: str = config['dialog'] - except KeyError as error: - print(f"Error: {error}: in the configuration file " + except (KeyError, tomli.TOMLDecodeError) as error: + raise SystemExit(f"\nError: {error}: in the configuration file " "'/etc/slpkg/slpkg.toml'\n") # Creating the paths if not exists diff --git a/slpkg/dialog_box.py b/slpkg/dialog_box.py index 9e976b4a..658208bc 100644 --- a/slpkg/dialog_box.py +++ b/slpkg/dialog_box.py @@ -1,6 +1,8 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- +import os +import tomli import locale from dialog import Dialog @@ -28,3 +30,47 @@ class DialogBox: tags = packages return code, tags + + def form_configs(self): + """ Read and write the configuration file. """ + elements = [] + config_file: str = f'{self.configs.etc_path}/{self.configs.prog_name}.toml' + + if os.path.isfile(config_file): + # Load the toml config file. + try: + with open(config_file, 'rb') as conf: + configs = tomli.load(conf) + except (KeyError, tomli.TOMLDecodeError) as error: + raise SystemExit(f"\nError: {error}: in the configuration file " + "'/etc/slpkg/slpkg.toml'\n") + + # Creating the elements for the dialog form. + for i, (key, value) in enumerate(configs['configs'].items(), start=1): + if value is True: + value = 'true' + elif value is False: + value = 'false' + elements += [ + (key, i, 1, value, i, 17, 47, 200, '0x0') + ] + text = f'Edit the configuration file: {config_file}.' + title = ' Configuration File ' + code, tags = self.d.mixedform(text=text, title=title, elements=elements, + height=30, width=70) + os.system('clear') + + if code == 'ok': + # Read the original config file. + with open(config_file, 'r') as toml_file: + orig_config = toml_file.readlines() + + # Write the new values to the config file. + with open(config_file, 'w') as patch_toml: + for line in orig_config: + for key, value in zip(configs['configs'].keys(), tags): + if line.lstrip().startswith(key): + line = f' {key} = "{value}"\n' + if line.lstrip().startswith(('colors =', 'dialog =')): + line = line.replace('"', '') + patch_toml.write(line) diff --git a/slpkg/main.py b/slpkg/main.py index 035fb324..f8a03751 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -185,6 +185,35 @@ class Argparse: raise SystemExit() self.usage.help(1) + def edit_configs(self): + if len(self.args) == 1 and not self.flags: + self.dialog.form_configs() + raise SystemExit() + self.usage.help(1) + + def clean_logs(self): + if [f for f in self.flags if f not in [self.flag_yes]]: + self.usage.help(1) + + if len(self.args) == 1: + self.check.database() + + logs = CleanLogsDependencies(self.flags) + logs.clean() + raise SystemExit() + self.usage.help(1) + + def clean_tmp(self): + if len(self.args) == 1 and not self.flags: + path = self.configs.tmp_path + tmp_slpkg = self.configs.tmp_slpkg + folder = self.configs.prog_name + + self.utils.remove_folder_if_exists(path, folder) + self.utils.create_folder(tmp_slpkg, 'build') + raise SystemExit() + self.usage.help(1) + def build(self): if [f for f in self.flags if f not in [self.flag_yes, self.flag_jobs, @@ -360,29 +389,6 @@ class Argparse: raise SystemExit() self.usage.help(1) - def clean_logs(self): - if [f for f in self.flags if f not in [self.flag_yes]]: - self.usage.help(1) - - if len(self.args) == 1: - self.check.database() - - logs = CleanLogsDependencies(self.flags) - logs.clean() - raise SystemExit() - self.usage.help(1) - - def clean_tmp(self): - if len(self.args) == 1 and not self.flags: - path = self.configs.tmp_path - tmp_slpkg = self.configs.tmp_slpkg - folder = self.configs.prog_name - - self.utils.remove_folder_if_exists(path, folder) - self.utils.create_folder(tmp_slpkg, 'build') - raise SystemExit() - self.usage.help(1) - def main(): args = sys.argv @@ -398,6 +404,7 @@ def main(): 'update': argparse.update, 'upgrade': argparse.upgrade, 'check-updates': argparse.check_updates, + 'configs': argparse.edit_configs, 'clean-logs': argparse.clean_logs, 'clean-tmp': argparse.clean_tmp, 'build': argparse.build, diff --git a/slpkg/utilities.py b/slpkg/utilities.py index eb6db319..4d7e2b3c 100644 --- a/slpkg/utilities.py +++ b/slpkg/utilities.py @@ -3,6 +3,7 @@ import os +import tomli import shutil import tarfile @@ -61,3 +62,4 @@ class Utilities: tag = ''.join(package[len(name + version + arch + build) + 4:].split('-')) return [name, version, arch, build, tag] + diff --git a/slpkg/views/cli_menu.py b/slpkg/views/cli_menu.py index 9e39d341..a07c3552 100644 --- a/slpkg/views/cli_menu.py +++ b/slpkg/views/cli_menu.py @@ -23,7 +23,8 @@ class Usage: f'Usage: {Configs.prog_name} [{self.yellow}OPTIONS{self.endc}] [{self.cyan}COMMAND{self.endc}] \n' f'\n slpkg [{self.yellow}OPTIONS{self.endc}] [--yes, --jobs, --resolve-off, --reinstall]\n' f' slpkg [{self.yellow}OPTIONS{self.endc}] [--skip-installed, --full-reverse, --search]\n' - f' slpkg [{self.cyan}COMMAND{self.endc}] [update, upgrade, check-updates, clean-logs, clean-tmp]\n' + f' slpkg [{self.cyan}COMMAND{self.endc}] [update, upgrade, check-updates, configs]\n' + f' slpkg [{self.cyan}COMMAND{self.endc}] [clean-logs, clean-tmp]\n' f' slpkg [{self.cyan}COMMAND{self.endc}] [-b, build, -i, install, -d, download, -r, remove] \n' f' slpkg [{self.cyan}COMMAND{self.endc}] [-f, find, -w, view, -s, search, -e, dependees] \n' f' slpkg [{self.cyan}COMMAND{self.endc}] [-t, tracking] \n' @@ -42,6 +43,7 @@ class Usage: f' {self.red}update{self.endc} Update the package lists.\n' f' {self.cyan}upgrade{self.endc} Upgrade all the packages.\n' f' {self.cyan}check-updates{self.endc} Check for news on ChangeLog.txt.\n' + f' {self.cyan}configs{self.endc} Edit the configuration file.\n' f' {self.cyan}clean-logs{self.endc} Clean dependencies log tracking.\n' f' {self.cyan}clean-tmp{self.endc} Delete all the downloaded sources.\n' f' {self.cyan}-b, build{self.endc} Build only the packages.\n' From 386ac67796281275ebd50a480abac92a56c64553 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 00:05:32 +0200 Subject: [PATCH 02/30] Removed space --- slpkg/utilities.py | 1 - 1 file changed, 1 deletion(-) diff --git a/slpkg/utilities.py b/slpkg/utilities.py index 4d7e2b3c..5dd33cea 100644 --- a/slpkg/utilities.py +++ b/slpkg/utilities.py @@ -62,4 +62,3 @@ class Utilities: tag = ''.join(package[len(name + version + arch + build) + 4:].split('-')) return [name, version, arch, build, tag] - From 3973fc034d5f6b5d236003102e651a507e047b8f Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 00:06:13 +0200 Subject: [PATCH 03/30] Added configs command --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index 1c8bb9b2..54200818 100644 --- a/README.rst +++ b/README.rst @@ -51,6 +51,7 @@ Usage update Update the package lists. upgrade Upgrade all the packages. check-updates Check for news on ChangeLog.txt. + configs Edit the configuration file. clean-logs Clean dependencies log tracking. clean-tmp Deletes all the downloaded sources. -b, build Build only the packages. From cf7442687851ab79db12f70bed9243e5cbe8df8a Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 00:08:59 +0200 Subject: [PATCH 04/30] Updated height --- slpkg/dialog_box.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slpkg/dialog_box.py b/slpkg/dialog_box.py index 658208bc..2dfe16b6 100644 --- a/slpkg/dialog_box.py +++ b/slpkg/dialog_box.py @@ -57,7 +57,7 @@ class DialogBox: text = f'Edit the configuration file: {config_file}.' title = ' Configuration File ' code, tags = self.d.mixedform(text=text, title=title, elements=elements, - height=30, width=70) + height=28, width=70) os.system('clear') if code == 'ok': From c38df50bc577958adfef3b0f1c01dcd05a9bd5dc Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 00:09:38 +0200 Subject: [PATCH 05/30] Updated text --- slpkg/dialog_box.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slpkg/dialog_box.py b/slpkg/dialog_box.py index 2dfe16b6..8a7beeef 100644 --- a/slpkg/dialog_box.py +++ b/slpkg/dialog_box.py @@ -54,7 +54,7 @@ class DialogBox: elements += [ (key, i, 1, value, i, 17, 47, 200, '0x0') ] - text = f'Edit the configuration file: {config_file}.' + text = f'Edit the configuration file: {config_file}' title = ' Configuration File ' code, tags = self.d.mixedform(text=text, title=title, elements=elements, height=28, width=70) From d9017d148761cbf1af3277bfa2f18a76832211e0 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 12:22:17 +0200 Subject: [PATCH 06/30] Moved to a new file --- slpkg/configs.py | 102 ++++++++++++++++++++++-------------------- slpkg/dialog_box.py | 50 ++++----------------- slpkg/form_configs.py | 59 ++++++++++++++++++++++++ slpkg/main.py | 4 +- 4 files changed, 124 insertions(+), 91 deletions(-) create mode 100644 slpkg/form_configs.py diff --git a/slpkg/configs.py b/slpkg/configs.py index 5b477def..1ab63bbb 100644 --- a/slpkg/configs.py +++ b/slpkg/configs.py @@ -9,6 +9,20 @@ import platform from dataclasses import dataclass +class LoadConfigs: + @staticmethod + def file(path, file): + try: + """ Load the configs from the file. """ + config_file: str = f'{path}/{file}.toml' + if os.path.isfile(config_file): + with open(config_file, 'rb') as conf: + return tomli.load(conf) + except (KeyError, tomli.TOMLDecodeError) as error: + raise SystemExit(f"\nError: {error}: in the configuration file " + "'/etc/slpkg/slpkg.toml'\n") + + @dataclass class Configs: """ Default configurations. """ @@ -54,64 +68,56 @@ class Configs: # Dialog utility dialog: str = True - # Overwrite with user configuration. - config_file: str = f'{etc_path}/{prog_name}.toml' - if os.path.isfile(config_file): - try: - with open(config_file, 'rb') as conf: - configs = tomli.load(conf) + load = LoadConfigs() + configs = load.file(etc_path, prog_name) + config = configs['configs'] - config = configs['configs'] + if config: + # OS architecture by default + os_arch: str = config['os_arch'] - # OS architecture by default - os_arch: str = config['os_arch'] + # All necessary paths + tmp_slpkg: str = config['tmp_slpkg'] + build_path: str = config['build_path'] + download_only: str = config['download_only'] + sbo_repo_path: str = config['sbo_repo_path'] - # All necessary paths - tmp_slpkg: str = config['tmp_slpkg'] - build_path: str = config['build_path'] - download_only: str = config['download_only'] - sbo_repo_path: str = config['sbo_repo_path'] + # Database name + database: str = config['database'] - # Database name - database: str = config['database'] + # SBo repository details + sbo_repo_url: str = config['sbo_repo_url'] + sbo_txt: str = config['sbo_txt'] + sbo_chglog_txt: str = config['sbo_chglog_txt'] + sbo_tar_suffix: str = config['sbo_tar_suffix'] + sbo_repo_tag: str = config['sbo_repo_tag'] - # SBo repository details - sbo_repo_url: str = config['sbo_repo_url'] - sbo_txt: str = config['sbo_txt'] - sbo_chglog_txt: str = config['sbo_chglog_txt'] - sbo_tar_suffix: str = config['sbo_tar_suffix'] - sbo_repo_tag: str = config['sbo_repo_tag'] + # Slackware commands + installpkg: str = config['installpkg'] + reinstall: str = config['reinstall'] + removepkg: str = config['removepkg'] - # Slackware commands - installpkg: str = config['installpkg'] - reinstall: str = config['reinstall'] - removepkg: str = config['removepkg'] + # Cli menu colors configs + colors: str = config['colors'] - # Cli menu colors configs - colors: str = config['colors'] + # Wget options + wget_options: str = config['wget_options'] - # Wget options - wget_options: str = config['wget_options'] + # Dialog utility + dialog: str = config['dialog'] - # Dialog utility - dialog: str = config['dialog'] + # Creating the paths if not exists + paths = [tmp_slpkg, + build_path, + download_only, + sbo_repo_path, + lib_path, + etc_path, + db_path] - except (KeyError, tomli.TOMLDecodeError) as error: - raise SystemExit(f"\nError: {error}: in the configuration file " - "'/etc/slpkg/slpkg.toml'\n") - - # Creating the paths if not exists - paths = [tmp_slpkg, - build_path, - download_only, - sbo_repo_path, - lib_path, - etc_path, - db_path] - - for path in paths: - if not os.path.isdir(path): - os.makedirs(path) + for path in paths: + if not os.path.isdir(path): + os.makedirs(path) @classmethod def colour(cls): diff --git a/slpkg/dialog_box.py b/slpkg/dialog_box.py index 8a7beeef..e595123c 100644 --- a/slpkg/dialog_box.py +++ b/slpkg/dialog_box.py @@ -1,8 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- -import os -import tomli import locale from dialog import Dialog @@ -31,46 +29,14 @@ class DialogBox: return code, tags - def form_configs(self): - """ Read and write the configuration file. """ - elements = [] - config_file: str = f'{self.configs.etc_path}/{self.configs.prog_name}.toml' + def mixedform(self, text, title, elements, height, width): + """ Display a mixedform box. """ - if os.path.isfile(config_file): - # Load the toml config file. - try: - with open(config_file, 'rb') as conf: - configs = tomli.load(conf) - except (KeyError, tomli.TOMLDecodeError) as error: - raise SystemExit(f"\nError: {error}: in the configuration file " - "'/etc/slpkg/slpkg.toml'\n") - - # Creating the elements for the dialog form. - for i, (key, value) in enumerate(configs['configs'].items(), start=1): - if value is True: - value = 'true' - elif value is False: - value = 'false' - elements += [ - (key, i, 1, value, i, 17, 47, 200, '0x0') - ] - text = f'Edit the configuration file: {config_file}' - title = ' Configuration File ' + if self.configs.dialog: code, tags = self.d.mixedform(text=text, title=title, elements=elements, - height=28, width=70) - os.system('clear') + height=height, width=width) + else: + code = False + tags = elements - if code == 'ok': - # Read the original config file. - with open(config_file, 'r') as toml_file: - orig_config = toml_file.readlines() - - # Write the new values to the config file. - with open(config_file, 'w') as patch_toml: - for line in orig_config: - for key, value in zip(configs['configs'].keys(), tags): - if line.lstrip().startswith(key): - line = f' {key} = "{value}"\n' - if line.lstrip().startswith(('colors =', 'dialog =')): - line = line.replace('"', '') - patch_toml.write(line) + return code, tags diff --git a/slpkg/form_configs.py b/slpkg/form_configs.py new file mode 100644 index 00000000..243a8185 --- /dev/null +++ b/slpkg/form_configs.py @@ -0,0 +1,59 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +import os + +from slpkg.configs import Configs +from slpkg.configs import LoadConfigs +from slpkg.dialog_box import DialogBox + + +class FormConfigs: + + def __init__(self): + self.configs = Configs() + self.load_configs = LoadConfigs() + self.dialog = DialogBox() + + def edit(self): + """ Read and write the configuration file. """ + elements = [] + config_file: str = f'{self.configs.etc_path}/{self.configs.prog_name}.toml' + + if os.path.isfile(config_file): + # Load the toml config file. + configs = self.load_configs.file(self.configs.etc_path, + self.configs.prog_name) + + # Creating the elements for the dialog form. + for i, (key, value) in enumerate(configs['configs'].items(), start=1): + if value is True: + value = 'true' + elif value is False: + value = 'false' + elements += [ + (key, i, 1, value, i, 17, 47, 200, '0x0') + ] + height = 28 + width = 70 + text = f'Edit the configuration file: {config_file}' + title = ' Configuration File ' + + code, tags = self.dialog.mixedform(text, title, elements, height, width) + + os.system('clear') + + if code == 'ok': + # Read the original config file. + with open(config_file, 'r') as toml_file: + orig_config = toml_file.readlines() + + # Write the new values to the config file. + with open(config_file, 'w') as patch_toml: + for line in orig_config: + for key, value in zip(configs['configs'].keys(), tags): + if line.lstrip().startswith(key): + line = f' {key} = "{value}"\n' + if line.lstrip().startswith(('colors =', 'dialog =')): + line = line.replace('"', '') + patch_toml.write(line) diff --git a/slpkg/main.py b/slpkg/main.py index f8a03751..9aa55efa 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -17,6 +17,7 @@ from slpkg.dialog_box import DialogBox from slpkg.views.version import Version from slpkg.download_only import Download from slpkg.slackbuild import Slackbuilds +from slpkg.form_configs import FormConfigs from slpkg.check_updates import CheckUpdates from slpkg.find_installed import FindInstalled from slpkg.views.view_package import ViewPackage @@ -35,6 +36,7 @@ class Argparse: self.utils = Utilities() self.usage = Usage() self.check = Check() + self.form_configs = FormConfigs() if len(self.args) == 0: self.usage.help_short() @@ -187,7 +189,7 @@ class Argparse: def edit_configs(self): if len(self.args) == 1 and not self.flags: - self.dialog.form_configs() + self.form_configs.edit() raise SystemExit() self.usage.help(1) From 417dee263b655501bb63dc3992a43e354539322c Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 12:23:38 +0200 Subject: [PATCH 07/30] Updated code --- slpkg/form_configs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/slpkg/form_configs.py b/slpkg/form_configs.py index 243a8185..0a328161 100644 --- a/slpkg/form_configs.py +++ b/slpkg/form_configs.py @@ -34,6 +34,7 @@ class FormConfigs: elements += [ (key, i, 1, value, i, 17, 47, 200, '0x0') ] + height = 28 width = 70 text = f'Edit the configuration file: {config_file}' From 207598dd4c089a8b54ad9489489c0c318f63e415 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 12:32:39 +0200 Subject: [PATCH 08/30] Updated for configs --- slpkg/main.py | 3 ++- slpkg/views/cli_menu.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/slpkg/main.py b/slpkg/main.py index 9aa55efa..13e3b34e 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -51,7 +51,8 @@ class Argparse: self.flag_full_reverse = '--full-reverse' self.flag_search = '--search' - if not self.configs.dialog and self.flag_search in self.args: + if (not self.configs.dialog and self.flag_search in self.args or + not self.configs.dialog and 'configs' in self.args): print("Error: You should enable the dialog " "in the '/etc/slpkg/' folder.\n") self.usage.help(1) diff --git a/slpkg/views/cli_menu.py b/slpkg/views/cli_menu.py index a07c3552..d4eaf82f 100644 --- a/slpkg/views/cli_menu.py +++ b/slpkg/views/cli_menu.py @@ -65,7 +65,8 @@ class Usage: f' {self.yellow}--search{self.endc} Search packages from the repository.\n' '\n -h, --help Show this message and exit.\n' ' -v, --version Print version and exit.\n' - '\nEdit the configuration file in the /etc/slpkg/slpkg.toml.\n' + '\nEdit the configuration file in the /etc/slpkg/slpkg.toml \n' + "or run 'slpkg configs'.\n" 'If you need more information try to use slpkg manpage.') print(args) From 0be7d969361ab0858927830c0f148c7c6cfc09fa Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 12:52:25 +0200 Subject: [PATCH 09/30] Split to methods --- slpkg/form_configs.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/slpkg/form_configs.py b/slpkg/form_configs.py index 0a328161..54fe5b0a 100644 --- a/slpkg/form_configs.py +++ b/slpkg/form_configs.py @@ -11,9 +11,11 @@ from slpkg.dialog_box import DialogBox class FormConfigs: def __init__(self): + self.orig_configs = None self.configs = Configs() self.load_configs = LoadConfigs() self.dialog = DialogBox() + self.config_file = f'{self.configs.etc_path}/{self.configs.prog_name}.toml' def edit(self): """ Read and write the configuration file. """ @@ -45,16 +47,21 @@ class FormConfigs: os.system('clear') if code == 'ok': - # Read the original config file. - with open(config_file, 'r') as toml_file: - orig_config = toml_file.readlines() + self.write_file(configs, tags) - # Write the new values to the config file. - with open(config_file, 'w') as patch_toml: - for line in orig_config: - for key, value in zip(configs['configs'].keys(), tags): - if line.lstrip().startswith(key): - line = f' {key} = "{value}"\n' - if line.lstrip().startswith(('colors =', 'dialog =')): - line = line.replace('"', '') - patch_toml.write(line) + def read_file(self): + """ Read the original config file. """ + with open(self.config_file, 'r') as toml_file: + self.orig_configs = toml_file.readlines() + + def write_file(self, configs, tags): + """ Write the new values to the config file. """ + self.read_file() + with open(self.config_file, 'w') as patch_toml: + for line in self.orig_configs: + for key, value in zip(configs['configs'].keys(), tags): + if line.lstrip().startswith(key): + line = f' {key} = "{value}"\n' + if line.lstrip().startswith(('colors =', 'dialog =')): + line = line.replace('"', '') + patch_toml.write(line) From ade466f874e7885eeb0f7aff9712e116b6c64680 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 19:39:50 +0200 Subject: [PATCH 10/30] Added msgbox and textbox --- slpkg/dialog_box.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/slpkg/dialog_box.py b/slpkg/dialog_box.py index e595123c..a29949b0 100644 --- a/slpkg/dialog_box.py +++ b/slpkg/dialog_box.py @@ -34,9 +34,19 @@ class DialogBox: if self.configs.dialog: code, tags = self.d.mixedform(text=text, title=title, elements=elements, - height=height, width=width) + height=height, width=width, help_button=True) else: code = False tags = elements return code, tags + + def msgbox(self, text, height, width): + + if self.configs.dialog: + self.d.msgbox(text, height, width) + + def textbox(self, text, height, width): + + if self.configs.dialog: + self.d.textbox(text, height, width) From f4b04cee39c85635a2d5d531180d41d21f7806d6 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 19:40:00 +0200 Subject: [PATCH 11/30] Updated for configs --- slpkg/form_configs.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/slpkg/form_configs.py b/slpkg/form_configs.py index 54fe5b0a..8e50a751 100644 --- a/slpkg/form_configs.py +++ b/slpkg/form_configs.py @@ -46,8 +46,28 @@ class FormConfigs: os.system('clear') - if code == 'ok': + check = self.check_configs(configs, tags) + + if code == 'ok' and check: self.write_file(configs, tags) + elif not check: + self.edit() + elif code == 'help': + self.help() + + def help(self): + """ Load the configuration file on a text box. """ + self.read_file() + self.dialog.textbox(self.config_file, 40, 60) + self.edit() + + def check_configs(self, configs, tags): + """ Check for true of false values. """ + for key, value in zip(configs['configs'].keys(), tags): + if key in ['colors', 'dialog'] and value not in ['true', 'false']: + self.dialog.msgbox(f"\nError value for {key}. It must be 'true' or 'false'\n", height=7, width=60) + return False + return True def read_file(self): """ Read the original config file. """ From 8c5b13bcaec701bf705a6a26a3bde5ae340c5516 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 20:15:53 +0200 Subject: [PATCH 12/30] Updated for version 4.4.1 Signed-off-by: Dimitris Zlatanidis --- README.rst | 4 ++-- setup.cfg | 2 +- slpkg/views/version.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 54200818..f44ac35d 100644 --- a/README.rst +++ b/README.rst @@ -31,8 +31,8 @@ Install from the official third-party `SBo repository Date: Wed, 28 Dec 2022 20:19:07 +0200 Subject: [PATCH 13/30] Added comments --- slpkg/dialog_box.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/slpkg/dialog_box.py b/slpkg/dialog_box.py index a29949b0..d800f15e 100644 --- a/slpkg/dialog_box.py +++ b/slpkg/dialog_box.py @@ -11,6 +11,7 @@ locale.setlocale(locale.LC_ALL, '') class DialogBox: + """ Class for dialog box library. """ def __init__(self): self.configs = Configs() @@ -19,7 +20,6 @@ class DialogBox: def checklist(self, text, title, height, width, list_height, choices, packages): """ Display a checklist box. """ - if self.configs.dialog: code, tags = self.d.checklist(text, title=title, height=height, width=width, list_height=list_height, choices=choices) @@ -31,7 +31,6 @@ class DialogBox: def mixedform(self, text, title, elements, height, width): """ Display a mixedform box. """ - if self.configs.dialog: code, tags = self.d.mixedform(text=text, title=title, elements=elements, height=height, width=width, help_button=True) @@ -42,11 +41,11 @@ class DialogBox: return code, tags def msgbox(self, text, height, width): - + """ Display a message box. """ if self.configs.dialog: self.d.msgbox(text, height, width) def textbox(self, text, height, width): - + """ Display a text box. """ if self.configs.dialog: self.d.textbox(text, height, width) From 2484629dc18f2b1fe1895b452d29e0d541a7ceff Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 20:36:43 +0200 Subject: [PATCH 14/30] Fixed code style --- slpkg/blacklist.py | 1 - slpkg/check_updates.py | 1 - slpkg/checksum.py | 1 - slpkg/clean_logs.py | 1 - slpkg/configs.py | 1 - slpkg/create_data.py | 1 - slpkg/dependees.py | 1 - slpkg/dependencies.py | 1 - slpkg/download_only.py | 1 - slpkg/downloader.py | 1 - slpkg/find_installed.py | 1 - slpkg/models/models.py | 1 - slpkg/queries.py | 1 - slpkg/search.py | 1 - slpkg/tracking.py | 1 - slpkg/update_repository.py | 1 - slpkg/utilities.py | 1 - slpkg/views/cli_menu.py | 1 - slpkg/views/version.py | 1 - slpkg/views/view_package.py | 1 - 20 files changed, 20 deletions(-) diff --git a/slpkg/blacklist.py b/slpkg/blacklist.py index 412b0828..9b62a48d 100644 --- a/slpkg/blacklist.py +++ b/slpkg/blacklist.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - import os import tomli diff --git a/slpkg/check_updates.py b/slpkg/check_updates.py index dfc96b8b..808a6991 100644 --- a/slpkg/check_updates.py +++ b/slpkg/check_updates.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - import os import urllib3 diff --git a/slpkg/checksum.py b/slpkg/checksum.py index 8bf953bf..83f3d09b 100644 --- a/slpkg/checksum.py +++ b/slpkg/checksum.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - import hashlib from slpkg.views.views import ViewMessage diff --git a/slpkg/clean_logs.py b/slpkg/clean_logs.py index 5d617602..5ccfd7bd 100644 --- a/slpkg/clean_logs.py +++ b/slpkg/clean_logs.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - from slpkg.views.views import ViewMessage from slpkg.models.models import LogsDependencies from slpkg.models.models import session as Session diff --git a/slpkg/configs.py b/slpkg/configs.py index 1ab63bbb..f9bbf57a 100644 --- a/slpkg/configs.py +++ b/slpkg/configs.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - import os import tomli import platform diff --git a/slpkg/create_data.py b/slpkg/create_data.py index 46e914fe..7cef514a 100644 --- a/slpkg/create_data.py +++ b/slpkg/create_data.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - from slpkg.configs import Configs from slpkg.models.models import SBoTable from slpkg.models.models import session as Session diff --git a/slpkg/dependees.py b/slpkg/dependees.py index a387eab7..1408a922 100644 --- a/slpkg/dependees.py +++ b/slpkg/dependees.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - from slpkg.configs import Configs from slpkg.queries import SBoQueries diff --git a/slpkg/dependencies.py b/slpkg/dependencies.py index c16c5b1b..79be9b1b 100644 --- a/slpkg/dependencies.py +++ b/slpkg/dependencies.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - from slpkg.queries import SBoQueries diff --git a/slpkg/download_only.py b/slpkg/download_only.py index e30ac419..1708e446 100644 --- a/slpkg/download_only.py +++ b/slpkg/download_only.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - from slpkg.downloader import Wget from slpkg.configs import Configs from slpkg.queries import SBoQueries diff --git a/slpkg/downloader.py b/slpkg/downloader.py index fc112fa1..e891663c 100644 --- a/slpkg/downloader.py +++ b/slpkg/downloader.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - import subprocess from slpkg.configs import Configs diff --git a/slpkg/find_installed.py b/slpkg/find_installed.py index 7064c6b6..a6d756de 100644 --- a/slpkg/find_installed.py +++ b/slpkg/find_installed.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - import os from slpkg.configs import Configs diff --git a/slpkg/models/models.py b/slpkg/models/models.py index 9beda31f..37f28f86 100644 --- a/slpkg/models/models.py +++ b/slpkg/models/models.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - from dataclasses import dataclass from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base diff --git a/slpkg/queries.py b/slpkg/queries.py index 5552597b..471bb577 100644 --- a/slpkg/queries.py +++ b/slpkg/queries.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - from slpkg.configs import Configs from slpkg.blacklist import Blacklist from slpkg.models.models import SBoTable diff --git a/slpkg/search.py b/slpkg/search.py index 4602ecdb..739ddcfd 100644 --- a/slpkg/search.py +++ b/slpkg/search.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - from slpkg.queries import SBoQueries from slpkg.configs import Configs diff --git a/slpkg/tracking.py b/slpkg/tracking.py index f2948c8e..b4bfebb1 100644 --- a/slpkg/tracking.py +++ b/slpkg/tracking.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - from slpkg.configs import Configs from slpkg.dependencies import Requires diff --git a/slpkg/update_repository.py b/slpkg/update_repository.py index 9c28a096..83f019a8 100644 --- a/slpkg/update_repository.py +++ b/slpkg/update_repository.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - import os from os import path diff --git a/slpkg/utilities.py b/slpkg/utilities.py index 5dd33cea..c49c91a6 100644 --- a/slpkg/utilities.py +++ b/slpkg/utilities.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - import os import tomli import shutil diff --git a/slpkg/views/cli_menu.py b/slpkg/views/cli_menu.py index d4eaf82f..be9d33e8 100644 --- a/slpkg/views/cli_menu.py +++ b/slpkg/views/cli_menu.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - from slpkg.configs import Configs diff --git a/slpkg/views/version.py b/slpkg/views/version.py index f4a189b1..5fbde9d7 100644 --- a/slpkg/views/version.py +++ b/slpkg/views/version.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - class Version: """ Print the version. """ diff --git a/slpkg/views/view_package.py b/slpkg/views/view_package.py index 238ba2cf..a33910fb 100644 --- a/slpkg/views/view_package.py +++ b/slpkg/views/view_package.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- - import urllib3 from slpkg.configs import Configs From fdee94cbbde6c519878efb8ad53855da893eac21 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 21:03:36 +0200 Subject: [PATCH 15/30] Fixed installed version for remove --- slpkg/dialog_box.py | 2 +- slpkg/main.py | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/slpkg/dialog_box.py b/slpkg/dialog_box.py index d800f15e..c2a11c86 100644 --- a/slpkg/dialog_box.py +++ b/slpkg/dialog_box.py @@ -11,7 +11,7 @@ locale.setlocale(locale.LC_ALL, '') class DialogBox: - """ Class for dialog box library. """ + """ Class for dialog box""" def __init__(self): self.configs = Configs() diff --git a/slpkg/main.py b/slpkg/main.py index 13e3b34e..78e3f1a6 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -87,22 +87,20 @@ class Argparse: repo_packages = SBoQueries('').sbos() if method == 'remove': - # Grab all the installed packages installed = os.listdir(self.configs.log_packages) for package in installed: - inst_pkg_name = self.utils.split_installed_pkg(package)[0] + name = self.utils.split_installed_pkg(package)[0] + version = self.utils.split_installed_pkg(package)[1] if package.endswith(self.configs.sbo_repo_tag): for pkg in packages: - if pkg in inst_pkg_name: - repo_ver = SBoQueries(inst_pkg_name).version() - choices += [(inst_pkg_name, repo_ver, False)] + if pkg in name: + choices += [(name, version, False)] else: for package in repo_packages: for pkg in packages: - if pkg in package: repo_ver = SBoQueries(package).version() From fa5311c621789c519ec17d28c35b045a51951b69 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 21:04:17 +0200 Subject: [PATCH 16/30] Fixed code style --- slpkg/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slpkg/main.py b/slpkg/main.py index 78e3f1a6..9cefd676 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -101,8 +101,8 @@ class Argparse: else: for package in repo_packages: for pkg in packages: - if pkg in package: + if pkg in package: repo_ver = SBoQueries(package).version() if method == 'upgrade': From e1607974ce10ac8939411352b2bb244a3f67356d Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 21:46:50 +0200 Subject: [PATCH 17/30] Added screenshot --- README.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.rst b/README.rst index f44ac35d..b8c80c25 100644 --- a/README.rst +++ b/README.rst @@ -35,6 +35,12 @@ Install from the official third-party `SBo repository Date: Wed, 28 Dec 2022 21:51:22 +0200 Subject: [PATCH 18/30] Added screenshot --- README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rst b/README.rst index b8c80c25..34f5e60a 100644 --- a/README.rst +++ b/README.rst @@ -41,6 +41,9 @@ Screenshots .. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/install.png :target: https://gitlab.com/dslackw/slpkg +.. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/next_install.png + :target: https://gitlab.com/dslackw/slpkg + Usage ----- From 4fa8608da2e5b4e51a2d8c4306ddb47c9a28add5 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 21:51:53 +0200 Subject: [PATCH 19/30] Added screenshot --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index 34f5e60a..63560e05 100644 --- a/README.rst +++ b/README.rst @@ -41,6 +41,7 @@ Screenshots .. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/install.png :target: https://gitlab.com/dslackw/slpkg + .. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/next_install.png :target: https://gitlab.com/dslackw/slpkg From 10bcad6c675a6fc533302666b4fafc5598038617 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 21:53:39 +0200 Subject: [PATCH 20/30] Updated for screenshot --- README.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/README.rst b/README.rst index 63560e05..34f5e60a 100644 --- a/README.rst +++ b/README.rst @@ -41,7 +41,6 @@ Screenshots .. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/install.png :target: https://gitlab.com/dslackw/slpkg - .. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/next_install.png :target: https://gitlab.com/dslackw/slpkg From 037f9b567fa5cf287e7d75dff32421746b1a06f7 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 22:00:45 +0200 Subject: [PATCH 21/30] Updated for screenshot --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 34f5e60a..c528da17 100644 --- a/README.rst +++ b/README.rst @@ -41,7 +41,7 @@ Screenshots .. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/install.png :target: https://gitlab.com/dslackw/slpkg -.. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/next_install.png +.. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/install_next.png :target: https://gitlab.com/dslackw/slpkg From 20d6f597d033fbb2beb9e53e6c45adc364a510bb Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 22:01:59 +0200 Subject: [PATCH 22/30] Updated for screenshot --- README.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/README.rst b/README.rst index c528da17..883e4e5b 100644 --- a/README.rst +++ b/README.rst @@ -41,6 +41,7 @@ Screenshots .. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/install.png :target: https://gitlab.com/dslackw/slpkg + .. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/install_next.png :target: https://gitlab.com/dslackw/slpkg From 751d472a7eaa7b9b763de4da278162aacab1b027 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 22:10:52 +0200 Subject: [PATCH 23/30] Added screenshot --- README.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 883e4e5b..8f3a6a8f 100644 --- a/README.rst +++ b/README.rst @@ -41,10 +41,12 @@ Screenshots .. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/install.png :target: https://gitlab.com/dslackw/slpkg - .. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/install_next.png :target: https://gitlab.com/dslackw/slpkg +.. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/dependees_next.png + :target: https://gitlab.com/dslackw/slpkg + Usage ----- From e454c6c79bfd86d79cb3b939b979485ed863059b Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 22:14:51 +0200 Subject: [PATCH 24/30] Added screenshot --- README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rst b/README.rst index 8f3a6a8f..61e75033 100644 --- a/README.rst +++ b/README.rst @@ -47,6 +47,9 @@ Screenshots .. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/dependees_next.png :target: https://gitlab.com/dslackw/slpkg +.. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/view_next.png + :target: https://gitlab.com/dslackw/slpkg + Usage ----- From 5dd11fd3568634994bb9e2df247f81d7175bc579 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 22:17:31 +0200 Subject: [PATCH 25/30] Updated for flag --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 61e75033..f6d336d9 100644 --- a/README.rst +++ b/README.rst @@ -128,7 +128,7 @@ Usage Do you want to continue (y/N)?: - $ slpkg dependees vlc + $ slpkg dependees vlc --full-reverse The list below shows the packages that dependees 'vlc' files: Collecting the data... From b35ed7b82a3dda7c9f9cace68e5215213a99ef2b Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 22:20:18 +0200 Subject: [PATCH 26/30] Added screenshot --- README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rst b/README.rst index f6d336d9..ea0703b0 100644 --- a/README.rst +++ b/README.rst @@ -50,6 +50,9 @@ Screenshots .. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/view_next.png :target: https://gitlab.com/dslackw/slpkg +.. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/remove_next.png + :target: https://gitlab.com/dslackw/slpkg + Usage ----- From 0ddee6e26123afb521acf3dfd52f1f4946009d7b Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 28 Dec 2022 22:23:18 +0200 Subject: [PATCH 27/30] Added screenshot --- README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rst b/README.rst index ea0703b0..c1b6b2a0 100644 --- a/README.rst +++ b/README.rst @@ -38,6 +38,9 @@ Install from the official third-party `SBo repository Date: Thu, 29 Dec 2022 13:58:19 +0200 Subject: [PATCH 28/30] Updated cli short menu --- slpkg/views/cli_menu.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/slpkg/views/cli_menu.py b/slpkg/views/cli_menu.py index be9d33e8..c8454b93 100644 --- a/slpkg/views/cli_menu.py +++ b/slpkg/views/cli_menu.py @@ -20,13 +20,13 @@ class Usage: """ Prints the short menu. """ args = ( f'Usage: {Configs.prog_name} [{self.yellow}OPTIONS{self.endc}] [{self.cyan}COMMAND{self.endc}] \n' - f'\n slpkg [{self.yellow}OPTIONS{self.endc}] [--yes, --jobs, --resolve-off, --reinstall]\n' - f' slpkg [{self.yellow}OPTIONS{self.endc}] [--skip-installed, --full-reverse, --search]\n' - f' slpkg [{self.cyan}COMMAND{self.endc}] [update, upgrade, check-updates, configs]\n' + f'\n slpkg [{self.cyan}COMMAND{self.endc}] [update, upgrade, check-updates, configs]\n' f' slpkg [{self.cyan}COMMAND{self.endc}] [clean-logs, clean-tmp]\n' f' slpkg [{self.cyan}COMMAND{self.endc}] [-b, build, -i, install, -d, download, -r, remove] \n' f' slpkg [{self.cyan}COMMAND{self.endc}] [-f, find, -w, view, -s, search, -e, dependees] \n' f' slpkg [{self.cyan}COMMAND{self.endc}] [-t, tracking] \n' + f' slpkg [{self.yellow}OPTIONS{self.endc}] [--yes, --jobs, --resolve-off, --reinstall]\n' + f' slpkg [{self.yellow}OPTIONS{self.endc}] [--skip-installed, --full-reverse, --search]\n' " \nIf you need more information please try 'slpkg --help'.") print(args) From 9e7402cd8b96b73c019fdd15d16391b0874d62d4 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Thu, 29 Dec 2022 17:21:53 +0200 Subject: [PATCH 29/30] Updated for typing --- slpkg/checksum.py | 2 +- slpkg/configs.py | 2 +- slpkg/create_data.py | 2 +- slpkg/dialog_box.py | 9 +++++---- slpkg/form_configs.py | 4 ++-- slpkg/slackbuild.py | 2 +- slpkg/tracking.py | 2 +- slpkg/update_repository.py | 2 +- slpkg/views/views.py | 5 +++-- 9 files changed, 16 insertions(+), 14 deletions(-) diff --git a/slpkg/checksum.py b/slpkg/checksum.py index 83f3d09b..fba7cdb1 100644 --- a/slpkg/checksum.py +++ b/slpkg/checksum.py @@ -29,7 +29,7 @@ class Md5sum: view.question() @staticmethod - def read_file(filename: str): + def read_file(filename: str) -> bytes: """ Reads the text file. """ with open(filename, 'rb') as f: return f.read() diff --git a/slpkg/configs.py b/slpkg/configs.py index f9bbf57a..02dd22eb 100644 --- a/slpkg/configs.py +++ b/slpkg/configs.py @@ -10,7 +10,7 @@ from dataclasses import dataclass class LoadConfigs: @staticmethod - def file(path, file): + def file(path: str, file: str) -> dict: try: """ Load the configs from the file. """ config_file: str = f'{path}/{file}.toml' diff --git a/slpkg/create_data.py b/slpkg/create_data.py index 7cef514a..6d282cc2 100644 --- a/slpkg/create_data.py +++ b/slpkg/create_data.py @@ -56,7 +56,7 @@ class CreateData: self.session.commit() @staticmethod - def read_file(file: str): + def read_file(file: str) -> list: """ Reads the text file. """ with open(file, 'r', encoding='utf-8') as f: return f.readlines() diff --git a/slpkg/dialog_box.py b/slpkg/dialog_box.py index c2a11c86..444af487 100644 --- a/slpkg/dialog_box.py +++ b/slpkg/dialog_box.py @@ -18,7 +18,8 @@ class DialogBox: self.d = Dialog(dialog="dialog") self.d.set_background_title(f'{self.configs.prog_name} {Version().version} - Software Package Manager') - def checklist(self, text, title, height, width, list_height, choices, packages): + def checklist(self, text: str, title: str, height: int, width: int, + list_height: int, choices: list, packages: list): """ Display a checklist box. """ if self.configs.dialog: code, tags = self.d.checklist(text, title=title, height=height, width=width, @@ -29,7 +30,7 @@ class DialogBox: return code, tags - def mixedform(self, text, title, elements, height, width): + def mixedform(self, text: str, title: str, elements: list, height: int, width: int): """ Display a mixedform box. """ if self.configs.dialog: code, tags = self.d.mixedform(text=text, title=title, elements=elements, @@ -40,12 +41,12 @@ class DialogBox: return code, tags - def msgbox(self, text, height, width): + def msgbox(self, text: str, height: int, width: int): """ Display a message box. """ if self.configs.dialog: self.d.msgbox(text, height, width) - def textbox(self, text, height, width): + def textbox(self, text: str, height: int, width: int): """ Display a text box. """ if self.configs.dialog: self.d.textbox(text, height, width) diff --git a/slpkg/form_configs.py b/slpkg/form_configs.py index 8e50a751..0b6572c9 100644 --- a/slpkg/form_configs.py +++ b/slpkg/form_configs.py @@ -61,7 +61,7 @@ class FormConfigs: self.dialog.textbox(self.config_file, 40, 60) self.edit() - def check_configs(self, configs, tags): + def check_configs(self, configs: dict, tags: list) -> bool: """ Check for true of false values. """ for key, value in zip(configs['configs'].keys(), tags): if key in ['colors', 'dialog'] and value not in ['true', 'false']: @@ -74,7 +74,7 @@ class FormConfigs: with open(self.config_file, 'r') as toml_file: self.orig_configs = toml_file.readlines() - def write_file(self, configs, tags): + def write_file(self, configs: dict, tags: list): """ Write the new values to the config file. """ self.read_file() with open(self.config_file, 'w') as patch_toml: diff --git a/slpkg/slackbuild.py b/slpkg/slackbuild.py index f125b2df..00991f27 100644 --- a/slpkg/slackbuild.py +++ b/slpkg/slackbuild.py @@ -75,7 +75,7 @@ class Slackbuilds: self.install_order.extend(self.dependencies) - def choose_dependencies(self, dependencies): + def choose_dependencies(self, dependencies: list): """ Choose packages for install. """ height = 10 width = 70 diff --git a/slpkg/tracking.py b/slpkg/tracking.py index b4bfebb1..7e6436bf 100644 --- a/slpkg/tracking.py +++ b/slpkg/tracking.py @@ -12,7 +12,7 @@ class Tracking: self.configs = Configs self.colors = self.configs.colour - def packages(self, packages): + def packages(self, packages: list): """ Prints the packages dependencies. """ color = self.colors() cyan = color['cyan'] diff --git a/slpkg/update_repository.py b/slpkg/update_repository.py index 83f019a8..ac43641d 100644 --- a/slpkg/update_repository.py +++ b/slpkg/update_repository.py @@ -17,7 +17,7 @@ from slpkg.models.models import session as Session class UpdateRepository: """ Deletes and install the data. """ - def __init__(self, flags): + def __init__(self, flags: list): self.flags = flags self.configs = Configs self.session = Session diff --git a/slpkg/views/views.py b/slpkg/views/views.py index 3e3f3805..9935bfdb 100644 --- a/slpkg/views/views.py +++ b/slpkg/views/views.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import os +from typing import Any from slpkg.configs import Configs from slpkg.queries import SBoQueries @@ -65,7 +66,7 @@ class ViewMessage: version = SBoQueries(sbo).version() self._view_download(sbo, version) - def remove_packages(self, packages: list): + def remove_packages(self, packages: list) -> Any: """ View remove packages. """ slackbuilds, dependencies, deps = [], [], [] for pkg in packages: @@ -100,7 +101,7 @@ class ViewMessage: return self.installed_packages, dependencies - def choose_dependencies_for_remove(self, dependencies): + def choose_dependencies_for_remove(self, dependencies: list) -> list: """ Choose packages for remove. """ height = 10 width = 70 From cfccbf8b71587993ab11bac1eff324d739b86cdd Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Thu, 29 Dec 2022 17:42:44 +0200 Subject: [PATCH 30/30] Added dialog to find command --- slpkg/main.py | 16 ++++++++++++---- slpkg/utilities.py | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/slpkg/main.py b/slpkg/main.py index 9cefd676..5d6b3eef 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -86,9 +86,10 @@ class Argparse: title = f' Choose packages you want to {method} ' repo_packages = SBoQueries('').sbos() - if method == 'remove': - # Grab all the installed packages - installed = os.listdir(self.configs.log_packages) + # Grab all the installed packages + installed = os.listdir(self.configs.log_packages) + + if method in ['remove', 'find']: for package in installed: name = self.utils.split_installed_pkg(package)[0] @@ -304,9 +305,16 @@ class Argparse: self.usage.help(1) def find(self): - if len(self.args) >= 2 and not self.flags: + if [f for f in self.flags if f not in [self.flag_search]]: + self.usage.help(1) + + if len(self.args) >= 2: packages = list(set(self.args[1:])) + if '--search' in self.flags: + packages = self.choose_packages(packages, + Argparse.find.__name__) + self.check.database() find = FindInstalled() diff --git a/slpkg/utilities.py b/slpkg/utilities.py index c49c91a6..625cb602 100644 --- a/slpkg/utilities.py +++ b/slpkg/utilities.py @@ -22,6 +22,7 @@ class Utilities: pkg = self.split_installed_pkg(package)[0] if pkg == name and self.configs.sbo_repo_tag in package and pkg not in self.black.get(): return package + return '' @staticmethod def untar_archive(path: str, archive: str, ext_path: str):