Merge branch 'develop' into 'master'

update man FR

See merge request dslackw/slpkg!118
This commit is contained in:
Dimitris Zlatanidis 2023-04-14 09:44:03 +00:00
commit b5039466e2
35 changed files with 476 additions and 376 deletions

View file

@ -1,3 +1,11 @@
4.7.8 - 12/04/203
Added:
- Module to support for Unix shell-style wildcards for blacklist (Thanks yo marav)
- Supports proxies (Thanks to tpiszcze) #160
Updated:
- Config file for --reinstall option (Thanks to rizitis)
- Improve speed
4.7.7 - 07/04/2023
Updated:
- Improve speed (Replace multi SQL queries)

View file

@ -27,7 +27,7 @@ Requirements
Install
-------
Install from the official third-party `SBo repository <https://slackbuilds.org/repository/15.0/system/slpkg/>`_ or directly from source:
Install it from the official third-party `SlackBuilds.org <https://slackbuilds.org/repository/15.0/system/slpkg/>`_ repository or directly from source:
.. code-block:: bash
@ -101,6 +101,71 @@ Usage
Edit the config file in the /etc/slpkg/slpkg.toml or 'slpkg configs'.
How to start
------------
If you are going to use only the `SlackBuilds.org <https://slackbuilds.org/>`_ repository, you don't need to edit the
:code:`/etc/slpkg/repositories.toml` file, otherwise edit the file and set :code:`true` the repositories you want.
The second step is to update the package lists and install the data to the database, just run:
.. code-block:: bash
$ slpkg update
or for binary repositories:
.. code-block:: bash
$ slpkg update --bin-repo='*'
Now you are ready to start!
To install a package from the `SlackBuilds.org <https://slackbuilds.org/>`_ or `Ponce <https://cgit.ponce.cc/slackbuilds/>`_ repository, run:
.. code-block:: bash
$ slpkg install <package_name>
or from a binary repository:
.. code-block:: bash
$ slpkg install <package_name> --bin-repo=<repo_name>
You can install a whole repository with the command:
.. code-block:: bash
$ slpkg install '*' --bin-repo=gnome --resolve-off
Note: Apply the option '--resolve-off' to speed up the process because the gnome repository has no references to the dependencies.
To remove a package with the dependencies:
.. code-block:: bash
$ slpkg remove <package_name>
If you wan to search a package from all binaries repositories, run:
.. code-block:: bash
$ slpkg search libreoffice --bin-repo='*'
For further information, please read the manpage:
.. code-block:: bash
$ man slpkg
Edit the configuration :code:`/etc/slpkg/slpkg.toml` file:
.. code-block:: bash
$ slpkg configs
Configuration files
-------------------
@ -157,6 +222,11 @@ If you feel satisfied with this project and want to thanks me make a donation.
.. image:: https://gitlab.com/dslackw/images/raw/master/donate/paypaldonate.png
:target: https://www.paypal.me/dslackw
Report bugs
-----------
Please report any issue here: `Issues <https://gitlab.com/dslackw/slpkg/-/issues>`_
Copyright
---------

View file

@ -1,7 +1,13 @@
[BLACKLIST]
# Add packages and separate them with commas.
# Example: ["package_1", "package_2", "package_3"].
# The "%README%" is part of REQUIRES indicating that important
# informationabout dependencies is available in the README file.
PACKAGES = ["%README%"]
# Support for Unix shell-style wildcards:
# '*' matches everything
# '?' matches any single character
# '[seq]' matches any character in seq
# '[!seq]' matches any character not in seq
# See: https://docs.python.org/3.9/library/fnmatch.html
# Example: PACKAGES = ["package", "package*", "[package]"].
PACKAGES = []

View file

