Updated for --repository option

This commit is contained in:
Dimitris Zlatanidis 2023-05-04 19:46:10 +03:00
parent c2b7a2a08c
commit 7ab0bd66d4
9 changed files with 92 additions and 80 deletions

View file

@ -11,7 +11,7 @@ slpkg [-h|-v] [-u, update] [-U, upgrade] [-c, check-updates] [-I, repo-info] [-g
[-L, clean-logs] [-D, clean-tmp] [-T, clean-data] [-b, build] [-i, install] [-d, download]
[-R, remove] [-f, find] [-w, view] [-s, search] [-e, dependees] [-t, tracking] -y, --yes, -j, --jobs, -o, --resolve-off,
-r, --reinstall, -k, --skip-installed, -a, --install-data, -E, --full-reverse, -S, --search, -n, --no-silent, -p, --pkg-version,
-P, --parallel, -B, --bin-repo=[\fIREPO\fR], -z, --directory=[\fIPATH\fR]
-P, --parallel, -o, --repository=[\fIREPO\fR], -z, --directory=[\fIPATH\fR]
.SH DESCRIPTION
.P
Slpkg is a software package manager that installs, updates, and removes packages on Slackware based systems.
@ -180,12 +180,10 @@ Download files in parallel to speed up the process.
(to be used with: -u, update, -U, upgrade, -b, build, -i, install, -d, download)
.RE
.P
.BI "-B," "" " \-\-bin-repo=[" REPO "]
.BI "-o," "" " \-\--repository=[" NAME "]
.RS
Switch to binaries repositories and select a repository.
Example: '\fIslpkg -i audacity --bin-repo=alien\fR'. Options update, check, and search support the asterisk '*' to apply
it in all repositories, like search a package to all binaries repositories '\fIslpkg -s libreoffice --bin-repo='*'\fR'.
Repo pattern '*' supported only with: -s, search, -u, update and -c, check-updates options.
Set the repository you want to work with. Make sure that you have been enabling the repository in the file '/etc/slpkg/repositories.toml'.
Repo pattern '*' supported only with: '-s, search' option.
(to be used with: -u, update, -c, check-updates, -U, upgrade, -i, install, -d, download, -s, search, -t, tracking, -e, dependees, -w, view)
.RE
.P

View file

@ -8,6 +8,7 @@ from multiprocessing import Process
from urllib3 import PoolManager, ProxyManager, make_headers
from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.progress_bar import ProgressBar
from slpkg.repositories import Repositories
from slpkg.logging_config import LoggingConfig
@ -16,20 +17,40 @@ from slpkg.logging_config import LoggingConfig
class CheckUpdates(Configs):
""" Check for changes in the ChangeLog file. """
def __init__(self):
def __init__(self, flags: list, repository: str):
super(Configs, self).__init__()
self.flags: list = flags
self.repository: str = repository
self.utils = Utilities()
self.progress = ProgressBar()
self.repos = Repositories()
self.compare: dict = {}
self.is_binary: bool = self.utils.is_binary_repo(repository)
self.option_for_repository: bool = self.utils.is_option(
['-o', '--repository'], flags)
logging.basicConfig(filename=LoggingConfig.log_file,
filemode=LoggingConfig.filemode,
encoding=LoggingConfig.encoding,
level=LoggingConfig.level)
def check(self) -> dict:
sbo_repository: dict = {
self.repos.sbo_repo_name: self.sbo_repository,
self.repos.ponce_repo_name: self.ponce_repository
}
if self.option_for_repository:
if self.is_binary:
self.binary_repository(self.repository)
else:
sbo_repository[self.repository]()
return self.compare
for repo in list(self.repos.repositories.keys())[2:]:

View file

@ -28,12 +28,15 @@ class Check(Configs):
self.is_binary: bool = self.utils.is_binary_repo(repository)
slackbuild_tables: dict = {
self.repos.sbo_repo_name: SBoTable,
self.repos.ponce_repo_name: PonceTable
}
if self.is_binary:
self.repo_table = BinariesTable
else:
self.repo_table = SBoTable
if self.repos.ponce_repo:
self.repo_table = PonceTable
self.repo_table = slackbuild_tables[repository]
def exists_in_the_database(self, packages: list) -> None:
""" Checking if the slackbuild exists in the database. """

View file

@ -82,8 +82,10 @@ class Argparse(Configs):
self.flag_directory: str = '--directory='
self.flag_short_directory: str = '-z'
self.flag_searches: list = [self.flag_short_search, self.flag_search]
# self.flag_binaries: list = [self.flag_short_repository, self.flag_repository]
self.flag_searches: list = [
self.flag_short_search,
self.flag_search
]
self.options: list = [
self.flag_yes,
@ -277,7 +279,7 @@ class Argparse(Configs):
self.split_options_from_args()
self.move_options()
self.invalid_options()
self.check_for_bin_repositories()
self.check_for_repositories()
if self.utils.is_binary_repo(self.repository): # is_option(self.flag_binaries, self.flags):
self.data: dict = BinQueries(self.repository).repository_data()
@ -296,26 +298,22 @@ class Argparse(Configs):
f'{self.__class__.__init__.__name__}: '
f'{args=}, {self.flags=}, {self.repository=}')
def check_for_bin_repositories(self) -> None:
def check_for_repositories(self) -> None:
""" Checks combination for binaries use repositories only and if repository exists. """
if self.utils.is_binary_repo(self.repository): # is_option(self.flag_binaries, self.flags):
except_options: list = [
'-s', 'search',
]
except_options: list = [
'-s', 'search',
'-u', 'update',
'-c', 'check-updates',
]
if self.repository == '*' and not self.utils.is_option(except_options, self.args):
self.usage.help_minimal(f"{self.prog_name}: invalid repository '{self.repository}'")
if (self.repository in list(self.repos.repositories.keys())[2:]
and not self.repos.repositories[self.repository][0]):
elif self.repository not in list(self.repos.repositories.keys()) and self.repository != '*':
self.usage.help_minimal(f"{self.prog_name}: invalid repository '{self.repository}'")
if self.repository != '*':
if not self.repos.repositories[self.repository][0]:
self.usage.help_minimal(f"{self.prog_name}: repository '{self.repository}' is disabled")
elif self.repository == '*' and not self.utils.is_option(except_options, self.args):
self.usage.help_minimal(f"{self.prog_name}: invalid binary repository '{self.repository}'")
elif self.repository not in list(self.repos.repositories.keys())[2:] and self.repository != '*':
self.usage.help_minimal(f"{self.prog_name}: invalid binary repository '{self.repository}'")
def invalid_options(self) -> None:
""" Checks for invalid options. """
invalid, commands, repeat = [], [], []
@ -467,7 +465,7 @@ class Argparse(Configs):
inst_pkg: str = self.utils.is_package_installed(package)
split_inst_pkg: list = self.utils.split_binary_pkg(inst_pkg)
if self.utils.is_binary_repo(self.repository): # is_option(self.flag_binaries, self.flags):
if self.utils.is_binary_repo(self.repository):
repo_ver: str = self.data[package][0]
bin_pkg: str = self.data[package][1]
repo_build_tag: str = self.utils.split_binary_pkg(bin_pkg[:-4])[3]
@ -486,13 +484,11 @@ class Argparse(Configs):
if pkg in package or pkg == '*':
if self.utils.is_binary_repo(self.repository):
repo_ver: str = self.data[package][0]
repo: str = self.repository
else:
repo_ver: str = self.data[package][2]
repo: str = self.repos.sbo_enabled_repo_name
choices += [(package, repo_ver, False, f'Package: {package}-{repo_ver} '
f'> {repo}')]
f'> {self.repository}')]
if not choices:
return packages
@ -556,7 +552,7 @@ class Argparse(Configs):
def check_updates(self) -> None:
if len(self.args) == 1:
check = CheckUpdates()
check = CheckUpdates(self.flags, self.repository)
check.updates()
raise SystemExit()
self.usage.help_short(1)

