mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-18 10:26:29 +01:00
Merged is_installed method
Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
parent
80afbdcd42
commit
01454c8093
4 changed files with 29 additions and 21 deletions
|
@ -1,3 +1,7 @@
|
|||
4.3.7 - 09/12/2022
|
||||
Updated:
|
||||
- Merge method is_installed in utilities
|
||||
|
||||
4.3.6 - 08/12/2022
|
||||
Fixed:
|
||||
- Remove packages
|
||||
|
|
|
@ -6,6 +6,7 @@ import os
|
|||
from slpkg.configs import Configs
|
||||
from slpkg.queries import SBoQueries
|
||||
from slpkg.blacklist import Blacklist
|
||||
from slpkg.utilities import Utilities
|
||||
|
||||
|
||||
class Check:
|
||||
|
@ -36,15 +37,14 @@ class Check:
|
|||
if 'UNSUPPORTED' in sources:
|
||||
raise SystemExit(f"\nPackage '{sbo}' unsupported by arch.\n")
|
||||
|
||||
def installed(self, slackbuilds: list):
|
||||
@staticmethod
|
||||
def installed(slackbuilds: list):
|
||||
""" Checking for installed packages. """
|
||||
found, not_found = [], []
|
||||
utils = Utilities()
|
||||
|
||||
for sbo in slackbuilds:
|
||||
for package in os.listdir(self.configs.log_packages):
|
||||
pkg = '-'.join(package.split('-')[:-3])
|
||||
if sbo == pkg and package.endswith(self.configs.sbo_repo_tag):
|
||||
found.append(sbo)
|
||||
found.append((utils.is_installed(sbo)))
|
||||
|
||||
for sbo in slackbuilds:
|
||||
if sbo not in found:
|
||||
|
|
|
@ -8,17 +8,20 @@ import tarfile
|
|||
|
||||
|
||||
from slpkg.configs import Configs
|
||||
from slpkg.blacklist import Blacklist
|
||||
|
||||
|
||||
class Utilities:
|
||||
|
||||
def __init__(self):
|
||||
self.configs = Configs
|
||||
self.black = Blacklist()
|
||||
|
||||
def is_installed(self, package: str):
|
||||
""" Returns True if a package is installed. """
|
||||
for pkg in os.listdir(self.configs.log_packages):
|
||||
if package in pkg:
|
||||
def is_installed(self, name: str):
|
||||
""" Returns the installed package name. """
|
||||
for package in os.listdir(self.configs.log_packages):
|
||||
pkg = '-'.join(package.split('-')[:-3])
|
||||
if pkg == name and self.configs.sbo_repo_tag in package and pkg not in self.black.get():
|
||||
return pkg
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -68,7 +68,7 @@ class ViewMessage:
|
|||
print('The following packages will be removed:\n')
|
||||
slackbuilds, dependencies, deps = [], [], []
|
||||
for pkg in packages:
|
||||
self._view_installed_packages(pkg)
|
||||
self._view_removed(pkg)
|
||||
slackbuilds.append(pkg)
|
||||
|
||||
requires = self.session.query(
|
||||
|
@ -83,7 +83,7 @@ class ViewMessage:
|
|||
|
||||
for i in range(0, len(deps)):
|
||||
for dep in deps[i][0].split():
|
||||
self._view_installed_packages(dep)
|
||||
self._view_removed(dep)
|
||||
dependencies.append(dep)
|
||||
|
||||
self._view_total(slackbuilds, dependencies, option='remove')
|
||||
|
@ -94,7 +94,7 @@ class ViewMessage:
|
|||
""" View packages for download only. """
|
||||
color = self.colors()
|
||||
|
||||
if self.utils.is_installed(f'{sbo}-'):
|
||||
if self.utils.is_installed(sbo):
|
||||
print(f'[{color["yellow"]} download {color["endc"]}] -> '
|
||||
f'{sbo}-{version}')
|
||||
else:
|
||||
|
@ -105,7 +105,7 @@ class ViewMessage:
|
|||
""" View packages for build. """
|
||||
color = self.colors()
|
||||
|
||||
if self.utils.is_installed(f'{sbo}-'):
|
||||
if self.utils.is_installed(sbo):
|
||||
print(f'[{color["yellow"]} build {color["endc"]}] -> '
|
||||
f'{sbo}-{version}')
|
||||
else:
|
||||
|
@ -116,7 +116,7 @@ class ViewMessage:
|
|||
""" View the packages for install. """
|
||||
color = self.colors()
|
||||
|
||||
installed = self.utils.is_installed(f'{sbo}-')
|
||||
installed = self.utils.is_installed(sbo)
|
||||
install, set_color = 'install', color['red']
|
||||
|
||||
if '--reinstall' in self.flags:
|
||||
|
@ -138,16 +138,17 @@ class ViewMessage:
|
|||
print(f'[{color["cyan"]} install {color["endc"]}] -> '
|
||||
f'{sbo}-{version}')
|
||||
|
||||
def _view_installed_packages(self, name: str):
|
||||
def _view_removed(self, name: str):
|
||||
""" View and creates list with packages for remove. """
|
||||
installed = os.listdir(self.configs.log_packages)
|
||||
color = self.colors()
|
||||
|
||||
for package in installed:
|
||||
pkg = '-'.join(package.split('-')[:-3])
|
||||
if pkg == name and self.configs.sbo_repo_tag in package and pkg not in self.black.get():
|
||||
self.installed_packages.append(package)
|
||||
print(f'[{color["red"]} delete {color["endc"]}] -> {package}')
|
||||
if self.utils.is_installed(name):
|
||||
for package in installed:
|
||||
pkg = '-'.join(package.split('-')[:-3])
|
||||
if pkg == name:
|
||||
self.installed_packages.append(package)
|
||||
print(f'[{color["red"]} delete {color["endc"]}] -> {package}')
|
||||
|
||||
def _view_total(self, slackbuilds: list, dependencies: list, option: str):
|
||||
""" View the status of the packages action. """
|
||||
|
@ -157,7 +158,7 @@ class ViewMessage:
|
|||
installed = upgraded = 0
|
||||
|
||||
for sbo in slackbuilds:
|
||||
if self.utils.is_installed(f'{sbo}-'):
|
||||
if self.utils.is_installed(sbo):
|
||||
upgraded += 1
|
||||
else:
|
||||
installed += 1
|
||||
|
|
Loading…
Reference in a new issue