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:
- Feature to check the ChangeLog.txt file before update #153
- Dependees in the view command
- Flag --dependees
- Dependees command
BugFixed:
- View installed version

View file

@ -60,6 +60,7 @@ Usage
-f, find <packages> Find installed packages.
-w, view <packages> View packages from the repository.
-s, search <packages> Search packages from the repository.
-e, dependees <packages> 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.

View file

@ -4,7 +4,7 @@
slpkg - [OPTIONS] [COMMAND] <packages>
.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.

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.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]]:
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)
if len(self.args) >= 2:
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:

View file

@ -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}] <packages>\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] <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}] [-b, build, -i, install, -d, download, -r, remove] <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'.")
print(args)
@ -49,14 +49,14 @@ class Usage:
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}-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.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.',

View file

@ -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. """