Added a command dependees

This commit is contained in:
Dimitris Zlatanidis 2022-12-22 20:53:37 +02:00
parent e45bba96cb
commit bc386dffec
7 changed files with 97 additions and 44 deletions

View file

@ -1,8 +1,7 @@
4.3.9 - 20/12/2022 4.3.9 - 22/12/2022
Added: Added:
- Feature to check the ChangeLog.txt file before update #153 - Feature to check the ChangeLog.txt file before update #153
- Dependees in the view command - Dependees command
- Flag --dependees
BugFixed: BugFixed:
- View installed version - View installed version

View file

@ -60,6 +60,7 @@ Usage
-f, find <packages> Find installed packages. -f, find <packages> Find installed packages.
-w, view <packages> View packages from the repository. -w, view <packages> View packages from the repository.
-s, search <packages> Search packages from the repository. -s, search <packages> Search packages from the repository.
-e, dependees <packages> Show which packages depend.
OPTIONS: OPTIONS:
--yes Answer Yes to all questions. --yes Answer Yes to all questions.
@ -67,7 +68,6 @@ Usage
--resolve-off Turns off dependency resolving. --resolve-off Turns off dependency resolving.
--reinstall Upgrade packages of the same version. --reinstall Upgrade packages of the same version.
--skip-installed Skip installed packages. --skip-installed Skip installed packages.
--dependees Show which packages depend.
-h, --help Show this message and exit. -h, --help Show this message and exit.
-v, --version Print version and exit. -v, --version Print version and exit.

View file

@ -4,7 +4,7 @@
slpkg - [OPTIONS] [COMMAND] <packages> slpkg - [OPTIONS] [COMMAND] <packages>
.SH SYNAPSES .SH SYNAPSES
.P .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 .SH DESCRIPTION
.P .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. 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 .RS
Search and match packages from the repository. Search and match packages from the repository.
.RE .RE
.P
-e, dependees
.RS
Show which SlackBuilds depend on.
.RE
.SH OPTIONS .SH OPTIONS
.P .P
--yes --yes
@ -100,11 +105,6 @@ Note: This option affects only the dependencies.
.RE .RE
.RE .RE
.P .P
--dependees
.RS
This flag works only with the -w, view command to show which packages depend.
.RE
.P
-h | --help -h | --help
.RS .RS
Show help information and exit. Show help information and exit.

58
slpkg/dependees.py Normal file
View file

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

View file

@ -7,6 +7,7 @@ import sys
from slpkg.checks import Check from slpkg.checks import Check
from slpkg.upgrade import Upgrade from slpkg.upgrade import Upgrade
from slpkg.configs import Configs from slpkg.configs import Configs
from slpkg.dependees import Dependees
from slpkg.utilities import Utilities from slpkg.utilities import Utilities
from slpkg.search import SearchPackage from slpkg.search import SearchPackage
from slpkg.views.cli_menu import Usage from slpkg.views.cli_menu import Usage
@ -162,17 +163,25 @@ class Argparse:
raise SystemExit() raise SystemExit()
self.usage.help(1) self.usage.help(1)
def view(self): def find(self):
if [f for f in self.flags if f not in self.options[5]]: if len(self.args) >= 2 and not self.flags:
self.usage.help(1) 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:])) packages = list(set(self.args[1:]))
self.check.database() self.check.database()
self.check.exists(packages) self.check.exists(packages)
view = ViewPackage(self.flags) view = ViewPackage()
view.package(packages) view.package(packages)
raise SystemExit() raise SystemExit()
self.usage.help(1) self.usage.help(1)
@ -188,14 +197,15 @@ class Argparse:
raise SystemExit() raise SystemExit()
self.usage.help(1) self.usage.help(1)
def find(self): def dependees(self):
if len(self.args) >= 2 and not self.flags: if len(self.args) >= 2 and not self.flags:
packages = list(set(self.args[1:])) packages = list(set(self.args[1:]))
self.check.database() self.check.database()
self.check.exists(packages)
find = FindInstalled() dependees = Dependees(packages)
find.find(packages) dependees.slackbuilds()
raise SystemExit() raise SystemExit()
self.usage.help(1) self.usage.help(1)
@ -253,7 +263,9 @@ def main():
'find': argparse.find, 'find': argparse.find,
'-f': argparse.find, '-f': argparse.find,
'search': argparse.search, 'search': argparse.search,
'-s': argparse.search '-s': argparse.search,
'dependees': argparse.dependees,
'-e': argparse.dependees
} }
try: try:

View file