@ -1,4 +1,5 @@
[CONFIGS]
# OS architecture by default.
OS_ARCH = "x86_64"
# Where the packages download.
@ -36,9 +37,17 @@
SPINNER_COLOR = "green"
# Slackware command for install packages, instead, you can use 'installpkg'.
# Normally upgradepkg only upgrades packages that are already installed
# on the system, and will skip any packages that do not already have a
# version installed. If --install- new is specified, the behavior is
# modified to install new packages in addition to upgrading existing ones.
INSTALLPKG = "upgradepkg --install-new"
# Slackware command to reinstall packages.
REINSTALL = "upgradepkg --reinstall"
# Upgradepkg usually skips packages if the exact same package (matching name,
# version, arch, and build number) is already installed on the system. Use
# the --reinstall option if you want to upgrade all packages even if the same
# version is already installed.
REINSTALL = "upgradepkg --install-new --reinstall"
# Slackware command to remove packages.
REMOVEPKG = "removepkg"
@ -56,3 +65,12 @@
LFTP_GET_OPTIONS = "-c get -e"
# Lftp mirror options are used to synchronize with the repositories.
LFTP_MIRROR_OPTIONS = "-c mirror --parallel=100 --only-newer"
# If you are going to use a proxy server, try to fill in these variables.
# Choose between http or socks proxy type, not both.
# For a socks proxy, you need to install the PySocks package.
# https://urllib3.readthedocs.io/en/stable/advanced-usage.html#socks-proxies
HTTP_PROXY_ADDRESS = ""
SOCKS_PROXY_ADDRESS = ""
PROXY_USERNAME = ""
PROXY_PASSWORD = ""

View file

@ -210,6 +210,33 @@ En plus de la façon classique, vous pouvez mettre ensemble plusieurs options qu
Au lieu de paquets, vous pouvez passer un fichier texte avec le suffixe '.pkgs' et les noms des paquets. Exemple : 'slpkg install list.pkgs'.
Éditer la configuration '/etc/slpkg/slpkg.toml' pour changer le suffixe si vous le souhaitez. Vous pouvez utiliser des listes provenant d'autres sources, avec des fichiers '.sqf'.
.RE
.SH A SAVOIR
.P
Il y a cinq indicateurs lorsque certaines commandes sont utilisées, par exemple :
Cyan : Installer, Jaune : Pour construire, Gris : C'est installé, Violet : Pour la mise à jour, Rouge : Pour supprimer.
Lorsque vous utilisez les commandes install, build, upgrade ou remove, vous devez savoir que si le paquet est installé,
sa couleur passera au gris, si le paquet peut être mis à niveau, il devient violet. Et s'il n'est pas installé alors
sa couleur sera cyan. De même, si vous essayez de supprimer un paquet, la couleur du paquet devient rouge.
Exemple : Si le paquet est déjà installé, que la couleur de l'indicateur est grise et que l'option '\fB-r, --reinstall\fR' n'est pas appliquée,
le paquetage ne sera pas installé et le message "(already installed)" s'affichera.
Si le paquet peut être mis à niveau, l'installation se poursuivra et le paquet passera à la mise à niveau.
Pour la commande de mise à niveau, vous devez savoir que vous pouvez mettre à niveau des paquets provenant de différents dépôts, si vous éditez
le fichier '\fI/etc/slpkg/repositories.toml\fR' et supprimez la balise repository. Le slpkg ne peut alors pas reconnaître le dépôt des paquets.
Avec la commande remove, il va supprimer les dépendances si le paquet a été installé avec la commande '\fIslpkg install\fR',
sinon, le slpkg ne connaît pas les dépendances qui sont installées avec les paquets qu'il va supprimer.
Vous pouvez appliquer l'astérisque '*' à la place d'un paquet, pour faire correspondre tous les paquets d'un dépôt. Vous ne pouvez pas appliquer
un astérisque à l'option '\fB-B, --bin-repos=\fR', sauf pour les commandes '\fB-s, search\fR', '\fB-u, update\fR' et '\fB-c, check-updates\fR'.
La commande clean-data supprime les données du référentiel local et de la base de données.
Remarque : il n'existe actuellement aucune fonction permettant d'indiquer les paquets si les couleurs sont désactivées.
.RE
.SH FICHIERS DE CONFIGURATION
.P
Fichier de \fBconfiguration\fP : /etc/slpkg/slpkg.toml