View file

@ -502,33 +502,23 @@ class Repositories:
except (tomli.TOMLDecodeError, KeyError) as error:
errors.raise_toml_error_message(error, repositories_toml_file)
# Default sbo repository configs.
repo_tag: str = sbo_repo_tag
patch_repo_tag: str = sbo_repo_patch_tag
sbo_enabled_repo_name: str = sbo_repo_name
if ponce_repo:
sbo_enabled_repo_name: str = ponce_repo_name
repo_tag: str = ponce_repo_tag
patch_repo_tag: str = ponce_repo_patch_tag
sbo_repo: bool = False
# List of repositories.
# Dictionary of configurations of repositories.
repositories = {
sbo_repo_name: [sbo_repo,
sbo_repo_path,
sbo_repo_mirror,
sbo_repo_slackbuilds,
sbo_repo_changelog,
sbo_repo_tag,
sbo_repo_patch_tag],
sbo_repo_patch_tag,
sbo_repo_tag],
ponce_repo_name: [ponce_repo,
ponce_repo_path,
ponce_repo_mirror,
ponce_repo_slackbuilds,
ponce_repo_changelog,
ponce_repo_tag,
ponce_repo_patch_tag],
ponce_repo_patch_tag,
ponce_repo_tag],
slack_repo_name: [slack_repo,
slack_repo_path,
@ -656,5 +646,6 @@ class Repositories:
slint_repo_packages,
slint_repo_checksums,
slint_repo_changelog,
slint_repo_tag]
slint_repo_tag],
'*': []
}

View file

