diff --git a/ChangeLog.txt b/ChangeLog.txt index d9b07765..021d16ef 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,4 +1,8 @@ -4.3.8 - 17/12/2022 +4.3.9 - 22/12/2022 +Added: +- Feature to check the ChangeLog.txt file before update #153 +- Dependees command + BugFixed: - View installed version - slpkg issue : permission denied #152 diff --git a/README.rst b/README.rst index 18d83c25..5c99d3ab 100644 --- a/README.rst +++ b/README.rst @@ -30,8 +30,8 @@ Install from the official third-party `SBo repository DESCRIPTION: @@ -60,6 +59,7 @@ Usage -f, find Find installed packages. -w, view View packages from the repository. -s, search Search packages from the repository. + -e, dependees Show which packages depend. OPTIONS: --yes Answer Yes to all questions. @@ -88,10 +88,10 @@ Usage Total 6 packages will be installed and 0 will be upgraded. - Do you want to continue [y/N]: + Do you want to continue (y/N)?: - $ slpkg remove Flask + $ slpkg remove Flask The following packages will be removed: [ delete ] -> Flask-2.1.2-x86_64-1_SBo @@ -105,7 +105,28 @@ Usage Total 6 packages will be removed. - Do you want to continue [y/N]: + Do you want to continue (y/N)?: + + + $ slpkg dependees vlc + The list below shows the packages that dependees 'vlc' files: + + Collecting the data... + + vlc + └─kaffeine + ├─ vlc + obs-studio + ├─ faac luajit rtmpdump x264 jack libfdk-aac mbedtls vlc + vlsub + ├─ vlc + sopcast-player + └─ sopcast vlc + + 4 dependees for vlc + + + Configuration files diff --git a/man/slpkg.1 b/man/slpkg.1 index 23020b8d..f3578969 100644 --- a/man/slpkg.1 +++ b/man/slpkg.1 @@ -1,10 +1,10 @@ -.TH slpkg 1 "Orestiada, Greece" "slpkg 4.3.1" dslackw +.TH slpkg 1 "Orestiada, Greece" "slpkg 4.3.9" dslackw .SH NAME .P slpkg - [OPTIONS] [COMMAND] .SH SYNAPSES .P -slpkg [-h|-v] [update] [upgrade] [check-updates] [clean-logs] [clean-tmp] [-b, build] [-i, install] [-d, download] [-r, remove] [-f, find] [-w, view] [-s, search] --yes --jobs --resolve-off --reinstall --skip-installed +slpkg [-h|-v] [update] [upgrade] [check-updates] [clean-logs] [clean-tmp] [-b, build] [-i, install] [-d, download] [-r, remove] [-f, find] [-w, view] [-s, search] [-e, dependees] --yes --jobs --resolve-off --reinstall --skip-installed .SH DESCRIPTION .P Slpkg is a software package manager that installs, updates, and removes packages on Slackware based systems. It automatically computes dependencies and figures out what things should occur to install packages. Slpkg makes it easier to maintain groups of machines without having to manually update. @@ -71,6 +71,11 @@ View packages from the repository and get everything in your terminal. .RS Search and match packages from the repository. .RE +.P +-e, dependees +.RS +Show which SlackBuilds depend on. +.RE .SH OPTIONS .P --yes @@ -98,10 +103,11 @@ Use this option if you want to upgrade all packages even if the same version is This a helpful option if you want to avoid building and reinstalling packages. Note: This option affects only the dependencies. .RE +.RE .P -h | --help .RS -Show help informatio and exit. +Show help information and exit. .RE .P -v | --version diff --git a/requirements.txt b/requirements.txt index 90355720..4c37dd2f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ SQLAlchemy>=1.4.36 -toml>=0.10.2 -setuptools~=60.2.0 +toml>=0.10.2 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index d9209af4..8adc8964 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = slpkg -version = 4.3.8 +version = 4.3.9 license_file = LICENSE author = Dimitris Zlatanidis author_email = d.zlatanidis@gmail.com diff --git a/slpkg/blacklist.py b/slpkg/blacklist.py index 20586e07..412b0828 100644 --- a/slpkg/blacklist.py +++ b/slpkg/blacklist.py @@ -14,7 +14,8 @@ class Blacklist: def __init__(self): self.configs = Configs - def get(self): + def get(self) -> list: + """ Reads the blacklist file. """ file = f'{self.configs.etc_path}/blacklist.toml' if os.path.isfile(file): with open(file, 'rb') as black: diff --git a/slpkg/check_updates.py b/slpkg/check_updates.py index 2ee72212..837c1ea1 100644 --- a/slpkg/check_updates.py +++ b/slpkg/check_updates.py @@ -14,7 +14,9 @@ class CheckUpdates: def __init__(self): self.configs = Configs - def updates(self): + def check(self) -> bool: + """ Checks the ChangeLogs and returns True or False. """ + print(end='\rChecking for news in the Changelog.txt file... ') local_date = 0 local_chg_txt = (f'{self.configs.sbo_repo_path}/' f'{self.configs.chglog_txt}') @@ -28,7 +30,10 @@ class CheckUpdates: repo_date = int(repo.headers['Content-Length']) - if repo_date != local_date: - print('\nThere are new updates available.\n') + return repo_date != local_date + + def updates(self): + if self.check(): + print('\n\nThere are new updates available!\n') else: - print('\nNo updated packages since the last check.\n') + print('\n\nNo updated packages since the last check.\n') diff --git a/slpkg/checks.py b/slpkg/checks.py index dd9cf918..5a12ede8 100644 --- a/slpkg/checks.py +++ b/slpkg/checks.py @@ -38,7 +38,7 @@ class Check: if 'UNSUPPORTED' in sources: raise SystemExit(f"\nPackage '{sbo}' unsupported by arch.\n") - def installed(self, slackbuilds: list): + def installed(self, slackbuilds: list) -> list: """ Checking for installed packages. """ found, not_found = [], [] diff --git a/slpkg/checksum.py b/slpkg/checksum.py index 5bd043b1..8bf953bf 100644 --- a/slpkg/checksum.py +++ b/slpkg/checksum.py @@ -10,10 +10,11 @@ from slpkg.views.views import ViewMessage class Md5sum: """ Checksum the sources. """ - def __init__(self, flags): + def __init__(self, flags: list): self.flags = flags def check(self, path: str, source: str, checksum: str, name: str): + """ Checksum the source. """ filename = f'{path}/{source.split("/")[-1]}' md5 = self.read_file(filename) @@ -30,5 +31,6 @@ class Md5sum: @staticmethod def read_file(filename: str): + """ Reads the text file. """ with open(filename, 'rb') as f: return f.read() diff --git a/slpkg/clean_logs.py b/slpkg/clean_logs.py index c5cb2c29..5d617602 100644 --- a/slpkg/clean_logs.py +++ b/slpkg/clean_logs.py @@ -10,11 +10,12 @@ from slpkg.models.models import session as Session class CleanLogsDependencies: """ Cleans the logs from packages. """ - def __init__(self, flags): + def __init__(self, flags: list): self.flags = flags self.session = Session def clean(self): + """ Deletes the log table from the database. """ dependencies = self.session.query( LogsDependencies.name, LogsDependencies.requires).all() diff --git a/slpkg/configs.py b/slpkg/configs.py index 74dae696..f450b34d 100644 --- a/slpkg/configs.py +++ b/slpkg/configs.py @@ -90,8 +90,9 @@ class Configs: # Wget options wget_options: str = config['wget_options'] - except KeyError as err: - raise KeyError(f"ERROR: {err} in the configurations.") + except KeyError: + print("Error: check the configuration file " + "in the '/etc/slpkg/' folder.\n") # Creating the paths if not exists paths = [tmp_slpkg, diff --git a/slpkg/create_data.py b/slpkg/create_data.py index 2f151554..46e914fe 100644 --- a/slpkg/create_data.py +++ b/slpkg/create_data.py @@ -15,6 +15,7 @@ class CreateData: self.session = Session def insert_sbo_table(self): + """ Install the data. """ sbo_tags = [ 'SLACKBUILD NAME:', 'SLACKBUILD LOCATION:', @@ -57,5 +58,6 @@ class CreateData: @staticmethod def read_file(file: str): + """ Reads the text file. """ with open(file, 'r', encoding='utf-8') as f: return f.readlines() diff --git a/slpkg/dependees.py b/slpkg/dependees.py new file mode 100644 index 00000000..1156f52f --- /dev/null +++ b/slpkg/dependees.py @@ -0,0 +1,61 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + + +from slpkg.configs import Configs +from slpkg.queries import SBoQueries + + +class Dependees: + """ Show which packages depend. """ + + def __init__(self, packages: list): + self.packages = packages + self.configs = Configs + self.colors = self.configs.colour + + def slackbuilds(self): + """ Collecting the dependees. """ + color = self.colors() + cyan = color['cyan'] + grey = color['grey'] + yellow = color['yellow'] + endc = color['endc'] + + print(f"The list below shows the " + f"packages that dependees '{', '.join([p for p in self.packages])}' files:\n") + + print(end='\rCollecting the data... ') + + dependees = {} + for package in self.packages: + found = [] # Reset list every package + sbos = SBoQueries('').names() + + for sbo in sbos: + requires = SBoQueries(sbo).requires() + + if package in requires: + found.append(sbo) + dependees[package] = found + + last = ' └─' + print('\n') + + for key, value in dependees.items(): + print(f'{yellow}{key}{endc}') + print(end=f'\r{last}') + char = ' ├─' + + for i, v in enumerate(value, start=1): + if i == len(value): + char = last + + if i == 1: + print(f'{cyan}{v}{endc}') + else: + print(f'{" " * 3}{cyan}{v}{endc}') + + print(f'{" " * 4}{char} {" ".join([req for req in SBoQueries(v).requires()])}') + + print(f'\n{grey}{len(value)} dependees for {key}{endc}\n') diff --git a/slpkg/dependencies.py b/slpkg/dependencies.py index e19c7ae7..c16c5b1b 100644 --- a/slpkg/dependencies.py +++ b/slpkg/dependencies.py @@ -9,10 +9,11 @@ class Requires: """ Creates a list of dependencies with the right order to install. """ - def __init__(self, name): + def __init__(self, name: str): self.name = name def resolve(self) -> list: + """ Resolve the dependencies. """ requires = SBoQueries(self.name).requires() for req in requires: diff --git a/slpkg/download_only.py b/slpkg/download_only.py index 17a25b09..e30ac419 100644 --- a/slpkg/download_only.py +++ b/slpkg/download_only.py @@ -12,12 +12,13 @@ from slpkg.models.models import session as Session class Download: """ Download the slackbuilds with the sources only. """ - def __init__(self, flags): + def __init__(self, flags: list): self.flags: list = flags self.configs = Configs self.session = Session def packages(self, slackbuilds: list): + """ Download the package only. """ view = ViewMessage(self.flags) view.download_packages(slackbuilds) view.question() @@ -31,5 +32,5 @@ class Download: wget.download(self.configs.download_only, url) sources = SBoQueries(sbo).sources() - for source in sources.split(): + for source in sources: wget.download(self.configs.download_only, source) diff --git a/slpkg/downloader.py b/slpkg/downloader.py index e1be310d..fc112fa1 100644 --- a/slpkg/downloader.py +++ b/slpkg/downloader.py @@ -14,5 +14,6 @@ class Wget: self.wget_options: str = Configs.wget_options def download(self, path: str, url: str): + """ Wget downloader. """ subprocess.call(f'wget {self.wget_options} --directory-prefix={path}' f' {url}', shell=True) diff --git a/slpkg/find_installed.py b/slpkg/find_installed.py index 7ca98fda..7064c6b6 100644 --- a/slpkg/find_installed.py +++ b/slpkg/find_installed.py @@ -16,9 +16,10 @@ class FindInstalled: self.color = colors() def find(self, packages: list): + """ Find the packages. """ matching = [] - print(f'The list below shows the packages ' + print(f'The list below shows the installed packages ' f'that contains \'{", ".join([p for p in packages])}\' files:\n') for pkg in packages: @@ -28,6 +29,7 @@ class FindInstalled: self.matched(matching) def matched(self, matching: list): + """ Print the matched packages. """ if matching: for package in matching: print(f'{self.color["cyan"]}{package}{self.color["endc"]}') diff --git a/slpkg/main.py b/slpkg/main.py index 607d5867..413ccb87 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -7,6 +7,7 @@ import sys from slpkg.checks import Check from slpkg.upgrade import Upgrade from slpkg.configs import Configs +from slpkg.dependees import Dependees from slpkg.utilities import Utilities from slpkg.search import SearchPackage from slpkg.views.cli_menu import Usage @@ -23,7 +24,7 @@ from slpkg.update_repository import UpdateRepository class Argparse: - def __init__(self, args): + def __init__(self, args: list): self.args = args self.flags = [] self.configs = Configs @@ -41,10 +42,17 @@ class Argparse: '--reinstall', '--skip-installed'] - for option in self.options: - if option in self.args: - self.args.remove(option) - self.flags.append(option) + # Check for correct flag + for opt in self.args: + if opt.startswith('--'): + if opt not in self.options and opt not in ['--help', '--version']: + raise SystemExit(f"\nError: flag '{opt}' does not exist.\n") + + # Remove flags from args + for opt in self.options: + if opt in self.args: + self.args.remove(opt) + self.flags.append(opt) def help(self): if len(self.args) == 1 and not self.flags: @@ -66,6 +74,9 @@ class Argparse: self.usage.help(1) def upgrade(self): + if [f for f in self.flags if f not in self.options[:-2]]: + self.usage.help(1) + if len(self.args) == 1: self.check.database() @@ -91,7 +102,10 @@ class Argparse: self.usage.help(1) def build(self): - if len(self.args) >= 2 and '--reinstall' not in self.flags: + if [f for f in self.flags if f not in self.options[:-3]]: + self.usage.help(1) + + if len(self.args) >= 2: packages = list(set(self.args[1:])) self.check.database() @@ -104,6 +118,9 @@ class Argparse: self.usage.help(1) def install(self): + if [f for f in self.flags if f not in self.options[:-1]]: + self.usage.help(1) + if len(self.args) >= 2: packages = list(set(self.args[1:])) @@ -127,7 +144,6 @@ class Argparse: self.check.exists(packages) download = Download(self.flags) download.packages(packages) - raise SystemExit() self.usage.help(1) @@ -146,6 +162,17 @@ class Argparse: raise SystemExit() self.usage.help(1) + def find(self): + if len(self.args) >= 2 and not self.flags: + packages = list(set(self.args[1:])) + + self.check.database() + + find = FindInstalled() + find.find(packages) + raise SystemExit() + self.usage.help(1) + def view(self): if len(self.args) >= 2 and not self.flags: packages = list(set(self.args[1:])) @@ -169,14 +196,15 @@ class Argparse: raise SystemExit() self.usage.help(1) - def find(self): + def dependees(self): if len(self.args) >= 2 and not self.flags: packages = list(set(self.args[1:])) self.check.database() + self.check.exists(packages) - find = FindInstalled() - find.find(packages) + dependees = Dependees(packages) + dependees.slackbuilds() raise SystemExit() self.usage.help(1) @@ -234,7 +262,9 @@ def main(): 'find': argparse.find, '-f': argparse.find, 'search': argparse.search, - '-s': argparse.search + '-s': argparse.search, + 'dependees': argparse.dependees, + '-e': argparse.dependees } try: diff --git a/slpkg/queries.py b/slpkg/queries.py index 101ee59e..4ae220e8 100644 --- a/slpkg/queries.py +++ b/slpkg/queries.py @@ -11,7 +11,7 @@ from slpkg.models.models import session as Session class SBoQueries: """ Queries class for the sbo repository. """ - def __init__(self, name): + def __init__(self, name: str): self.name = name self.session = Session self.configs = Configs @@ -20,10 +20,13 @@ class SBoQueries: if self.name in self.black.get(): self.name = '' - def names(self): - return list(self._names_grabbing()) + def names(self) -> list: + """ Returns all the slackbuilds. """ + names = self.session.query(SBoTable.name).all() + return [name[0] for name in names] - def slackbuild(self): + def slackbuild(self) -> str: + """ Returns a slackbuild. """ sbo = self.session.query( SBoTable.name).filter(SBoTable.name == self.name).first() @@ -31,7 +34,8 @@ class SBoQueries: return sbo[0] return '' - def location(self): + def location(self) -> str: + """ Returns the category of a slackbuild. """ location = self.session.query( SBoTable.location).filter(SBoTable.name == self.name).first() @@ -39,16 +43,19 @@ class SBoQueries: return location[0] return '' - def sources(self): + def sources(self) -> list: + """ Returns the source of a slackbuild. """ source, source64 = self.session.query( SBoTable.download, SBoTable.download64).filter( SBoTable.name == self.name).first() - if source or source64: - return self._chose_arch(source, source64) - return '' + if self.configs.os_arch == 'x86_64' and source64: + return source64.split() - def requires(self): + return source.split() + + def requires(self) -> str: + """ Returns the requirements of a slackbuild. """ requires = self.session.query( SBoTable.requires).filter( SBoTable.name == self.name).first() @@ -61,7 +68,8 @@ class SBoQueries: return requires return '' - def version(self): + def version(self) -> str: + """ Returns the version of a slackbuild. """ version = self.session.query( SBoTable.version).filter( SBoTable.name == self.name).first() @@ -70,22 +78,19 @@ class SBoQueries: return version[0] return '' - def checksum(self): - md5sum, md5sum64, = [], [] + def checksum(self) -> list: + """ Returns the source checksum. """ mds5, md5s64 = self.session.query( SBoTable.md5sum, SBoTable.md5sum64).filter( SBoTable.name == self.name).first() - if mds5: - md5sum.append(mds5) - if md5s64: - md5sum64.append(md5s64) + if self.configs.os_arch == 'x86_64' and md5s64: + return md5s64.split() - if md5sum or md5sum64: - return self._chose_arch(md5sum, md5sum64) - return '' + return mds5.split() - def description(self): + def description(self) -> str: + """ Returns the slackbuild description. """ desc = self.session.query( SBoTable.short_description).filter( SBoTable.name == self.name).first() @@ -94,7 +99,8 @@ class SBoQueries: return desc[0] return '' - def files(self): + def files(self) -> str: + """ Returns the files of a slackbuild. """ files = self.session.query( SBoTable.files).filter( SBoTable.name == self.name).first() @@ -102,13 +108,3 @@ class SBoQueries: if files: return files[0] return '' - - def _chose_arch(self, arch, arch64): - if self.configs.os_arch == 'x86_64' and arch64: - return arch64 - return arch - - def _names_grabbing(self): - names = self.session.query(SBoTable.name).all() - for n in names: - yield n[0] diff --git a/slpkg/remove_packages.py b/slpkg/remove_packages.py index 311f81b0..6556e4f2 100644 --- a/slpkg/remove_packages.py +++ b/slpkg/remove_packages.py @@ -13,7 +13,7 @@ from slpkg.models.models import session as Session class RemovePackages: """ Removes installed packages. """ - def __init__(self, packages, flags): + def __init__(self, packages: list, flags: list): self.packages = packages self.flags = flags self.session = Session diff --git a/slpkg/search.py b/slpkg/search.py index 74093cf0..4effad2d 100644 --- a/slpkg/search.py +++ b/slpkg/search.py @@ -12,7 +12,8 @@ class SearchPackage: def __init__(self): self.colors = Configs.colour - def package(self, packages): + def package(self, packages: list): + """ Searching and print the matched slackbuilds. """ color = self.colors() cyan = color['cyan'] endc = color['endc'] @@ -20,8 +21,8 @@ class SearchPackage: names = SBoQueries('').names() - print(f'The list below shows the packages ' - f'that contains \'{", ".join([p for p in packages])}\' files:\n') + print(f'The list below shows the repo ' + f'packages that contains \'{", ".join([p for p in packages])}\' files:\n') for name in names: for package in packages: diff --git a/slpkg/slackbuild.py b/slpkg/slackbuild.py index f9cb42a3..c2ebde21 100644 --- a/slpkg/slackbuild.py +++ b/slpkg/slackbuild.py @@ -21,7 +21,7 @@ from slpkg.models.models import session as Session class Slackbuilds: """ Download build and install the SlackBuilds. """ - def __init__(self, slackbuilds, flags, install): + def __init__(self, slackbuilds: list, flags: list, install: bool): self.slackbuilds = slackbuilds self.flags = flags self.install = install @@ -200,7 +200,7 @@ class Slackbuilds: cpus = multiprocessing.cpu_count() os.environ['MAKEFLAGS'] = f'-j {cpus}' - def download_sources(self, name: str, sources: str): + def download_sources(self, name: str, sources: list): """ Download the sources. """ wget = Wget() @@ -208,7 +208,7 @@ class Slackbuilds: checksums = SBoQueries(name).checksum() - for source, checksum in zip(sources.split(), checksums[0].split()): + for source, checksum in zip(sources, checksums): wget.download(path, source) md5sum = Md5sum(self.flags) md5sum.check(path, source, checksum, name) diff --git a/slpkg/update_repository.py b/slpkg/update_repository.py index 28d7f147..655488c2 100644 --- a/slpkg/update_repository.py +++ b/slpkg/update_repository.py @@ -10,6 +10,8 @@ from slpkg.downloader import Wget from slpkg.configs import Configs from slpkg.create_data import CreateData from slpkg.models.models import SBoTable +from slpkg.views.views import ViewMessage +from slpkg.check_updates import CheckUpdates from slpkg.models.models import session as Session @@ -21,6 +23,17 @@ class UpdateRepository: self.session = Session def sbo(self): + """ Updated the sbo repository. """ + view = ViewMessage([]) + check_updates = CheckUpdates() + + if not check_updates.check(): + print('\n\nNo changes in ChangeLog.txt between your last update and now.') + else: + print('\n\nThere are new updates available!') + + view.question() + print('Updating the package list...\n') self.delete_file(self.configs.sbo_repo_path, self.configs.sbo_txt) self.delete_file(self.configs.sbo_repo_path, self.configs.chglog_txt) @@ -38,10 +51,12 @@ class UpdateRepository: @staticmethod def delete_file(folder: str, txt_file: str): + """ Delete the file. """ file = f'{folder}/{txt_file}' if path.exists(file): os.remove(file) def delete_sbo_data(self): + """ Delete the table from the database. """ self.session.query(SBoTable).delete() self.session.commit() diff --git a/slpkg/upgrade.py b/slpkg/upgrade.py index 48a8192b..ec5e7101 100644 --- a/slpkg/upgrade.py +++ b/slpkg/upgrade.py @@ -19,8 +19,6 @@ class Upgrade: def packages(self): """ Compares version of packages and returns the maximum. """ - print("Do not forget to run 'slpkg update' before.\n") - repo_packages = SBoQueries('').names() black = Blacklist().get() diff --git a/slpkg/utilities.py b/slpkg/utilities.py index 5fb5dc4f..eb6db319 100644 --- a/slpkg/utilities.py +++ b/slpkg/utilities.py @@ -16,7 +16,7 @@ class Utilities: self.configs = Configs self.black = Blacklist() - def is_installed(self, name: str): + def is_installed(self, name: str) -> str: """ Returns the installed package name. """ for package in os.listdir(self.configs.log_packages): pkg = self.split_installed_pkg(package)[0] @@ -52,7 +52,7 @@ class Utilities: if not os.path.isdir(directory): os.makedirs(directory) - def split_installed_pkg(self, package): + def split_installed_pkg(self, package: str) -> list: """ Split the package by the name, version, arch, build and tag. """ name = '-'.join(package.split('-')[:-3]) version = ''.join(package[len(name):].split('-')[:-2]) diff --git a/slpkg/views/cli_menu.py b/slpkg/views/cli_menu.py index 445a7367..3c4b1a59 100644 --- a/slpkg/views/cli_menu.py +++ b/slpkg/views/cli_menu.py @@ -18,46 +18,48 @@ class Usage: self.endc = color['endc'] def help_short(self): + """ 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, --skip-installed]\n' + f'\n slpkg [{self.yellow}OPTIONS{self.endc}] [--yes, --jobs, --resolve-off, --reinstall, ' + f'--skip-installed]\n' f' slpkg [{self.cyan}COMMAND{self.endc}] [update, upgrade, check-updates, clean-logs, clean-tmp]\n' - f' slpkg [{self.cyan}COMMAND{self.endc}] [-b, build, -i, install, -d, download] \n' - f' slpkg [{self.cyan}COMMAND{self.endc}] [-r, remove, -f, find, -w, view, -s, search] \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' " \nIf you need more information please try 'slpkg --help'.") - print(args) - raise SystemExit() + raise SystemExit(args) def help(self, status: int): - args = [ - f'{self.bold}USAGE:{self.endc} {Configs.prog_name} [{self.yellow}OPTIONS{self.endc}] [{self.cyan}COMMAND{self.endc}] \n', - f'{self.bold}DESCRIPTION:{self.endc}', - ' Packaging tool that interacts with the SBo repository.\n', - f'{self.bold}COMMANDS:{self.endc}', - f' {self.red}update{self.endc} Update the package lists.', - f' {self.cyan}upgrade{self.endc} Upgrade all the packages.', - f' {self.cyan}check-updates{self.endc} Check for news on ChangeLog.txt.', - f' {self.cyan}clean-logs{self.endc} Clean dependencies log tracking.', - f' {self.cyan}clean-tmp{self.endc} Delete all the downloaded sources.', - f' {self.cyan}-b, build{self.endc} Build only the packages.', - f' {self.cyan}-i, install{self.endc} Build and install the packages.', - f' {self.cyan}-d, download{self.endc} Download only the scripts and sources.', - f' {self.cyan}-r, remove{self.endc} Remove installed packages.', - f' {self.cyan}-f, find{self.endc} Find installed packages.', - f' {self.cyan}-w, view{self.endc} View packages from the repository.', - f' {self.cyan}-s, search{self.endc} Search packages from the repository.\n', - f'{self.bold}OPTIONS:{self.endc}', - f' {self.yellow}--yes{self.endc} Answer Yes to all questions.', - f' {self.yellow}--jobs{self.endc} Set it for multicore systems.', - f' {self.yellow}--resolve-off{self.endc} Turns off dependency resolving.', - f' {self.yellow}--reinstall{self.endc} Upgrade packages of the same version.', - f' {self.yellow}--skip-installed{self.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.'] + """ Prints the main menu. """ + args = ( + f'{self.bold}USAGE:{self.endc} {Configs.prog_name} [{self.yellow}OPTIONS{self.endc}] ' + f'[{self.cyan}COMMAND{self.endc}] \n' + f'\n{self.bold}DESCRIPTION:{self.endc} Packaging tool that interacts with the SBo repository.\n' + f'\n{self.bold}COMMANDS:{self.endc}\n' + 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}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' + f' {self.cyan}-i, install{self.endc} Build and install the packages.\n' + f' {self.cyan}-d, download{self.endc} Download only the scripts and sources.\n' + f' {self.cyan}-r, remove{self.endc} Remove installed packages.\n' + f' {self.cyan}-f, find{self.endc} Find installed packages.\n' + f' {self.cyan}-w, view{self.endc} View packages from the repository.\n' + f' {self.cyan}-s, search{self.endc} Search packages from the repository.\n' + f' {self.cyan}-e, dependees{self.endc} Show which packages depend.\n\n' + f'{self.bold}OPTIONS:{self.endc}\n' + f' {self.yellow}--yes{self.endc} Answer Yes to all questions.\n' + f' {self.yellow}--jobs{self.endc} Set it for multicore systems.\n' + f' {self.yellow}--resolve-off{self.endc} Turns off dependency resolving.\n' + f' {self.yellow}--reinstall{self.endc} Upgrade packages of the same version.\n' + f' {self.yellow}--skip-installed{self.endc} Skip installed packages.\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' + 'If you need more information try to use slpkg manpage.') - for opt in args: - print(opt) + print(args) raise SystemExit(status) diff --git a/slpkg/views/version.py b/slpkg/views/version.py index c3a97918..aa9c19cc 100644 --- a/slpkg/views/version.py +++ b/slpkg/views/version.py @@ -6,13 +6,14 @@ class Version: """ Print the version. """ def __init__(self): - self.version_info: tuple = (4, 3, 8) - self.version: str = '{0}.{1}.{2}'.format(*self.version_info) - self.license: str = 'MIT License' - self.author: str = 'Dimitris Zlatanidis (dslackw)' - self.homepage: str = 'https://dslackw.gitlab.io/slpkg' + self.version_info = (4, 3, 9) + self.version = '{0}.{1}.{2}'.format(*self.version_info) + self.license = 'MIT License' + self.author = 'Dimitris Zlatanidis (dslackw)' + self.homepage = 'https://dslackw.gitlab.io/slpkg' def view(self): + """ Prints the version. """ print(f'Version: {self.version}\n' f'Author: {self.author}\n' f'License: {self.license}\n' diff --git a/slpkg/views/view_package.py b/slpkg/views/view_package.py index b9b1f2bb..238ba2cf 100644 --- a/slpkg/views/view_package.py +++ b/slpkg/views/view_package.py @@ -18,9 +18,8 @@ class ViewPackage: self.configs = Configs self.colors = self.configs.colour - def package(self, packages): + def package(self, packages: list): """ View the packages from the repository. """ - http = urllib3.PoolManager() color = self.colors() green = color['green'] blue = color['blue'] @@ -30,6 +29,7 @@ class ViewPackage: endc = color['endc'] for package in packages: + info = self.session.query( SBoTable.name, SBoTable.version, @@ -43,11 +43,9 @@ class ViewPackage: SBoTable.location ).filter(SBoTable.name == package).first() - readme = http.request( - 'GET', f'{self.configs.sbo_repo_url}/{info[9]}/{info[0]}/README') + readme = self.http_request(f'{self.configs.sbo_repo_url}/{info[9]}/{info[0]}/README') - info_file = http.request( - 'GET', f'{self.configs.sbo_repo_url}/{info[9]}/{info[0]}/{info[0]}.info') + info_file = self.http_request(f'{self.configs.sbo_repo_url}/{info[9]}/{info[0]}/{info[0]}.info') maintainer, email, homepage = '', '', '' for line in info_file.data.decode().splitlines(): @@ -64,7 +62,8 @@ class ViewPackage: f'Version: {green}{info[1]}{endc}\n' f'Requires: {green}{deps}{endc}\n' f'Homepage: {blue}{homepage}{endc}\n' - f'Download SlackBuild: {blue}{self.configs.sbo_repo_url}/{info[9]}/{info[0]}{self.configs.sbo_tar_suffix}{endc}\n' + f'Download SlackBuild: {blue}{self.configs.sbo_repo_url}/{info[9]}/{info[0]}' + f'{self.configs.sbo_tar_suffix}{endc}\n' f'Download sources: {blue}{info[3]}{endc}\n' f'Download_x86_64 sources: {blue}{info[4]}{endc}\n' f'Md5sum: {yellow}{info[5]}{endc}\n' @@ -77,3 +76,9 @@ class ViewPackage: f'Maintainer: {yellow}{maintainer}{endc}\n' f'Email: {yellow}{email}{endc}\n' f'\nREADME: {cyan}{readme.data.decode()}{endc}') + + @staticmethod + def http_request(link: str) -> str: + """ Http get request. """ + http = urllib3.PoolManager() + return http.request('GET', link) diff --git a/slpkg/views/views.py b/slpkg/views/views.py index a2a75024..4d774691 100644 --- a/slpkg/views/views.py +++ b/slpkg/views/views.py @@ -14,7 +14,7 @@ from slpkg.models.models import session as Session class ViewMessage: """ Print some messages before. """ - def __init__(self, flags): + def __init__(self, flags: list): self.flags = flags self.configs = Configs self.colors = self.configs.colour @@ -170,7 +170,7 @@ class ViewMessage: print(f'\n{color["grey"]}Total {installed + upgraded} packages ' f'will be removed.{color["endc"]}') - def logs_packages(self, dependencies): + def logs_packages(self, dependencies: list): """ View the logging packages. """ print('The following logs will be removed:\n') color = self.colors() @@ -184,7 +184,7 @@ class ViewMessage: def question(self): """ Manage to proceed. """ if '--yes' not in self.flags: - answer = input('\nDo you want to continue [y/N]: ') + answer = input('\nDo you want to continue (y/N)?: ') if answer not in ['Y', 'y']: raise SystemExit() print() diff --git a/tests/test_checks.py b/tests/test_checks.py index 76402be5..2d2e496c 100644 --- a/tests/test_checks.py +++ b/tests/test_checks.py @@ -6,20 +6,19 @@ class TestPkgInstalled(unittest.TestCase): def setUp(self): self.check = Check() - self.packages = ['Flask', 'colored', 'slpkg'] + self.packages = ['fish', 'ranger', 'pycharm'] def test_check_exists(self): self.assertIsNone(self.check.exists(self.packages)) - def tect_check_unsupported(self): + def test_check_unsupported(self): self.assertIsNone(self.check.unsupported(self.packages)) def test_check_installed(self): - self.assertIsNone(self.check.installed(self.packages)) + self.assertListEqual(self.packages, self.check.installed(self.packages)) def test_check_blacklist(self): - self.assertListEqual(self.packages, - self.check.blacklist(self.packages)) + self.assertIsNone(self.check.blacklist(self.packages)) if __name__ == "__main__": diff --git a/tests/test_colors.py b/tests/test_colors.py index 235b0e24..fe9b873a 100644 --- a/tests/test_colors.py +++ b/tests/test_colors.py @@ -9,12 +9,14 @@ class TestColors(unittest.TestCase): self.color = colors() def test_colors(self): - self.assertIn('BOLD', self.color) - self.assertIn('RED', self.color) - self.assertIn('YELLOW', self.color) - self.assertIn('GREEN', self.color) - self.assertIn('BLUE', self.color) - self.assertIn('GREY', self.color) + self.assertIn('bold', self.color) + self.assertIn('red', self.color) + self.assertIn('yellow', self.color) + self.assertIn('cyan', self.color) + self.assertIn('green', self.color) + self.assertIn('blue', self.color) + self.assertIn('grey', self.color) + self.assertIn('endc', self.color) if __name__ == '__main__': diff --git a/tests/test_queries.py b/tests/test_queries.py index a96068aa..bfb1bf93 100644 --- a/tests/test_queries.py +++ b/tests/test_queries.py @@ -14,17 +14,17 @@ class TestSBoQueries(unittest.TestCase): self.assertEqual('system', self.query.location()) def test_sources(self): - self.assertEqual('https://gitlab.com/dslackw/slpkg/-/archive' - '/4.3.0/slpkg-4.3.0.tar.gz', self.query.sources()) + self.assertEqual(['https://gitlab.com/dslackw/slpkg/-/archive' + '/4.3.7/slpkg-4.3.7.tar.gz'], self.query.sources()) def test_requires(self): - self.assertEqual(['SQLAlchemy'], self.query.requires()) + self.assertEqual(['SQLAlchemy', 'python-toml'], self.query.requires()) def test_version(self): - self.assertEqual('4.3.0', self.query.version()) + self.assertEqual('4.3.7', self.query.version()) def test_checksum(self): - self.assertListEqual(['ab03d0543b74abfce92287db740394c4'], + self.assertListEqual(['5a55fd350004b3e49a060835a7ada3e9'], self.query.checksum()) def test_files(self):