View file

@ -1,4 +1,4 @@
.TH slpkg 1 "Orestiada, Greece" "slpkg 4.7.7" dslackw
.TH slpkg 1 "Orestiada, Greece" "slpkg 4.7.8" dslackw
.SH NAME
.P
slpkg \- Package manager utility for Slackware.
@ -225,18 +225,18 @@ When you use the install, build, upgrade or remove commands you should know that
color will change to gray, if the package is upgradeable then it will change to violet, and if it is not installed then
its color will be cyan. Also, if you try to remove a package you will see the package color turns red.
Example: If the package is already installed and the indicator color is grey and the option '-r, --reinstall' is not applied,
Example: If the package is already installed and the indicator color is grey and the option '\fB-r, --reinstall\fR' is not applied,
the package will skip from the installation and you will see a message '(already installed)'.
If the package is upgradeable, the installation will continue and the package will go to upgrade.
For the upgrade command, you should know, that you can upgrade packages from different repositories, if you edit
the '/etc/slpkg/repositories.toml' file and remove the repository tag. Then the slpkg can't recognize the repository of the packages.
the '\fI/etc/slpkg/repositories.toml\fR' file and remove the repository tag. Then the slpkg can't recognize the repository of the packages.
With the remove command, it's going to remove the dependencies if the package had installed with the 'slpkg install' command,
With the remove command, it's going to remove the dependencies if the package had installed with the '\fIslpkg install\fR' command,
otherwise, the slpkg does not know the dependencies that are installed with the packages that going to remove.
You can apply the asterisk '*' instead of a package, to matching all the packages from a repository. You can't apply
an asterisk to the '-B, --bin-repos=' option, except for the '-s, search', '-u, update' and '-c, check-updates' commands.
an asterisk to the '\fB-B, --bin-repos=\fR' option, except for the '\fB-s, search\fR', '\fB-u, update\fR' and '\fB-c, check-updates\fR' commands.
Command clean-data, removes the local repository data and the database data.

View file

@ -1,3 +1,6 @@
SQLAlchemy >= 1.4.46
pythondialog >= 3.5.3
progress >= 1.6
[socks]
PySocks >= 1.7.1

View file

@ -1,6 +1,6 @@
[metadata]
name = slpkg
version = 4.7.7
version = 4.7.8
license_file = LICENSE
author = Dimitris Zlatanidis
author_email = d.zlatanidis@gmail.com
@ -43,5 +43,9 @@ install_requires =
progress >= 1.6
include_package_data = True
[options.extras_require]
socks =
PySocks >= 1.7.1
[options.packages.find]
where = .

View file

@ -253,6 +253,9 @@ class Packages(Configs):
if self.mode == 'install' and not installed:
status: bool = True
if self.option_for_reinstall:
status: bool = True
choices += [(package, repo_ver, status, help_text)]
text: str = f'There are {len(choices)} dependencies:'

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,15 +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
def count_packages(self) -> int:
""" Counts the number of the packages. """
count = self.session.query(
BinariesTable.id).where(
BinariesTable.repo == self.repo).count()
return count

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