@ -73,8 +73,8 @@ class Slackbuilds(Configs):
self.slackbuilds: list = self.utils.apply_package_pattern(data, slackbuilds)
# Patch the TAG from configs.
if self.repos.patch_repo_tag:
self.repos.repo_tag = self.repos.patch_repo_tag
if self.repos.repositories[repository][5]:
self.repo_tag = self.repos.repositories[repository][5]
logging.basicConfig(filename=LoggingConfig.log_file,
filemode=LoggingConfig.filemode,
@ -239,14 +239,14 @@ class Slackbuilds(Configs):
""" Patching SBo TAG from the configuration file. """
sbo_script: Path = Path(self.build_path, sbo, f'{sbo}.SlackBuild')
if sbo_script.is_file() and self.repos.patch_repo_tag:
if sbo_script.is_file() and self.repo_tag:
lines: list = self.utils.read_file(sbo_script)
with open(sbo_script, 'w') as script:
for line in lines:
if line.startswith('TAG=$'):
line: str = f'TAG=${{TAG:-{self.repos.patch_repo_tag}}}\n'
line: str = f'TAG=${{TAG:-{self.repo_tag}}}\n'
script.write(line)
def install_package(self, package: str) -> None:
@ -272,7 +272,7 @@ class Slackbuilds(Configs):
""" Returns the package for install. """
package: str = ''
version: str = self.data[name][2]
pattern: str = f'{name}-{version}*{self.repos.repo_tag}*'
pattern: str = f'{name}-{version}*{self.repo_tag}*'
packages: list = [file.name for file in self.tmp_path.glob(pattern)]

View file

@ -20,32 +20,34 @@ from slpkg.models.models import (SBoTable, PonceTable,
class UpdateRepository(Configs):
""" Deletes and install the data. """
def __init__(self, flags: list, repo: str):
__slots__ = 'flags', 'repo'
def __init__(self, flags: list, repository: str):
__slots__ = 'flags', 'repository'
super(Configs, self).__init__()
self.flags: list = flags
self.repo: str = repo
self.repository: str = repository
self.session = Session
self.view = ViewMessage(flags)
self.view = ViewMessage(flags, repository)
self.repos = Repositories()
self.progress = ProgressBar()
self.utils = Utilities()
self.data = InstallData()
self.check_updates = CheckUpdates()
self.check_updates = CheckUpdates(flags, repository)
self.repos_for_update: dict = {}
self.is_binary: bool = self.utils.is_binary_repo(repository)
self.option_for_repository: bool = self.utils.is_option(
['-o', '--repository'], flags)
self.option_for_generate: bool = self.utils.is_option(
['-G', '--generate-only'], flags)
self.option_for_install_data: bool = self.utils.is_option(
['-a', '--install-data'], flags)
self.option_for_binaries: bool = self.utils.is_option(
['-B', '--bin-repo='], flags)
def update_the_repositories(self) -> None:
if not any(list(self.repos_for_update.values())):
self.view.question()
@ -73,9 +75,12 @@ class UpdateRepository(Configs):
self.repos.slint_repo_name: self.slint_repository
}
for repo, value in self.repos_for_update.items():
if value:
repositories[repo]()
if self.option_for_repository:
repositories[self.repository]()
else:
for repo, value in self.repos_for_update.items():
if value:
repositories[repo]()
print()
def slack_repository(self):

View file

@ -17,6 +17,7 @@ class Upgrade(Configs):
def __init__(self, repository: str, data: dict):
__slots__ = 'repository', 'data'
super(Configs, self).__init__()
self.repository = repository
self.data: dict = data
self.utils = Utilities()
@ -45,11 +46,7 @@ class Upgrade(Configs):
inst_version = inst_build = '0'
inst_package: str = self.utils.is_package_installed(name)
repo_tag: str = self.repos.repo_tag
if self.is_binary:
repo_tag: str = self.repos.repositories[self.data[name][11]][6]
if inst_package and inst_package.endswith(repo_tag):
if inst_package and inst_package.endswith(self.repos.repositories[self.repository][6]):
inst_version: str = self.utils.split_binary_pkg(inst_package)[1]
inst_build: str = self.utils.split_binary_pkg(inst_package)[3]
@ -78,7 +75,8 @@ class Upgrade(Configs):
logger = logging.getLogger(LoggingConfig.date)
logger.exception(f'{self.__class__.__name__}: '
f'{self.__class__.is_package_upgradeable.__name__}: '
f'{repo_tag=}, {repo_pkg=}, {inst_pkg=}, {repo_pkg > inst_pkg}, '
f'{self.repos.repositories[self.repository][6]}, '
f'{repo_pkg=}, {inst_pkg=}, {repo_pkg > inst_pkg}, '
f'{repo_pkg == inst_pkg and repo_build > inst_build}')
if repo_pkg > inst_pkg:

View file

@ -179,16 +179,16 @@ class Utilities(Configs):
if [black for black in self.black.packages() if fnmatch.fnmatch(name, black)]:
return True
def repository_name(self, data: dict) -> str:
""" Get the binary repository name from the repository data. """
try:
# Binary repository name
repo: list = list(data.values())[0][11]
except (IndexError, AttributeError):
# Slackbuilds repository name 'sbo | ponce'
repo: str = self.repos.sbo_enabled_repo_name
# def repository_name(self, data: dict) -> str:
# """ Get the binary repository name from the repository data. """
# try:
# # Binary repository name
# repo: list = list(data.values())[0][11]
# except (IndexError, AttributeError):
# # Slackbuilds repository name 'sbo | ponce'
# repo: str = self.repos.sbo_enabled_repo_name
return repo
# return repo
def is_binary_repo(self, repo: str) -> bool:
""" Checks if the repository is binary. """