@ -21,11 +21,11 @@ class Usage:
""" Prints the short menu. """ """ Prints the short menu. """
args = ( args = (
f'Usage: {Configs.prog_name} [{self.yellow}OPTIONS{self.endc}] [{self.cyan}COMMAND{self.endc}] <packages>\n' f'Usage: {Configs.prog_name} [{self.yellow}OPTIONS{self.endc}] [{self.cyan}COMMAND{self.endc}] <packages>\n'
f'\n slpkg [{self.yellow}OPTIONS{self.endc}] [--yes, --jobs, --resolve-off, --reinstall, \n' f'\n slpkg [{self.yellow}OPTIONS{self.endc}] [--yes, --jobs, --resolve-off, --reinstall, '
' --skip-installed, --dependees]\n' 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}] [update, upgrade, check-updates, clean-logs, clean-tmp]\n'
f' slpkg [{self.cyan}COMMAND{self.endc}] [-b, build, -i, install, -d, download] <packages>\n' f' slpkg [{self.cyan}COMMAND{self.endc}] [-b, build, -i, install, -d, download, -r, remove] <packages>\n'
f' slpkg [{self.cyan}COMMAND{self.endc}] [-r, remove, -f, find, -w, view, -s, search] <packages>\n' f' slpkg [{self.cyan}COMMAND{self.endc}] [-f, find, -w, view, -s, search, -e, dependees] <packages>\n'
" \nIf you need more information please try 'slpkg --help'.") " \nIf you need more information please try 'slpkg --help'.")
print(args) print(args)
@ -49,14 +49,14 @@ class Usage:
f' {self.cyan}-r, remove{self.endc} <packages> Remove installed packages.', f' {self.cyan}-r, remove{self.endc} <packages> Remove installed packages.',
f' {self.cyan}-f, find{self.endc} <packages> Find installed packages.', f' {self.cyan}-f, find{self.endc} <packages> Find installed packages.',
f' {self.cyan}-w, view{self.endc} <packages> View packages from the repository.', f' {self.cyan}-w, view{self.endc} <packages> View packages from the repository.',
f' {self.cyan}-s, search{self.endc} <packages> Search packages from the repository.\n', f' {self.cyan}-s, search{self.endc} <packages> Search packages from the repository.',
f' {self.cyan}-e, dependees{self.endc} <packages> Show which packages depend.\n',
f'{self.bold}OPTIONS:{self.endc}', f'{self.bold}OPTIONS:{self.endc}',
f' {self.yellow}--yes{self.endc} Answer Yes to all questions.', 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}--jobs{self.endc} Set it for multicore systems.',
f' {self.yellow}--resolve-off{self.endc} Turns off dependency resolving.', 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}--reinstall{self.endc} Upgrade packages of the same version.',
f' {self.yellow}--skip-installed{self.endc} Skip installed packages.', f' {self.yellow}--skip-installed{self.endc} Skip installed packages.\n',
f' {self.yellow}--dependees{self.endc} Show which packages depend.\n',
' -h, --help Show this message and exit.', ' -h, --help Show this message and exit.',
' -v, --version Print version and exit.\n', ' -v, --version Print version and exit.\n',
'Edit the configuration file in the /etc/slpkg/slpkg.toml.', 'Edit the configuration file in the /etc/slpkg/slpkg.toml.',

View file

@ -2,7 +2,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import sys
import urllib3 import urllib3
from slpkg.configs import Configs from slpkg.configs import Configs
@ -14,8 +13,7 @@ from slpkg.models.models import session as Session
class ViewPackage: class ViewPackage:
""" View the repository packages. """ """ View the repository packages. """
def __init__(self, flags): def __init__(self):
self.flags = flags
self.session = Session self.session = Session
self.configs = Configs self.configs = Configs
self.colors = self.configs.colour self.colors = self.configs.colour
@ -30,11 +28,8 @@ class ViewPackage:
red = color['red'] red = color['red']
endc = color['endc'] endc = color['endc']
print(end='\rCollecting the data... ')
for package in packages: for package in packages:
dependees = " ".join(list(self.dependees(package)))
info = self.session.query( info = self.session.query(
SBoTable.name, SBoTable.name,
SBoTable.version, SBoTable.version,
@ -63,10 +58,9 @@ class ViewPackage:
deps = (', '.join([f'{pkg} ({SBoQueries(pkg).version()})' for pkg in info[2].split()])) 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'Version: {green}{info[1]}{endc}\n'
f'Requires: {green}{deps}{endc}\n' f'Requires: {green}{deps}{endc}\n'
f'Dependees: {green}{dependees}{endc}\n'
f'Homepage: {blue}{homepage}{endc}\n' f'Homepage: {blue}{homepage}{endc}\n'
f'Download SlackBuild: {blue}{self.configs.sbo_repo_url}/{info[9]}/{info[0]}' f'Download SlackBuild: {blue}{self.configs.sbo_repo_url}/{info[9]}/{info[0]}'
f'{self.configs.sbo_tar_suffix}{endc}\n' f'{self.configs.sbo_tar_suffix}{endc}\n'
@ -83,16 +77,6 @@ class ViewPackage:
f'Email: {yellow}{email}{endc}\n' f'Email: {yellow}{email}{endc}\n'
f'\nREADME: {cyan}{readme.data.decode()}{endc}') 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 @staticmethod
def http_request(link): def http_request(link):
""" Http get request. """ """ Http get request. """