@ -2,9 +2,9 @@
# -*- coding: utf-8 -*-
import os
import urllib3
from pathlib import Path
from multiprocessing import Process
from urllib3 import PoolManager, ProxyManager, make_headers
from slpkg.configs import Configs
from slpkg.utilities import Utilities
@ -168,7 +168,21 @@ class CheckUpdates(Configs):
def compare_dates(self) -> bool:
local_date: int = 0
try:
http = urllib3.PoolManager()
http = PoolManager()
proxy_default_headers = make_headers(proxy_basic_auth=f'{self.proxy_username}:{self.proxy_password}')
if self.http_proxy_address:
http = ProxyManager(f'{self.http_proxy_address}', headers=proxy_default_headers)
elif self.socks_proxy_address:
# https://urllib3.readthedocs.io/en/stable/advanced-usage.html#socks-proxies
try: # Try to import PySocks if it's installed.
from urllib3.contrib.socks import SOCKSProxyManager
except (ModuleNotFoundError, ImportError):
raise SystemExit()
http = SOCKSProxyManager(f'{self.socks_proxy_address}', headers=proxy_default_headers)
repo = http.request('GET', self.repo_chg_txt)
except KeyboardInterrupt:
raise SystemExit(1)

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()
@ -77,17 +75,6 @@ class Check(Configs):
if not_found:
self.utils.raise_error_message(f'Not found \'{", ".join(not_found)}\' installed packages')
def is_blacklist(self, package: list) -> None:
""" Checking if the packages are blacklisted. """
blacklist: list = []
for pkg in package:
if pkg in self.black.packages():
blacklist.append(pkg)
if blacklist:
self.utils.raise_error_message(f"The packages '{', '.join(blacklist)}' is blacklisted")
def is_empty_database(self) -> None:
""" Checking for empty table and database file. """
db = Path(self.db_path, self.database_name)

View file

