mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-30 20:34:38 +01:00
Merge branch 'develop' of https://gitlab.com/dslackw/slpkg into develop
This commit is contained in:
commit
8833c0d2a8
7 changed files with 105 additions and 59 deletions
|
@ -17,9 +17,11 @@ class BinQueries(Configs):
|
|||
self.repo: str = repo
|
||||
self.session = Session
|
||||
self.repos = Repositories()
|
||||
self.bin_repo: list = []
|
||||
|
||||
self.bin_repo: list = self.repos.enabled_repositories
|
||||
if self.repo:
|
||||
if self.repo is None or self.repo == '*':
|
||||
self.bin_repo: list = self.repos.enabled_repositories
|
||||
elif self.repo:
|
||||
self.bin_repo: list = [self.repo]
|
||||
|
||||
self.black = Blacklist()
|
||||
|
@ -29,7 +31,7 @@ class BinQueries(Configs):
|
|||
def all_name_packages(self) -> list:
|
||||
""" Returns all the names of the binaries packages. """
|
||||
pkgs: tuple = self.session.query(
|
||||
BinariesTable.name,
|
||||
BinariesTable.name).where(
|
||||
BinariesTable.repo.in_(self.bin_repo)).all()
|
||||
|
||||
return [pkg[0] for pkg in pkgs]
|
||||
|
@ -37,7 +39,7 @@ class BinQueries(Configs):
|
|||
def all_name_binaries_packages(self) -> list:
|
||||
""" Returns all the binaries packages. """
|
||||
pkgs: tuple = self.session.query(
|
||||
BinariesTable.package,
|
||||
BinariesTable.package).where(
|
||||
BinariesTable.repo.in_(self.bin_repo)).all()
|
||||
|
||||
return [pkg[0] for pkg in pkgs]
|
||||
|
@ -55,7 +57,7 @@ class BinQueries(Configs):
|
|||
""" Returns the package name. """
|
||||
pkg: tuple = self.session.query(
|
||||
BinariesTable.name).filter(
|
||||
BinariesTable.name == self.name,
|
||||
BinariesTable.name == self.name).where(
|
||||
BinariesTable.repo.in_(self.bin_repo)).first()
|
||||
|
||||
if pkg:
|
||||
|
@ -66,7 +68,7 @@ class BinQueries(Configs):
|
|||
""" Returns the binary package. """
|
||||
pkg: tuple = self.session.query(
|
||||
BinariesTable.package).filter(
|
||||
BinariesTable.name == self.name,
|
||||
BinariesTable.name == self.name).where(
|
||||
BinariesTable.repo.in_(self.bin_repo)).first()
|
||||
|
||||
if pkg:
|
||||
|
@ -77,7 +79,7 @@ class BinQueries(Configs):
|
|||
""" Returns the binary package checksum. """
|
||||
md5: tuple = self.session.query(
|
||||
BinariesTable.checksum).filter(
|
||||
BinariesTable.package == self.name,
|
||||
BinariesTable.package == self.name).where(
|
||||
BinariesTable.repo.in_(self.bin_repo)).first()
|
||||
|
||||
if md5:
|
||||
|
@ -88,7 +90,7 @@ class BinQueries(Configs):
|
|||
""" Returns the package version. """
|
||||
pkg: tuple = self.session.query(
|
||||
BinariesTable.version).filter(
|
||||
BinariesTable.name == self.name,
|
||||
BinariesTable.name == self.name).where(
|
||||
BinariesTable.repo.in_(self.bin_repo)).first()
|
||||
|
||||
if pkg:
|
||||
|
@ -99,7 +101,7 @@ class BinQueries(Configs):
|
|||
""" Returns the package mirror. """
|
||||
mir: tuple = self.session.query(
|
||||
BinariesTable.mirror).filter(
|
||||
BinariesTable.name == self.name,
|
||||
BinariesTable.name == self.name).where(
|
||||
BinariesTable.repo.in_(self.bin_repo)).first()
|
||||
|
||||
if mir:
|
||||
|
@ -110,7 +112,7 @@ class BinQueries(Configs):
|
|||
""" Returns the package location. """
|
||||
loc: tuple = self.session.query(
|
||||
BinariesTable.location).filter(
|
||||
BinariesTable.name == self.name,
|
||||
BinariesTable.name == self.name).where(
|
||||
BinariesTable.repo.in_(self.bin_repo)).first()
|
||||
|
||||
if loc:
|
||||
|
@ -121,7 +123,7 @@ class BinQueries(Configs):
|
|||
""" Returns the package comp size. """
|
||||
size: tuple = self.session.query(
|
||||
BinariesTable.size_comp).filter(
|
||||
BinariesTable.name == self.name,
|
||||
BinariesTable.name == self.name).where(
|
||||
BinariesTable.repo.in_(self.bin_repo)).first()
|
||||
|
||||
if size:
|
||||
|
@ -132,7 +134,7 @@ class BinQueries(Configs):
|
|||
""" Returns the package uncomp size. """
|
||||
size: tuple = self.session.query(
|
||||
BinariesTable.unsize_comp).filter(
|
||||
BinariesTable.name == self.name,
|
||||
BinariesTable.name == self.name).where(
|
||||
BinariesTable.repo.in_(self.bin_repo)).first()
|
||||
|
||||
if size:
|
||||
|
@ -143,7 +145,7 @@ class BinQueries(Configs):
|
|||
""" Returns the package required. """
|
||||
req: tuple = self.session.query(
|
||||
BinariesTable.required).filter(
|
||||
BinariesTable.name == self.name,
|
||||
BinariesTable.name == self.name).where(
|
||||
BinariesTable.repo.in_(self.bin_repo)).first()
|
||||
|
||||
if req:
|
||||
|
@ -154,7 +156,7 @@ class BinQueries(Configs):
|
|||
""" Returns the package conflicts. """
|
||||
con: tuple = self.session.query(
|
||||
BinariesTable.conflicts).filter(
|
||||
BinariesTable.name == self.name,
|
||||
BinariesTable.name == self.name).where(
|
||||
BinariesTable.repo.in_(self.bin_repo)).first()
|
||||
|
||||
if con:
|
||||
|
@ -165,7 +167,7 @@ class BinQueries(Configs):
|
|||
""" Returns the package suggests. """
|
||||
sug: tuple = self.session.query(
|
||||
BinariesTable.suggests).filter(
|
||||
BinariesTable.name == self.name,
|
||||
BinariesTable.name == self.name).where(
|
||||
BinariesTable.repo.in_(self.bin_repo)).first()
|
||||
|
||||
if sug:
|
||||
|
@ -176,7 +178,7 @@ class BinQueries(Configs):
|
|||
""" Returns the package description. """
|
||||
desc: tuple = self.session.query(
|
||||
BinariesTable.description).filter(
|
||||
BinariesTable.name == self.name,
|
||||
BinariesTable.name == self.name).where(
|
||||
BinariesTable.repo.in_(self.bin_repo)).first()
|
||||
|
||||
if desc:
|
||||
|
|
|
@ -5,13 +5,14 @@ from slpkg.configs import Configs
|
|||
from slpkg.utilities import Utilities
|
||||
|
||||
|
||||
class FindInstalled(Configs, Utilities):
|
||||
class FindInstalled(Configs):
|
||||
""" Find installed packages. """
|
||||
|
||||
def __init__(self):
|
||||
super(Configs, self).__init__()
|
||||
super(Utilities, self).__init__()
|
||||
|
||||
self.color = self.colour()
|
||||
self.utils = Utilities()
|
||||
|
||||
self.yellow: str = self.color['yellow']
|
||||
self.cyan: str = self.color['cyan']
|
||||
|
@ -20,19 +21,20 @@ class FindInstalled(Configs, Utilities):
|
|||
self.endc: str = self.color['endc']
|
||||
self.grey: str = self.color['grey']
|
||||
|
||||
self.installed: list = self.utils.installed_packages
|
||||
|
||||
def find(self, packages: list) -> None:
|
||||
""" Find the packages. """
|
||||
matching: list = []
|
||||
|
||||
installed: list = list(self.all_installed())
|
||||
|
||||
print(f'The list below shows the installed packages '
|
||||
f'that contains \'{", ".join([p for p in packages])}\' files:\n')
|
||||
|
||||
for pkg in packages:
|
||||
for package in installed:
|
||||
for package in self.installed:
|
||||
if pkg in package:
|
||||
matching.append(package)
|
||||
|
||||
self.matched(matching)
|
||||
|
||||
def matched(self, matching: list) -> None:
|
||||
|
|
|
@ -9,7 +9,6 @@ from slpkg.checks import Check
|
|||
from slpkg.upgrade import Upgrade
|
||||
from slpkg.configs import Configs
|
||||
from slpkg.tracking import Tracking
|
||||
from slpkg.sbos.queries import SBoQueries
|
||||
from slpkg.dependees import Dependees
|
||||
from slpkg.utilities import Utilities
|
||||
from slpkg.search import SearchPackage
|
||||
|
@ -17,13 +16,15 @@ from slpkg.views.cli_menu import Usage
|
|||
from slpkg.dialog_box import DialogBox
|
||||
from slpkg.views.version import Version
|
||||
from slpkg.download_only import Download
|
||||
from slpkg.sbos.slackbuild import Slackbuilds
|
||||
from slpkg.views.views import ViewMessage
|
||||
from slpkg.sbos.queries import SBoQueries
|
||||
from slpkg.form_configs import FormConfigs
|
||||
from slpkg.views.help_commands import Help
|
||||
from slpkg.repositories import Repositories
|
||||
from slpkg.binaries.install import Packages
|
||||
from slpkg.check_updates import CheckUpdates
|
||||
from slpkg.sbos.slackbuild import Slackbuilds
|
||||
from slpkg.binaries.queries import BinQueries
|
||||
from slpkg.find_installed import FindInstalled
|
||||
from slpkg.views.view_package import ViewPackage
|
||||
from slpkg.remove_packages import RemovePackages
|
||||
|
@ -78,7 +79,7 @@ class Argparse(Configs):
|
|||
self.flag_short_parallel: str = '-P'
|
||||
self.flag_binary: str = '--binary'
|
||||
self.flag_short_binary: str = '-B'
|
||||
self.flag_bin_repository: str = '--repository='
|
||||
self.flag_bin_repository: str = '--bin-repo='
|
||||
self.flag_short_bin_repository: str = '-O='
|
||||
self.flag_directory: str = '--directory='
|
||||
self.flag_short_directory: str = '-z='
|
||||
|
@ -143,6 +144,10 @@ class Argparse(Configs):
|
|||
self.flag_short_reinstall,
|
||||
self.flag_no_silent,
|
||||
self.flag_short_no_silent,
|
||||
self.flag_binary,
|
||||
self.flag_short_binary,
|
||||
self.flag_bin_repository,
|
||||
self.flag_short_bin_repository,
|
||||
self.flag_parallel,
|
||||
self.flag_short_parallel
|
||||
],
|
||||
|
@ -274,6 +279,16 @@ class Argparse(Configs):
|
|||
|
||||
self.check = Check(self.flags)
|
||||
self.check.is_blacklist(self.args[1:])
|
||||
self.check_for_bin_repositories()
|
||||
|
||||
def check_for_bin_repositories(self) -> None:
|
||||
""" Checks combination for binaries use repositories only and if repository exists. """
|
||||
if (self.utils.is_option([self.flag_bin_repository, self.flag_short_bin_repository], self.flags) and not
|
||||
self.utils.is_option([self.flag_binary, self.flag_short_binary], self.flags)):
|
||||
self.usage.help_minimal(f"{self.prog_name}: invalid options '{', '.join(self.flags)}'")
|
||||
|
||||
if self.binary_repo and self.binary_repo not in self.repos.binaries_repositories_dict.keys():
|
||||
self.usage.help_minimal(f"{self.prog_name}: invalid binary repository '{self.binary_repo}'")
|
||||
|
||||
def invalid_options(self) -> None:
|
||||
""" Checks for invalid options. """
|
||||
|
@ -292,13 +307,11 @@ class Argparse(Configs):
|
|||
|
||||
# Fixed for recurring options.
|
||||
if repeat:
|
||||
print(f"{self.prog_name}: invalid recurring options '{', '.join(repeat)}'")
|
||||
self.usage.help_minimal()
|
||||
self.usage.help_minimal(f"{self.prog_name}: invalid recurring options '{', '.join(repeat)}'")
|
||||
|
||||
# Fixed for invalid commands combination.
|
||||
if len(commands) > 1:
|
||||
print(f"{self.prog_name}: invalid commands combination '{', '.join(commands)}'")
|
||||
self.usage.help_minimal()
|
||||
self.usage.help_minimal(f"{self.prog_name}: invalid commands combination '{', '.join(commands)}'")
|
||||
|
||||
# Fixed for correct options by command.
|
||||
try:
|
||||
|
@ -311,9 +324,7 @@ class Argparse(Configs):
|
|||
|
||||
# Prints error for invalid options.
|
||||
if invalid:
|
||||
for opt in invalid:
|
||||
print(f"{self.prog_name}: invalid option '{opt}'")
|
||||
self.usage.help_minimal()
|
||||
self.usage.help_minimal(f"{self.prog_name}: invalid options '{','.join(invalid)}'")
|
||||
|
||||
def split_options(self) -> None:
|
||||
""" Split options and commands, like: -iyjR
|
||||
|
@ -387,9 +398,12 @@ class Argparse(Configs):
|
|||
list_height: int = 0
|
||||
choices: list = []
|
||||
title: str = f' Choose packages you want to {method} '
|
||||
repo_packages: list = SBoQueries('').sbos()
|
||||
|
||||
installed: list = list(self.utils.all_installed())
|
||||
repo_packages: list = SBoQueries('').sbos()
|
||||
if self.utils.is_option([self.flag_binary, self.flag_short_binary], self.flags):
|
||||
repo_packages: list = BinQueries('', self.binary_repo).all_name_packages()
|
||||
|
||||
installed: list = self.utils.installed_packages
|
||||
|
||||
if method in ['remove', 'find']:
|
||||
|
||||
|
@ -406,12 +420,19 @@ class Argparse(Configs):
|
|||
for package in repo_packages:
|
||||
|
||||
if pkg == package:
|
||||
|
||||
repo_ver: str = SBoQueries(package).version()
|
||||
inst_pkg: str = self.utils.is_package_installed(package)
|
||||
inst_ver: str = self.utils.split_binary_pkg(inst_pkg)[1]
|
||||
inst_build_tag: str = self.utils.split_binary_pkg(inst_pkg)[3]
|
||||
|
||||
repo_build_tag = self.utils.read_build_tag(package)
|
||||
inst_build_tag = self.utils.split_binary_pkg(inst_pkg)[3]
|
||||
if self.utils.is_option([self.flag_binary, self.flag_short_binary], self.flags):
|
||||
repo_ver: str = BinQueries(package, self.binary_repo).version()
|
||||
bin_pkg: str = BinQueries(package, self.binary_repo).package_bin()
|
||||
repo_build_tag: str = self.utils.split_binary_pkg(bin_pkg[:-4])[3]
|
||||
|
||||
else:
|
||||
repo_build_tag: str = self.utils.read_sbo_build_tag(package)
|
||||
|
||||
choices += [(package, f'{inst_ver} -> {repo_ver}', True,
|
||||
f'Installed: {package}-{inst_ver} Build: {inst_build_tag} -> '
|
||||
|
@ -422,7 +443,11 @@ class Argparse(Configs):
|
|||
for package in repo_packages:
|
||||
|
||||
if pkg in package:
|
||||
repo_ver = SBoQueries(package).version()
|
||||
|
||||
repo_ver: str = SBoQueries(package).version()
|
||||
if self.utils.is_option([self.flag_binary, self.flag_short_binary], self.flags):
|
||||
repo_ver: str = BinQueries(package, self.binary_repo).version()
|
||||
|
||||
choices += [(package, repo_ver, False, f'Package: {package}-{repo_ver}')]
|
||||
|
||||
if not choices:
|
||||
|
@ -467,7 +492,7 @@ class Argparse(Configs):
|
|||
if len(self.args) == 1:
|
||||
self.check.is_empty_database()
|
||||
|
||||
upgrade = Upgrade()
|
||||
upgrade = Upgrade(self.flags, self.binary_repo)
|
||||
packages: list = list(upgrade.packages())
|
||||
|
||||
packages: list = self.choose_packages(packages, command)
|
||||
|
@ -476,8 +501,12 @@ class Argparse(Configs):
|
|||
print('\nEverything is up-to-date.\n')
|
||||
raise SystemExit()
|
||||
|
||||
install = Slackbuilds(packages, self.flags, mode=command)
|
||||
install.execute()
|
||||
if self.utils.is_option([self.flag_binary, self.flag_short_binary], self.flags):
|
||||
install = Packages(packages, self.flags, self.binary_repo, mode=command)
|
||||
install.execute()
|
||||
else:
|
||||
install = Slackbuilds(packages, self.flags, mode=command)
|
||||
install.execute()
|
||||
raise SystemExit()
|
||||
self.usage.help_short(1)
|
||||
|
||||
|
|
|
@ -4,33 +4,43 @@
|
|||
from typing import Generator
|
||||
|
||||
from slpkg.configs import Configs
|
||||
from slpkg.sbos.queries import SBoQueries
|
||||
from slpkg.utilities import Utilities
|
||||
from slpkg.dependencies import Requires
|
||||
from slpkg.sbos.queries import SBoQueries
|
||||
from slpkg.binaries.queries import BinQueries
|
||||
|
||||
|
||||
class Upgrade(Configs, Utilities):
|
||||
class Upgrade(Configs):
|
||||
""" Upgrade the installed packages. """
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, flags: list, repo: str):
|
||||
super(Configs, self).__init__()
|
||||
super(Utilities, self).__init__()
|
||||
self.flags = flags
|
||||
self.repo = repo
|
||||
self.utils = Utilities()
|
||||
|
||||
self.flag_binary: list = ['-B', '--binary']
|
||||
|
||||
def packages(self) -> Generator[str, None, None]:
|
||||
""" Compares version of packages and returns the maximum. """
|
||||
upgrade: list = []
|
||||
requires: list = []
|
||||
repo_packages: list = SBoQueries('').sbos()
|
||||
upgrade, requires = [], []
|
||||
|
||||
installed: list = list(self.all_installed())
|
||||
repo_packages: list = SBoQueries('').sbos()
|
||||
if self.utils.is_option(self.flag_binary, self.flags):
|
||||
repo_packages: list = BinQueries('', self.repo).all_name_packages()
|
||||
|
||||
installed: list = self.utils.installed_packages
|
||||
|
||||
for pkg in installed:
|
||||
inst_pkg_name: str = self.split_binary_pkg(pkg)[0]
|
||||
inst_pkg_name: str = self.utils.split_binary_pkg(pkg)[0]
|
||||
|
||||
if inst_pkg_name in repo_packages:
|
||||
|
||||
if self.is_package_upgradeable(inst_pkg_name):
|
||||
requires += Requires(inst_pkg_name).resolve()
|
||||
if self.utils.is_package_upgradeable(inst_pkg_name):
|
||||
|
||||
if not self.utils.is_option(self.flag_binary, self.flags):
|
||||
requires += Requires(inst_pkg_name).resolve()
|
||||
|
||||
upgrade.append(inst_pkg_name)
|
||||
|
||||
# Clean the packages if they are dependencies
|
||||
|
|
|
@ -91,13 +91,15 @@ class Utilities:
|
|||
if not directory.exists():
|
||||
directory.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def split_binary_pkg(self, package: str) -> list:
|
||||
@staticmethod
|
||||
def split_binary_pkg(package: str) -> list:
|
||||
""" Split the package by the name, version, arch, build and tag. """
|
||||
name: str = '-'.join(package.split('-')[:-3])
|
||||
version: str = ''.join(package[len(name):].split('-')[:-2])
|
||||
arch: str = ''.join(package[len(name + version) + 2:].split('-')[:-1])
|
||||
build: str = ''.join(package[len(name + version + arch) + 3:].split('-')).replace(self.repos.repo_tag, '')
|
||||
tag: str = ''.join(package[len(name + version + arch + build) + 4:].split('-'))
|
||||
build_tag: str = package.split('-')[-1]
|
||||
build: str = ''.join(re.findall(r'\d+', build_tag[:2]))
|
||||
tag: str = build_tag[len(build):].replace('_', '')
|
||||
|
||||
return [name, version, arch, build, tag]
|
||||
|
||||
|
@ -112,7 +114,7 @@ class Utilities:
|
|||
installed_version: str = '0'
|
||||
installed = self.is_package_installed(package)
|
||||
repository_version = str(SBoQueries(package).version())
|
||||
repo_build_tag: str = self.read_build_tag(package)
|
||||
repo_build_tag: str = self.read_sbo_build_tag(package)
|
||||
inst_build_tag: str = self.split_binary_pkg(installed)[3]
|
||||
|
||||
if not repo_build_tag:
|
||||
|
@ -129,7 +131,7 @@ class Utilities:
|
|||
|
||||
return parse(repository_version + repo_build_tag) > parse(installed_version + inst_build_tag)
|
||||
|
||||
def read_build_tag(self, sbo: str) -> str:
|
||||
def read_sbo_build_tag(self, sbo: str) -> str:
|
||||
""" Patching SBo TAG from the configuration file. """
|
||||
location: str = SBoQueries(sbo).location()
|
||||
sbo_script = Path(self.repos.sbo_repo_path, location, sbo, f'{sbo}.SlackBuild')
|
||||
|
|
|
@ -17,8 +17,9 @@ class Usage(Configs):
|
|||
self.yellow: str = color['yellow']
|
||||
self.endc: str = color['endc']
|
||||
|
||||
def help_minimal(self) -> NoReturn:
|
||||
def help_minimal(self, message: str) -> NoReturn:
|
||||
""" Prints the minimal help menu. """
|
||||
print(message)
|
||||
args: str = (
|
||||
f'\nUsage: {self.prog_name} [{self.yellow}OPTIONS{self.endc}] [{self.cyan}COMMAND{self.endc}] '
|
||||
f'[FILELIST|PACKAGES...]\n'
|
||||
|
@ -40,7 +41,7 @@ class Usage(Configs):
|
|||
f' slpkg [{self.yellow}OPTIONS{self.endc}] [-y, --yes, -j, --jobs, -o, --resolve-off, -r, --reinstall]\n'
|
||||
f' slpkg [{self.yellow}OPTIONS{self.endc}] [-k, --skip-installed, -E, --full-reverse, -S, --search]\n'
|
||||
f' slpkg [{self.yellow}OPTIONS{self.endc}] [-n, --no-silent, -p, --pkg-version, -G, --generate-only]\n'
|
||||
f' slpkg [{self.yellow}OPTIONS{self.endc}] [-P, --parallel, -B, --binary, -O, --repository=[REPO]]\n'
|
||||
f' slpkg [{self.yellow}OPTIONS{self.endc}] [-P, --parallel, -B, --binary, -O, --bin-repo=[REPO]]\n'
|
||||
f' slpkg [{self.yellow}OPTIONS{self.endc}] [-z, --directory=[PATH]]\n'
|
||||
" \nIf you need more information please try 'slpkg --help'.")
|
||||
|
||||
|
@ -83,7 +84,7 @@ class Usage(Configs):
|
|||
f' {self.yellow}-G, --generate-only{self.endc} Generates only the SLACKBUILDS.TXT file.\n'
|
||||
f' {self.yellow}-P, --parallel{self.endc} Download files in parallel.\n'
|
||||
f' {self.yellow}-B, --binary{self.endc} Switch with binaries repositories.\n'
|
||||
f' {self.yellow}-O, --repository={self.endc}[REPO] Set the binary repository.\n'
|
||||
f' {self.yellow}-O, --bin-repo={self.endc}[REPO] Set the binary repository.\n'
|
||||
f' {self.yellow}-z, --directory={self.endc}[PATH] Download files to a specific path.\n'
|
||||
'\n -h, --help Show this message and exit.\n'
|
||||
' -v, --version Print version and exit.\n'
|
||||
|
|
|
@ -65,7 +65,7 @@ class ViewPackage(Configs):
|
|||
path = Path(self.repo_path, info[9], info[0], f'{info[0]}.info')
|
||||
info_file = self.utils.read_file(path)
|
||||
|
||||
repo_build_tag = self.utils.read_build_tag(info[0])
|
||||
repo_build_tag = self.utils.read_sbo_build_tag(info[0])
|
||||
|
||||
maintainer, email, homepage = '', '', ''
|
||||
for line in info_file:
|
||||
|
|
Loading…
Add table
Reference in a new issue