Updated for blacklist pattern

This commit is contained in:
Dimitris Zlatanidis 2023-04-12 22:47:50 +03:00
parent b49ca1fc15
commit 27b896ca5f
9 changed files with 42 additions and 51 deletions

View file

@ -1,3 +1,7 @@
4.7.8 - 12/04/203
Added:
- Module to support for Unix shell-style wildcards for blacklist
4.7.7 - 07/04/2023
Updated:
- Improve speed (Replace multi SQL queries)

View file

@ -1,7 +1,7 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from slpkg.blacklist import Blacklist
from slpkg.utilities import Utilities
from slpkg.models.models import BinariesTable
from slpkg.models.models import session as Session
@ -14,7 +14,7 @@ class BinQueries:
self.repo: str = repo
self.session = Session
self.black = Blacklist()
self.utils = Utilities()
def repository_data(self) -> dict:
""" Returns a dictionary with the repository data. """
@ -36,7 +36,7 @@ class BinQueries:
data.checksum,
data.repo)
for data in repository_data
if data.name not in self.black.packages()
if not self.utils.blacklist_pattern(data.name)
}
return repos_dict
@ -60,7 +60,7 @@ class BinQueries:
data.checksum,
data.repo)
for data in repositories_data
if data.name not in self.black.packages()
if not self.utils.blacklist_pattern(data.name)
}
return repos_dict

View file

@ -1,7 +1,7 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from slpkg.blacklist import Blacklist
from slpkg.utilities import Utilities
from slpkg.repositories import Repositories
@ -15,7 +15,7 @@ class Required:
self.name: str = name
self.repo: str = repo
self.repos = Repositories()
self.black = Blacklist()
self.utils = Utilities()
self.special_repos: list = [
self.repos.salixos_repo_name,
@ -40,7 +40,7 @@ class Required:
# Remove requirements that are included as dependencies,
# but are not included in the repository.
if req not in list(self.data.keys()) or req in self.black.packages():
if req not in list(self.data.keys()) or self.utils.blacklist_pattern(req):
required.remove(req)
continue

View file

@ -4,7 +4,6 @@
from pathlib import Path
from slpkg.configs import Configs
from slpkg.blacklist import Blacklist
from slpkg.utilities import Utilities
from slpkg.repositories import Repositories
from slpkg.models.models import session as Session
@ -21,7 +20,6 @@ class Check(Configs):
self.flags: list = flags
self.data: dict = data
self.black = Blacklist()
self.utils = Utilities()
self.repos = Repositories()
@ -82,7 +80,7 @@ class Check(Configs):
blacklist: list = []
for pkg in package:
if pkg in self.black.packages():
if self.utils.blacklist_pattern(pkg):
blacklist.append(pkg)
if blacklist:

View file

@ -1,7 +1,7 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from slpkg.blacklist import Blacklist
from slpkg.utilities import Utilities
class Requires:
@ -13,7 +13,7 @@ class Requires:
self.data: dict = data
self.name: str = name
self.black = Blacklist()
self.utils = Utilities()
def resolve(self) -> list:
""" Resolve the dependencies. """
@ -23,7 +23,7 @@ class Requires:
# Remove requirements that are included as dependencies,
# but are not included in the repository.
if req not in list(self.data.keys()) or req in self.black.packages():
if req not in list(self.data.keys()) or self.utils.blacklist_pattern(req):
requires.remove(req)
continue

View file

@ -1,10 +1,8 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from sqlalchemy import inspect
from slpkg.configs import Configs
from slpkg.blacklist import Blacklist
from slpkg.utilities import Utilities
from slpkg.repositories import Repositories
from slpkg.models.models import session as Session
from slpkg.models.models import SBoTable, PonceTable
@ -18,7 +16,7 @@ class SBoQueries(Configs):
self.session = Session
self.repos = Repositories()
self.black = Blacklist()
self.utils = Utilities()
# Switch between sbo and ponce repository.
self.sbo_table = SBoTable
@ -40,7 +38,7 @@ class SBoQueries(Configs):
data.requires,
data.short_description)
for data in repository_data
if data.name not in self.black.packages()
if not self.utils.blacklist_pattern(data.name)
}
return repos_dict
@ -51,12 +49,3 @@ class SBoQueries(Configs):
self.sbo_table.id).count()
return count
def repo_name(self) -> str:
""" Returns the repo name by the table. """
table = inspect(self.sbo_table)
repo = self.repos.sbo_repo_name
if table.tables[0].name == 'poncetable':
repo = self.repos.ponce_repo_name
return repo

