Remove check from upgrade

This commit is contained in:
Dimitris Zlatanidis 2024-03-25 19:20:55 +02:00
parent dbe0a7e510
commit 2779dcbfcd
3 changed files with 42 additions and 143 deletions

View file

@ -103,7 +103,7 @@ Answer Yes to all questions. (to be used with: -u, update, -U, upgrade, -b, buil
.P
.B -c, --check
.RS
Check a procedure before you run it. (to be used with: -u, update, -U, upgrade)
Check a procedure before you run it. (to be used with: -u, update)
.RE
.P
.B -O, --resolve-off

View file

@ -130,8 +130,6 @@ class Menu(Configs):
'upgrade': [
self.flag_yes,
self.flag_short_yes,
self.flag_check,
self.flag_short_check,
self.flag_resolve_off,
self.flag_short_resolve_off,
self.flag_reinstall,
@ -288,8 +286,7 @@ class Menu(Configs):
def check_for_repositories(self) -> None:
""" Checks a combination for binaries use repositories only and if repository exists. """
except_options: tuple = (
'-s', 'search',
'-U', 'upgrade'
'-s', 'search'
)
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}'")
@ -432,43 +429,35 @@ class Menu(Configs):
if len(self.args) == 1:
if self.utils.is_option((self.flag_check, self.flag_short_check), self.flags):
self.data: dict = self.load_data.load(self.repository)
upgrade = Upgrade(self.repository, self.data)
upgrade.check_packages()
self.data: dict = self.load_data.load(self.repository)
upgrade = Upgrade(self.repository, self.data)
packages: list = list(upgrade.packages())
for package in packages:
if package.endswith('_Removed.'):
removed.append(package.replace('_Removed.', ''))
if removed:
packages = [pkg for pkg in packages if not pkg.endswith('_Removed.')]
remove = RemovePackages(removed, self.flags)
remove.remove(upgrade=True)
packages: list = self.choose.packages(self.data, packages, command)
if not packages:
print('\nEverything is up-to-date!\n')
raise SystemExit(0)
if self.repository not in [self.repos.sbo_repo_name, self.repos.ponce_repo_name]:
install = Packages(
self.repository, self.data, packages, self.flags, mode=command
)
else:
if self.repository == '*':
self.repository = self.repos.default_repository
install = Slackbuilds(
self.repository, self.data, packages, self.flags, mode=command
)
self.data: dict = self.load_data.load(self.repository)
upgrade = Upgrade(self.repository, self.data)
packages: list = list(upgrade.packages())
for package in packages:
if package.endswith('_Removed.'):
removed.append(package.replace('_Removed.', ''))
if removed:
packages = [pkg for pkg in packages if not pkg.endswith('_Removed.')]
remove = RemovePackages(removed, self.flags)
remove.remove(upgrade=True)
packages: list = self.choose.packages(self.data, packages, command)
if not packages:
print('\nEverything is up-to-date!\n')
raise SystemExit(0)
if self.repository not in [self.repos.sbo_repo_name, self.repos.ponce_repo_name]:
install = Packages(
self.repository, self.data, packages, self.flags, mode=command
)
else:
install = Slackbuilds(
self.repository, self.data, packages, self.flags, mode=command
)
install.execute()
install.execute()
raise SystemExit(0)
self.usage.help_short(1)

View file

@ -22,28 +22,28 @@ class Upgrade(Configs):
self.utils = Utilities()
self.repos = Repositories()
self.ascii = AsciiBox()
self.count_packages: int = 0
self.count_repos: list = []
def packages(self) -> Generator:
""" Returns the upgradable packages. """
print('\rRetrieving packages... ', end='')
installed_names: list = []
installed_packages: list = []
self.installed_names: list = []
self.installed_packages: list = []
def load_installed_packages(self):
if self.repository in [self.repos.slack_repo_name, self.repos.salixos_repo_name]:
installed: dict = self.utils.all_installed()
for name, package in installed.items():
tag: str = self.utils.split_package(package)['tag']
if not tag:
installed_packages.append(Path(package))
installed_names.append(name)
self.installed_packages.append(Path(package))
self.installed_names.append(name)
else:
repo_tag: str = self.repos.repositories[self.repository]['repo_tag']
installed_packages: Generator = self.log_packages.glob(f'*{repo_tag}')
self.installed_packages: list = list(self.log_packages.glob(f'*{repo_tag}'))
for inst in installed_packages:
def packages(self) -> Generator:
""" Returns the upgradable packages. """
print('\rRetrieving packages... ', end='')
self.load_installed_packages()
for inst in self.installed_packages:
name: str = self.utils.split_package(inst.name)['name']
if self.is_package_upgradeable(inst.name):
yield name
@ -55,9 +55,8 @@ class Upgrade(Configs):
if self.repository == self.repos.slack_repo_name and self.new_packages:
for name in self.data.keys():
# if not self.utils.is_package_installed(name):
if name not in installed_names:
if name not in self.installed_names:
yield name
print(f'{self.bgreen}{self.ascii.done}{self.endc}')
def is_package_upgradeable(self, installed: str) -> bool:
@ -70,92 +69,3 @@ class Upgrade(Configs):
except ValueError:
return False
return False
def check_packages(self) -> None:
found_packages: dict = {}
if self.repository == '*':
for repo in self.data.keys():
repo_tag: str = self.repos.repositories[repo]['repo_tag']
installed_packages: Generator = self.log_packages.glob(f'*{repo_tag}')
for installed in installed_packages:
name: str = self.utils.split_package(installed.name)['name']
if self.data[repo].get(name):
repo_package: str = self.data[repo][name]['package'][:-4]
if parse_version(repo_package) > parse_version(installed.name):
self.count_packages += 1
self.count_repos.append(repo)
repo_version: str = self.data[repo][name]['version']
repo_build: str = self.data[repo][name]['build']
inst_version: str = self.utils.split_package(installed.name)['version']
inst_build: str = self.utils.split_package(installed.name)['build']
found_packages[self.count_packages]: dict = {
'name': name,
'repo_version': repo_version,
'repo_build': repo_build,
'inst_version': inst_version,
'inst_build': inst_build,
'repo': repo
}
else:
repo_tag: str = self.repos.repositories[self.repository]['repo_tag']
installed_package: Generator = self.log_packages.glob(f'*{repo_tag}')
self.count_repos.append(self.repository)
for installed in installed_package:
name: str = self.utils.split_package(installed.name)['name']
if self.data.get(name):
repo_package: str = self.data[name]['package'][:-4]
if parse_version(repo_package) > parse_version(installed.name):
self.count_packages += 1
repo_version: str = self.data[name]['version']
repo_build: str = self.data[name]['build']
inst_version: str = self.utils.split_package(installed.name)['version']
inst_build: str = self.utils.split_package(installed.name)['build']
found_packages[self.count_packages]: dict = {
'name': name,
'repo_version': repo_version,
'repo_build': repo_build,
'inst_version': inst_version,
'inst_build': inst_build,
'repo': self.repository
}
if self.count_packages:
title: str = f"{'packages':<18} {'Version':<15} {'Build':<6} {'Repository':<15} {'Build':<5} {'Repo':>15}"
print(len(title) * '=')
print(f'{self.bgreen}{title}{self.endc}')
print(len(title) * '=')
for data in found_packages.values():
name: str = data['name']
repo_version: str = data['repo_version']
repo_build: str = data['repo_build']
inst_version: str = data['inst_version']
inst_build: str = data['inst_build']
if len(name) > 17:
name: str = f'{name[:14]}...'
if len(inst_version) > 15:
inst_version: str = f"{inst_version[:11]}..."
if len(repo_version) > 15:
repo_version: str = f"{repo_version[:11]}..."
print(f"{name:<18} {inst_version:<15} {inst_build:<6} {repo_version:<15} "
f"{repo_build:<5} {data['repo']:>15}")
count_repos: int = len(set(self.count_repos))
repos_message: str = 'repository'
if count_repos > 1:
repos_message: str = 'repositories'
print(len(title) * '=')
print(f'{self.grey}Total packages for upgrade {self.count_packages} in {count_repos} '
f'{repos_message}.{self.endc}\n')
else:
print('\nEverything is up-to-date!\n')
raise SystemExit(0)