From bc386dffec2dff3ababf6ea22614c6393c6353d5 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Thu, 22 Dec 2022 20:53:37 +0200 Subject: [PATCH] Added a command dependees --- ChangeLog.txt | 5 ++-- README.rst | 2 +- man/slpkg.1 | 12 ++++---- slpkg/dependees.py | 58 +++++++++++++++++++++++++++++++++++++ slpkg/main.py | 30 +++++++++++++------ slpkg/views/cli_menu.py | 14 ++++----- slpkg/views/view_package.py | 20 ++----------- 7 files changed, 97 insertions(+), 44 deletions(-) create mode 100644 slpkg/dependees.py diff --git a/ChangeLog.txt b/ChangeLog.txt index 30e57cce..021d16ef 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,8 +1,7 @@ -4.3.9 - 20/12/2022 +4.3.9 - 22/12/2022 Added: - Feature to check the ChangeLog.txt file before update #153 -- Dependees in the view command -- Flag --dependees +- Dependees command BugFixed: - View installed version diff --git a/README.rst b/README.rst index 173ac233..d30b2a05 100644 --- a/README.rst +++ b/README.rst @@ -60,6 +60,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. @@ -67,7 +68,6 @@ Usage --resolve-off Turns off dependency resolving. --reinstall Upgrade packages of the same version. --skip-installed Skip installed packages. - --dependees Show which packages depend. -h, --help Show this message and exit. -v, --version Print version and exit. diff --git a/man/slpkg.1 b/man/slpkg.1 index 67236ceb..f3578969 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] [-r, remove] [-f, find] [-w, view] [-s, search] --yes --jobs --resolve-off --reinstall --skip-installed, --dependees +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 @@ -100,11 +105,6 @@ Note: This option affects only the dependencies. .RE .RE .P ---dependees -.RS -This flag works only with the -w, view command to show which packages depend. -.RE -.P -h | --help .RS Show help information and exit. diff --git a/slpkg/dependees.py b/slpkg/dependees.py new file mode 100644 index 00000000..de5b717e --- /dev/null +++ b/slpkg/dependees.py @@ -0,0 +1,58 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + + +from slpkg.configs import Configs +from slpkg.queries import SBoQueries + + +class Dependees: + + def __init__(self, packages): + 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])}\' SlackBuilds:\n') + + print(end='\rCollecting the data... ') + + dependees = {} + for package in self.packages: + found = [] + 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' {cyan}{v}{endc}') + print(f' {char} {" ".join([r for r in SBoQueries(v).requires()])}') + + print(f'\n{grey}{len(value)} dependees for {key}{endc}\n') diff --git a/slpkg/main.py b/slpkg/main.py index f2fb7b06..135ead8b 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 @@ -162,17 +163,25 @@ class Argparse: raise SystemExit() self.usage.help(1) - def view(self): - if [f for f in self.flags if f not in self.options[5]]: - self.usage.help(1) + def find(self): + if len(self.args) >= 2 and not self.flags: + packages = list(set(self.args[1:])) - if len(self.args) >= 2: + 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:])) self.check.database() self.check.exists(packages) - view = ViewPackage(self.flags) + view = ViewPackage() view.package(packages) raise SystemExit() self.usage.help(1) @@ -188,14 +197,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) @@ -253,7 +263,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/views/cli_menu.py b/slpkg/views/cli_menu.py index 9070e8a4..1343ecdc 100644 --- a/slpkg/views/cli_menu.py +++ b/slpkg/views/cli_menu.py @@ -21,11 +21,11 @@ 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' - ' --skip-installed, --dependees]\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) @@ -49,14 +49,14 @@ class Usage: 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.cyan}-s, search{self.endc} Search packages from the repository.', + f' {self.cyan}-e, dependees{self.endc} Show which packages depend.\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.', - f' {self.yellow}--dependees{self.endc} Show which packages depend.\n', + 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.', diff --git a/slpkg/views/view_package.py b/slpkg/views/view_package.py index 8594ed05..60e43104 100644 --- a/slpkg/views/view_package.py +++ b/slpkg/views/view_package.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- -import sys import urllib3 from slpkg.configs import Configs @@ -14,8 +13,7 @@ from slpkg.models.models import session as Session class ViewPackage: """ View the repository packages. """ - def __init__(self, flags): - self.flags = flags + def __init__(self): self.session = Session self.configs = Configs self.colors = self.configs.colour @@ -30,11 +28,8 @@ class ViewPackage: red = color['red'] endc = color['endc'] - print(end='\rCollecting the data... ') for package in packages: - dependees = " ".join(list(self.dependees(package))) - info = self.session.query( SBoTable.name, SBoTable.version, @@ -63,10 +58,9 @@ class ViewPackage: deps = (', '.join([f'{pkg} ({SBoQueries(pkg).version()})' for pkg in info[2].split()])) - print(f'\n\nName: {green}{info[0]}{endc}\n' + print(f'Name: {green}{info[0]}{endc}\n' f'Version: {green}{info[1]}{endc}\n' f'Requires: {green}{deps}{endc}\n' - f'Dependees: {green}{dependees}{endc}\n' f'Homepage: {blue}{homepage}{endc}\n' f'Download SlackBuild: {blue}{self.configs.sbo_repo_url}/{info[9]}/{info[0]}' f'{self.configs.sbo_tar_suffix}{endc}\n' @@ -83,16 +77,6 @@ class ViewPackage: f'Email: {yellow}{email}{endc}\n' f'\nREADME: {cyan}{readme.data.decode()}{endc}') - def dependees(self, name): - """ Collecting the dependees. """ - if '--dependees' in self.flags: - sbos = SBoQueries(name).names() - for sbo in sbos: - requires = SBoQueries(sbo).requires() - if name in requires: - version = SBoQueries(sbo).version() - yield f'{sbo} ({version})' - @staticmethod def http_request(link): """ Http get request. """