@ -77,6 +77,11 @@ class Configs:
progress_spinner: str = 'pixel'
spinner_color: str = 'green'
http_proxy_address: str = ''
socks_proxy_address: str = ''
proxy_username: str = ''
proxy_password: str = ''
load = Load()
configs = load.config_file(etc_path, prog_name)
@ -104,6 +109,10 @@ class Configs:
file_pattern_conf: str = config['FILE_PATTERN']
progress_spinner: str = config['PROGRESS_SPINNER']
spinner_color: str = config['SPINNER_COLOR']
http_proxy_address: str = config['HTTP_PROXY_ADDRESS']
socks_proxy_address: str = config['SOCKS_PROXY_ADDRESS']
proxy_username: str = config['PROXY_USERNAME']
proxy_password: str = config['PROXY_PASSWORD']
except KeyError as error:
raise SystemExit(f"\n{prog_name}: {color['bold']}{color['red']}Error{color['endc']}: "

View file

@ -51,7 +51,7 @@ class Dependees(Configs):
self.packages: list = self.utils.apply_package_pattern(self.data, self.packages)
for pkg in self.packages:
dependees: list = list(self.find_requires(pkg))
dependees: dict = dict(self.find_requires(pkg))
package: str = f'{self.byellow}{pkg}{self.endc}'
@ -71,17 +71,17 @@ class Dependees(Configs):
print(f'{self.cyan} No dependees{self.endc}')
sp: str = ' ' * 4
for i, dep in enumerate(dependees, start=1):
dependency: str = f'{self.cyan}{dep[0]}{self.endc}'
for i, (name, requires) in enumerate(dependees.items(), start=1):
dependency: str = f'{self.cyan}{name}{self.endc}'
if self.option_for_pkg_version:
if self.option_for_binaries:
version: str = self.data[dep[0]][0]
version: str = self.data[name][0]
else:
version: str = self.data[dep[0]][2]
version: str = self.data[name][2]
dependency: str = (f'{self.cyan}{dep[0]}{self.endc} {self.yellow}'
dependency: str = (f'{self.cyan}{name}{self.endc} {self.yellow}'
f'{version}{self.endc}')
if i == 1:
@ -91,26 +91,21 @@ class Dependees(Configs):
if self.option_for_full_reverse:
if i == len(dependees):
print(' ' * 4 + f' {self.llc}{self.hl} {self.violet}{dep[1]}{self.endc}')
print(' ' * 4 + f' {self.llc}{self.hl} {self.violet}{requires}{self.endc}')
else:
print(' ' * 4 + f' {self.var}{self.hl} {self.violet}{dep[1]}{self.endc}')
print(' ' * 4 + f' {self.var}{self.hl} {self.violet}{requires}{self.endc}')
print(f'\n{self.grey}{len(dependees)} dependees for {pkg}{self.endc}\n')
def find_requires(self, pkg: str) -> Generator[str, None, None]:
def find_requires(self, pkg: str) -> Generator:
""" Find requires that package dependees. """
if self.option_for_binaries:
for name, data in self.data.items():
if name:
for req in data[6].split():
if req == pkg:
if pkg in data[6].split():
yield name, data[6]
yield [name, data[6]]
else:
for name, data in self.data.items():
if name:
for req in data[7].split():
if req == pkg:
yield [name, data[7]]
if pkg in data[7].split():
yield name, data[7]

View file

@ -21,7 +21,7 @@ class FindInstalled(Configs):
self.endc: str = self.color['endc']
self.grey: str = self.color['grey']
self.installed: list = self.utils.installed_packages
self.installed: dict = self.utils.installed_packages
def find(self, packages: list) -> None:
""" Find the packages. """
@ -31,7 +31,7 @@ class FindInstalled(Configs):
f'that contains \'{", ".join([p for p in packages])}\' files:\n')
for pkg in packages:
for package in self.installed:
for package in self.installed.values():
if pkg in package or pkg == '*':
matching.append(package)

View file

@ -290,7 +290,6 @@ class Argparse(Configs):
self.data: dict = SBoQueries().repository_data()
self.check = Check(self.flags, self.data)
self.check.is_blacklist(self.args[1:])
logging.basicConfig(filename=LoggingConfig.log_file,
filemode='w',
@ -307,7 +306,10 @@ class Argparse(Configs):
'-c', 'check-updates',
]
if self.binary_repo == '*' and not self.utils.is_option(except_options, self.args):
if self.binary_repo in self.repos.bin_repos_names and self.binary_repo not in self.repos.bin_enabled_repos:
self.usage.help_minimal(f"{self.prog_name}: repository '{self.binary_repo}' is disabled")
elif self.binary_repo == '*' and not self.utils.is_option(except_options, self.args):
self.usage.help_minimal(f"{self.prog_name}: invalid binary repository '{self.binary_repo}'")
elif self.binary_repo not in self.repos.bin_repos_names and self.binary_repo != '*':
@ -435,9 +437,8 @@ class Argparse(Configs):
repo_packages: list = list(self.data.keys())
installed: list = self.utils.installed_packages
if method in ['remove', 'find']:
installed: list = list(self.utils.installed_packages.values())
for package in installed:
split_package: list = self.utils.split_binary_pkg(package)

View file

@ -5,11 +5,9 @@ import shutil
from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.sbos.queries import SBoQueries
from slpkg.repositories import Repositories
from slpkg.binaries.queries import BinQueries
from slpkg.models.models import LastRepoUpdated
from slpkg.models.models import session as Session
from slpkg.models.models import LastRepoUpdated, SBoTable, BinariesTable
class RepoInfo(Configs):
@ -61,9 +59,9 @@ class RepoInfo(Configs):
if value[0]:
if repo in [self.repos.sbo_repo_name, self.repos.ponce_repo_name]:
count = int(SBoQueries().count_packages())
count = self.session.query(SBoTable.id).count()
else:
count = int(BinQueries(repo).count_packages())
count = self.session.query(BinariesTable).where(BinariesTable.repo == repo).count()
total_packages += count

View file

@ -471,7 +471,4 @@ class Repositories:
bin_repos_names = list(repositories.keys())[2:]
# All the enabled binary repositories names.
for repo, enabled in repositories.items():
if repo not in [sbo_repo_name, ponce_repo_name]:
if enabled[0]:
bin_enabled_repos.append(repo)
bin_enabled_repos = list(repositories.keys())[2:]

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,23 +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
def count_packages(self) -> int:
""" Counts the number of the packages. """
count = self.session.query(
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

@ -378,7 +378,7 @@ class Slackbuilds(Configs):
for package in dependencies:
status: bool = False
repo_ver: str = self.data[package][0]
repo_ver: str = self.data[package][2]
description: str = self.data[package][8]
help_text: str = f'Description: {description}'
upgradable: bool = self.upgrade.is_package_upgradeable(package)
@ -396,6 +396,9 @@ class Slackbuilds(Configs):
if self.mode == 'install' and not installed:
status: bool = True
if self.option_for_reinstall:
status: bool = True
choices += [(package, repo_ver, status, help_text)]
text: str = f'There are {len(choices)} dependencies:'

View file

@ -43,7 +43,7 @@ class SearchPackage(Configs):
for package in packages:
for data_pkg in data.values():
if package in data_pkg[1] or package == '*':
if package in data_pkg[0] or package == '*':
matching += 1
print(f'{data_pkg[12]}: {self.cyan}{data_pkg[0]}{self.endc} '

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

@ -35,7 +35,7 @@ class Upgrade(Configs):
""" Returns the upgradable packages. """
# Returns the matched packages between two lists.
packages: list = list(set(self.utils.installed_package_names) & set(list(self.data.keys())))
packages: list = list(set(self.utils.installed_packages.keys()) & set(list(self.data.keys())))
for pkg in packages:
if self.is_package_upgradeable(pkg):

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',
@ -40,35 +40,29 @@ class Utilities:
level=logging.INFO)
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]
if pkg_name == name:
return package
""" Returns the installed package binary. """
try:
return self.installed_packages[name]
except KeyError:
return ''
def all_installed(self) -> Generator:
def all_installed(self) -> dict:
""" Return all installed packages from /val/log/packages folder. """
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
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 +190,8 @@ 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

@ -5,7 +5,7 @@ class Version:
""" Print the version. """
def __init__(self):
self.version_info: tuple = (4, 7, 7)
self.version_info: tuple = (4, 7, 8)
self.version: str = '{0}.{1}.{2}'.format(*self.version_info)
self.license: str = 'MIT License'
self.author: str = 'Dimitris Zlatanidis (dslackw)'

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

View file

@ -9,9 +9,6 @@ class TestBinQueries(unittest.TestCase):
self.repo_data = self.bin_queries.repository_data()
self.repos_data = self.bin_queries.repositories_data()
def test_count_packages(self):
self.assertGreater(self.bin_queries.count_packages(), 1)
def test_repository_data(self):
self.assertGreater(len(list(self.repo_data.keys())), 1)

View file

@ -6,7 +6,7 @@ class TestBlacklist(unittest.TestCase):
def test_blacklist(self):
black = Blacklist()
self.assertListEqual(['%README%'], black.packages())
self.assertListEqual([], black.packages())
if __name__ == '__main__':

View file

@ -20,12 +20,6 @@ class TestPkgInstalled(unittest.TestCase):
def test_check_is_installed(self):
self.assertIsNone(self.check.is_package_unsupported(self.packages))
def test_check_blacklist(self):
self.assertIsNone(self.check.is_blacklist(self.packages))
def test_check_is_empty(self):
self.assertIsNone(self.check.is_blacklist(self.packages))
if __name__ == "__main__":
unittest.main()

View file

@ -38,6 +38,10 @@ class TestConfigs(unittest.TestCase):
self.assertEqual('*', self.configs.file_pattern)
self.assertEqual('pixel', self.configs.progress_spinner)
self.assertEqual('green', self.configs.spinner_color)
self.assertEqual('', self.configs.http_proxy_address)
self.assertEqual('', self.configs.socks_proxy_address)
self.assertEqual('', self.configs.proxy_username)
self.assertEqual('', self.configs.proxy_password)
if __name__ == '__main__':

View file

@ -36,14 +36,6 @@ class TestUtilities(unittest.TestCase):
def test_all_installed(self):
self.assertIn(self.package, self.utils.all_installed())
def test_all_installed_names(self):
self.assertIn('aaa_base', self.utils.all_installed_names())
self.assertIn('vim', self.utils.all_installed_names())
self.assertIn('nano', self.utils.all_installed_names())
self.assertIn('wget', self.utils.all_installed_names())
self.assertIn('curl', self.utils.all_installed_names())
self.assertIn('lftp', self.utils.all_installed_names())
def test_read_build_tag(self):
self.assertEqual('1', self.utils.read_sbo_build_tag('slpkg', 'system'))