View file

@ -4,7 +4,6 @@
from slpkg.configs import Configs
from slpkg.views.ascii import Ascii
from slpkg.utilities import Utilities
from slpkg.blacklist import Blacklist
class Tracking(Configs):
@ -18,7 +17,6 @@ class Tracking(Configs):
self.ascii = Ascii()
self.color = self.colour()
self.utils = Utilities()
self.black = Blacklist()
self.llc: str = self.ascii.lower_left_corner
self.hl: str = self.ascii.horizontal_line
@ -69,7 +67,7 @@ class Tracking(Configs):
print(f' {self.cyan}No dependencies{self.endc}')
else:
for i, req in enumerate(requires, start=1):
if req not in self.black.packages():
if not self.utils.blacklist_pattern(req):
require: str = f'{self.cyan}{req}{self.endc}'

View file

@ -5,6 +5,7 @@ import re
import time
import shutil
import logging
import fnmatch
import subprocess
from pathlib import Path
from typing import Generator, Union
@ -31,8 +32,7 @@ class Utilities:
self.endc: str = self.color['endc']
self.bred: str = f'{self.bold}{self.red}'
self.installed_packages: list = list(self.all_installed())
self.installed_package_names: list = list(self.all_installed_names())
self.installed_packages: dict = dict(self.all_installed())
logging.basicConfig(filename=LoggingConfig.log_file,
filemode='w',
@ -41,34 +41,29 @@ class Utilities:
def is_package_installed(self, name: str) -> str:
""" Returns the installed package name. """
for package in self.installed_packages:
pkg_name: str = self.split_binary_pkg(package)[0]
try:
return self.installed_packages[name]
except KeyError:
return ''
if pkg_name == name:
return package
return ''
def all_installed(self) -> Generator:
def all_installed(self) -> dict:
""" Return all installed packages from /val/log/packages folder. """
# installed_dict: dict = {}
var_log_packages: Path = Path(self.configs.log_packages)
try:
for file in var_log_packages.glob(self.configs.file_pattern):
name = self.split_binary_pkg(file.name)[0]
if not name.startswith('.') and name not in self.black.packages():
yield file.name
if not name.startswith('.') and not self.blacklist_pattern(name):
yield name, file.name
# return installed_dict
except ValueError as err:
logger = logging.getLogger(__name__)
logger.info('%s: %s: %s', self.__class__.__name__,
Utilities.all_installed.__name__,
err)
def all_installed_names(self) -> Generator:
""" Return all installed packages names from /val/log/packages folder. """
for package in self.installed_packages:
yield self.split_binary_pkg(package)[0]
@staticmethod
def remove_file_if_exists(path: Path, file: str) -> None:
""" Clean the old files. """
@ -196,3 +191,11 @@ class Utilities:
packages += list(data.keys())
return packages
def blacklist_pattern(self, name):
""" This module provides support for Unix shell-style wildcards. """
if [
black for black in self.black.packages()
if fnmatch.fnmatch(name, black)
]:
return True

View file

@ -10,7 +10,6 @@ from slpkg.upgrade import Upgrade
from slpkg.views.ascii import Ascii
from slpkg.utilities import Utilities
from slpkg.dialog_box import DialogBox
from slpkg.sbos.queries import SBoQueries
from slpkg.repositories import Repositories
from slpkg.models.models import LogsDependencies
from slpkg.models.models import session as Session
@ -65,7 +64,7 @@ class ViewMessage(Configs):
repo: str = self.repo
else:
version: str = self.data[package][2]
repo: str = SBoQueries().repo_name()
repo: str = self.repos.sbo_enabled_repository
if mode in ['install', 'download']:
color: str = self.cyan
@ -75,13 +74,13 @@ class ViewMessage(Configs):
color: str = self.violet
# If the package is installed and change the color to gray.
if package in self.utils.installed_package_names and mode == 'install':
if package in self.utils.installed_packages.keys() and mode == 'install':
color: str = self.grey
if self.upgrade.is_package_upgradeable(package) and mode == 'install':
color: str = self.violet
if (package in self.utils.installed_package_names and mode == 'install'
if (package in self.utils.installed_packages.keys() and mode == 'install'
and self.option_for_reinstall):
color: str = self.violet