diff --git a/slpkg/main.py b/slpkg/main.py index 92c3badc..ceb694fc 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -17,7 +17,7 @@ from slpkg.find_installed import FindInstalled from slpkg.views.view_package import ViewPackage from slpkg.remove_packages import RemovePackages from slpkg.clean_logs import CleanLogsDependencies -from slpkg.views.cli_menu import usage, usage_short +from slpkg.views.cli_menu import Usage from slpkg.update_repository import UpdateRepository @@ -26,11 +26,12 @@ class Argparse: def __init__(self, args): self.args: list = args + self.usage = Usage() self.flag() self.check = Check() if len(self.args) == 0: - usage_short() + self.usage.help_short() self.check.blacklist(self.args) @@ -50,22 +51,22 @@ class Argparse: def help(self): if len(self.args) == 1 and not self.flags: - usage(0) - usage(1) + self.usage.help(0) + self.usage.help(1) def version(self): if len(self.args) == 1 and not self.flags: version = Version() version.view() raise SystemExit() - usage(1) + self.usage.help(1) def update(self): if len(self.args) == 1 and not self.flags: update = UpdateRepository() update.sbo() raise SystemExit() - usage(1) + self.usage.help(1) def upgrade(self): if len(self.args) == 1: @@ -81,7 +82,7 @@ class Argparse: install = Slackbuilds(packages, self.flags, install=True) install.execute() raise SystemExit() - usage(1) + self.usage.help(1) def check_updates(self): if len(self.args) == 1 and not self.flags: @@ -90,7 +91,7 @@ class Argparse: check = CheckUpdates() check.updates() raise SystemExit() - usage(1) + self.usage.help(1) def build(self): if len(self.args) >= 2 and '--reinstall' not in self.flags: @@ -103,7 +104,7 @@ class Argparse: build = Slackbuilds(packages, self.flags, install=False) build.execute() raise SystemExit() - usage(1) + self.usage.help(1) def install(self): if len(self.args) >= 2: @@ -116,11 +117,11 @@ class Argparse: install = Slackbuilds(packages, self.flags, install=True) install.execute() raise SystemExit() - usage(1) + self.usage.help(1) def download(self): if [f for f in self.flags if f in self.options[1:]]: - usage(1) + self.usage.help(1) if len(self.args) >= 2: packages = list(set(self.args[1:])) @@ -131,11 +132,11 @@ class Argparse: download.packages(packages) raise SystemExit() - usage(1) + self.usage.help(1) def remove(self): if [f for f in self.flags if f in self.options[1:]]: - usage(1) + self.usage.help(1) if len(self.args) >= 2: packages = list(set(self.args[1:])) @@ -146,7 +147,7 @@ class Argparse: remove = RemovePackages(packages, self.flags) remove.remove() raise SystemExit() - usage(1) + self.usage.help(1) def view(self): if len(self.args) >= 2 and not self.flags: @@ -158,7 +159,7 @@ class Argparse: view = ViewPackage() view.package(packages) raise SystemExit() - usage(1) + self.usage.help(1) def search(self): if len(self.args) >= 2 and not self.flags: @@ -169,7 +170,7 @@ class Argparse: search = SearchPackage() search.package(packages) raise SystemExit() - usage(1) + self.usage.help(1) def find(self): if len(self.args) >= 2 and not self.flags: @@ -180,11 +181,11 @@ class Argparse: find = FindInstalled() find.find(packages) raise SystemExit() - usage(1) + self.usage.help(1) def clean_logs(self): if [f for f in self.flags if f in self.options[1:]]: - usage(1) + self.usage.help(1) if len(self.args) == 1: self.check.database() @@ -192,7 +193,7 @@ class Argparse: logs = CleanLogsDependencies(self.flags) logs.clean() raise SystemExit() - usage(1) + self.usage.help(1) def clean_tmp(self): if len(self.args) == 1 and not self.flags: @@ -204,7 +205,7 @@ class Argparse: utils.remove_folder_if_exists(path, folder) utils.create_folder(tmp_slpkg, 'build') raise SystemExit() - usage(1) + self.usage.help(1) def main(): @@ -242,7 +243,7 @@ def main(): try: arguments[args[0]]() except KeyError: - usage(1) + Usage().help(1) if __name__ == '__main__': diff --git a/slpkg/update_repository.py b/slpkg/update_repository.py index bbeb708b..daf1da04 100644 --- a/slpkg/update_repository.py +++ b/slpkg/update_repository.py @@ -17,26 +17,21 @@ class UpdateRepository: ''' Deletes and install the data. ''' def __init__(self): - self.sbo_repo_path: str = Configs.sbo_repo_path - self.url: str = Configs.sbo_repo_url - self.sbo_txt: str = Configs.sbo_txt - self.chglog_txt: str = Configs.chglog_txt - self.db_path: str = Configs.db_path - self.database: str = Configs.database + self.configs: str = Configs self.session: str = Session def sbo(self): print('Updating the package list...\n') - self.delete_file(self.sbo_repo_path, self.sbo_txt) - self.delete_file(self.sbo_repo_path, self.chglog_txt) + self.delete_file(self.configs.sbo_repo_path, self.configs.sbo_txt) + self.delete_file(self.configs.sbo_repo_path, self.configs.chglog_txt) self.delete_sbo_data() - slackbuilds_txt = f'{self.url}/{self.sbo_txt}' - changelog_txt = f'{self.url}/{self.chglog_txt}' + slackbuilds_txt = f'{self.configs.sbo_repo_url}/{self.configs.sbo_txt}' + changelog_txt = f'{self.configs.sbo_repo_url}/{self.configs.chglog_txt}' wget = Wget() - wget.download(self.sbo_repo_path, slackbuilds_txt) - wget.download(self.sbo_repo_path, changelog_txt) + wget.download(self.configs.sbo_repo_path, slackbuilds_txt) + wget.download(self.configs.sbo_repo_path, changelog_txt) data = CreateData() data.insert_sbo_table() diff --git a/slpkg/upgrade.py b/slpkg/upgrade.py index c58e9b02..b7f1f269 100644 --- a/slpkg/upgrade.py +++ b/slpkg/upgrade.py @@ -13,8 +13,7 @@ class Upgrade: ''' Upgrade the installed packages. ''' def __init__(self): - self.log_packages: str = Configs.log_packages - self.sbo_repo_tag: str = Configs.sbo_repo_tag + self.configs: str = Configs def packages(self): ''' Compares version of packages and returns the maximum. ''' @@ -23,9 +22,10 @@ class Upgrade: repo_packages = SBoQueries('').names() black = Blacklist().get() - for pkg in os.listdir(self.log_packages): + for pkg in os.listdir(self.configs.log_packages): inst_pkg_name = '-'.join(pkg.split('-')[:-3]) - if pkg.endswith(self.sbo_repo_tag) and inst_pkg_name not in black: + if (pkg.endswith(self.configs.sbo_repo_tag) + and inst_pkg_name not in black): if inst_pkg_name in repo_packages: installed_ver = pkg.replace(f'{inst_pkg_name}-', diff --git a/slpkg/utilities.py b/slpkg/utilities.py index 2706bdba..ce1ed960 100644 --- a/slpkg/utilities.py +++ b/slpkg/utilities.py @@ -13,7 +13,7 @@ from slpkg.configs import Configs class Utilities: def __init__(self): - self.log_packages: str = Configs.log_packages + self.configs: str = Configs def untar_archive(self, path: str, archive: str, ext_path: str): ''' Untar the file to the build folder. ''' @@ -24,7 +24,7 @@ class Utilities: def is_installed(self, package: str): ''' Returns True if a package is installed. ''' - for pkg in os.listdir(self.log_packages): + for pkg in os.listdir(self.configs.log_packages): if package in pkg: return pkg diff --git a/slpkg/views/cli_menu.py b/slpkg/views/cli_menu.py index 3d451fda..7947124a 100644 --- a/slpkg/views/cli_menu.py +++ b/slpkg/views/cli_menu.py @@ -5,55 +5,57 @@ from slpkg.configs import Configs -def usage_short(): - args = (f'Usage: {Configs.prog_name} [OPTIONS] [COMMAND] \n' - '\n slpkg [OPTIONS] {--yes, --jobs, --resolve-off, --reinstall, --skip-installed}\n' - ' slpkg [COMMAND] {update, upgrade, check-updates, clean-logs, clean-tmp}\n' - ' slpkg [COMMAND] {-b, build, -i, install, -d, download} \n' - ' slpkg [COMMAND] {-r, remove, -f, find, -w, view, -s, search} \n' - " \nIf you need more information please try 'slpkg --help'.") +class Usage: - print(args) - raise SystemExit() + def help_short(self): + args = (f'Usage: {Configs.prog_name} [OPTIONS] [COMMAND] \n' + '\n slpkg [OPTIONS] {--yes, --jobs, --resolve-off, --reinstall, --skip-installed}\n' + ' slpkg [COMMAND] {update, upgrade, check-updates, clean-logs, clean-tmp}\n' + ' slpkg [COMMAND] {-b, build, -i, install, -d, download} \n' + ' slpkg [COMMAND] {-r, remove, -f, find, -w, view, -s, search} \n' + " \nIf you need more information please try 'slpkg --help'.") + + print(args) + raise SystemExit() -def usage(status: int): - colors = Configs.colour - color = colors() + def help(self, status: int): + colors = Configs.colour + color = colors() - BOLD = color['BOLD'] - RED = color['RED'] - CYAN = color['CYAN'] - YELLOW = color['YELLOW'] - ENDC = color['ENDC'] + BOLD = color['BOLD'] + RED = color['RED'] + CYAN = color['CYAN'] + YELLOW = color['YELLOW'] + ENDC = color['ENDC'] - args = [f'{BOLD}USAGE:{ENDC} {Configs.prog_name} [{YELLOW}OPTIONS{ENDC}] [{CYAN}COMMAND{ENDC}] \n', - f'{BOLD}DESCRIPTION:{ENDC}', - ' Packaging tool that interacts with the SBo repository.\n', - f'{BOLD}COMMANDS:{ENDC}', - f' {RED}update{ENDC} Update the package lists.', - f' {CYAN}upgrade{ENDC} Upgrade all the packages.', - f' {CYAN}check-updates{ENDC} Check for news on ChangeLog.txt.', - f' {CYAN}clean-logs{ENDC} Clean dependencies log tracking.', - f' {CYAN}clean-tmp{ENDC} Delete all the downloaded sources.', - f' {CYAN}-b, build{ENDC} Build only the packages.', - f' {CYAN}-i, install{ENDC} Build and install the packages.', - f' {CYAN}-d, download{ENDC} Download only the scripts and sources.', - f' {CYAN}-r, remove{ENDC} Remove installed packages.', - f' {CYAN}-f, find{ENDC} Find installed packages.', - f' {CYAN}-w, view{ENDC} View packages from the repository.', - f' {CYAN}-s, search{ENDC} Search packages from the repository.\n', - f'{BOLD}OPTIONS:{ENDC}', - f' {YELLOW}--yes{ENDC} Answer Yes to all questions.', - f' {YELLOW}--jobs{ENDC} Set it for multicore systems.', - f' {YELLOW}--resolve-off{ENDC} Turns off dependency resolving.', - f' {YELLOW}--reinstall{ENDC} Upgrade packages of the same version.', - f' {YELLOW}--skip-installed{ENDC} Skip installed packages.\n', - ' -h, --help Show this message and exit.', - ' -v, --version Print version and exit.\n', - 'Edit the configuration file in the /etc/slpkg/slpkg.toml.', - 'If you need more information try to use slpkg manpage.'] + args = [f'{BOLD}USAGE:{ENDC} {Configs.prog_name} [{YELLOW}OPTIONS{ENDC}] [{CYAN}COMMAND{ENDC}] \n', + f'{BOLD}DESCRIPTION:{ENDC}', + ' Packaging tool that interacts with the SBo repository.\n', + f'{BOLD}COMMANDS:{ENDC}', + f' {RED}update{ENDC} Update the package lists.', + f' {CYAN}upgrade{ENDC} Upgrade all the packages.', + f' {CYAN}check-updates{ENDC} Check for news on ChangeLog.txt.', + f' {CYAN}clean-logs{ENDC} Clean dependencies log tracking.', + f' {CYAN}clean-tmp{ENDC} Delete all the downloaded sources.', + f' {CYAN}-b, build{ENDC} Build only the packages.', + f' {CYAN}-i, install{ENDC} Build and install the packages.', + f' {CYAN}-d, download{ENDC} Download only the scripts and sources.', + f' {CYAN}-r, remove{ENDC} Remove installed packages.', + f' {CYAN}-f, find{ENDC} Find installed packages.', + f' {CYAN}-w, view{ENDC} View packages from the repository.', + f' {CYAN}-s, search{ENDC} Search packages from the repository.\n', + f'{BOLD}OPTIONS:{ENDC}', + f' {YELLOW}--yes{ENDC} Answer Yes to all questions.', + f' {YELLOW}--jobs{ENDC} Set it for multicore systems.', + f' {YELLOW}--resolve-off{ENDC} Turns off dependency resolving.', + f' {YELLOW}--reinstall{ENDC} Upgrade packages of the same version.', + f' {YELLOW}--skip-installed{ENDC} Skip installed packages.\n', + ' -h, --help Show this message and exit.', + ' -v, --version Print version and exit.\n', + 'Edit the configuration file in the /etc/slpkg/slpkg.toml.', + 'If you need more information try to use slpkg manpage.'] - for opt in args: - print(opt) - raise SystemExit(status) + for opt in args: + print(opt) + raise SystemExit(status)