Merge to utilities method

This commit is contained in:
Dimitris Zlatanidis 2023-01-09 20:06:12 +02:00
parent a6c7e8b966
commit 80c43f3851
5 changed files with 21 additions and 17 deletions

View file

@ -1,9 +1,8 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
from slpkg.configs import Configs
from slpkg.utilities import Utilities
class FindInstalled:
@ -13,17 +12,19 @@ class FindInstalled:
self.configs = Configs
colors = self.configs.colour
self.color = colors()
self.utils = Utilities()
def find(self, packages: list):
""" Find the packages. """
matching = []
installed = self.utils.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 os.listdir(self.configs.log_packages):
if pkg in package and self.configs.sbo_repo_tag in package:
for package in installed:
if pkg in package:
matching.append(package)
self.matched(matching)

View file

@ -96,7 +96,7 @@ class Argparse:
repo_packages = SBoQueries('').sbos()
# Grab all the installed packages
installed = os.listdir(self.configs.log_packages)
installed = self.utils.all_installed()
if method in ['remove', 'find']:
@ -104,10 +104,9 @@ class Argparse:
name = self.utils.split_installed_pkg(package)[0]
version = self.utils.split_installed_pkg(package)[1]
if package.endswith(self.configs.sbo_repo_tag):
for pkg in packages:
if pkg in name:
choices += [(name, version, False)]
for pkg in packages:
if pkg in name:
choices += [(name, version, False)]
else:
for package in repo_packages:
for pkg in packages:

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
from distutils.version import LooseVersion
@ -27,7 +26,9 @@ class Upgrade:
black = Blacklist().get()
upgrade, requires = [], []
for pkg in os.listdir(self.configs.log_packages):
installed = self.utils.all_installed()
for pkg in installed:
inst_pkg_name = self.utils.split_installed_pkg(pkg)[0]
if (pkg.endswith(self.configs.sbo_repo_tag)

View file

@ -33,9 +33,16 @@ class Utilities:
if pkg == name and pkg not in self.black.get():
return package
return ''
def all_installed(self):
""" Return all installed SBo packages from /val/log/packages folder. """
pattern = f'*{self.configs.sbo_repo_tag}'
var_log_packages = Path(self.configs.log_packages)
installed = [file.name for file in var_log_packages.glob(pattern)]
return installed
@staticmethod
def untar_archive(path: str, archive: str, ext_path: str):
""" Untar the file to the build folder. """

View file

@ -4,7 +4,6 @@
import os
import shutil
from typing import Any
from pathlib import Path
from distutils.version import LooseVersion
from slpkg.configs import Configs
@ -181,10 +180,7 @@ class ViewMessage:
def _view_removed(self, name: str):
""" View and creates list with packages for remove. """
pattern = f'*{self.configs.sbo_repo_tag}'
var_log_packages = Path(self.configs.log_packages)
installed = [file.name for file in var_log_packages.glob(pattern)]
installed = self.utils.all_installed()
if self.utils.is_installed(name):
for package in installed: