Merge branch 'develop'

This commit is contained in:
Dimitris Zlatanidis 2022-06-24 19:28:23 +03:00
commit 8c29d78b80
28 changed files with 480 additions and 194 deletions

View file

@ -1,3 +1,12 @@
4.1.1 - 23/06/2022
Updated:
- Cli menu view with colors
- Switch to yaml configurations
Added:
- Unittests
- Command clean-tmp to deletes all downloaded sources from /tmp/slpkg folder
- Command find installed packages
4.1.0 - 20/06/2022 4.1.0 - 20/06/2022
Updated: Updated:
- slpkg code re-written from the beginning and currently supports only the SBo repository - slpkg code re-written from the beginning and currently supports only the SBo repository

View file

@ -4,7 +4,7 @@
About About
----- -----
Slpkg is a software package manager that installs, updates and removes packages on `Slackware <http://www.slackware.com/>`_ -based systems. Slpkg is a software package manager that installs, updates and removes packages on `Slackware <http://www.slackware.com/>`_-based systems.
It automatically calculates dependencies and figures out what things need to happen to install packages. It automatically calculates dependencies and figures out what things need to happen to install packages.
Slpkg makes it easier to manage groups of machines without the need for manual updates. Slpkg makes it easier to manage groups of machines without the need for manual updates.
@ -21,6 +21,7 @@ Requirements
.. code-block:: bash .. code-block:: bash
SQLAlchemy>=1.4.36 SQLAlchemy>=1.4.36
PyYAML>=6.0
Install Install
------- -------
@ -29,8 +30,8 @@ Install from the official third-party `SBo repository <https://slackbuilds.org/r
.. code-block:: bash .. code-block:: bash
$ tar xvf slpkg-4.1.0.tar.gz $ tar xvf slpkg-4.1.1.tar.gz
$ cd slpkg-4.1.0 $ cd slpkg-4.1.1
$ ./install.sh $ ./install.sh
@ -41,25 +42,31 @@ Usage
$ slpkg --help $ slpkg --help
Usage: slpkg [OPTIONS] <packages> USAGE: slpkg [OPTIONS] [COMMAND] <packages>
DESCRIPTION:
Packaging tool that interacts with the SBo repository. Packaging tool that interacts with the SBo repository.
Options: COMMANDS:
update Update the package lists. update Update the package lists.
build Build only the packages. build <packages> Build only the packages.
install Build and install the packages. install <packages> Build and install the packages.
remove Remove installed packages. remove <packages> Remove installed packages.
search Search packages by name. find <packages> Find installed packages.
clean-logs Purge logs of dependencies. search <packages> Search packages on repository.
clean-logs Clean dependencies log tracking.
clean-tmp Deletes all the downloaded sources.
--yes Answer Yes to all questions. OPTIONS:
--jobs Set it for multicore systems. --yes Answer Yes to all questions.
--resolve-off Turns off dependency resolving. --jobs Set it for multicore systems.
--reinstall Use this option if you want to upgrade. --resolve-off Turns off dependency resolving.
--reinstall Use this option if you want to upgrade.
-h, --help Show this message and exit. -h, --help Show this message and exit.
-v, --version Print version and exit. -v, --version Print version and exit.
If you need more information try to use slpkg manpage.
Configuration files Configuration files
@ -67,10 +74,10 @@ Configuration files
.. code-block:: bash .. code-block:: bash
/etc/slpkg/slpkg.json /etc/slpkg/slpkg.yaml
General configuration of slpkg General configuration of slpkg
/etc/slpkg/blacklist.json /etc/slpkg/blacklist.yaml
Blacklist of packages Blacklist of packages
Donate Donate

View file

@ -1,3 +0,0 @@
{
"blacklist": []
}

2
configs/blacklist.yaml Normal file
View file

@ -0,0 +1,2 @@
blacklist:
packages: []

View file

@ -1,23 +0,0 @@
{
"os_arch": "x86_64",
"tmp_path": "/tmp",
"tmp_slpkg": "/tmp/slpkg",
"build_path": "/tmp/slpkg/build",
"lib_path": "/var/lib/slpkg",
"etc_path": "/etc/slpkg",
"db_path": "/var/lib/slpkg/database",
"sbo_repo_path": "/var/lib/slpkg/repository",
"log_packages": "/var/log/packages",
"database": "database.slpkg",
"repo_version": "15.0",
"sbo_url": "http://slackbuilds.org/slackbuilds/15.0",
"sbo_txt": "SLACKBUILDS.TXT",
"tar_suffix": ".tar.gz",
"pkg_suffix": ".tgz",
"repo_tag": "_SBo",
"installpkg": "upgradepkg --install-new",
"reinstall": "upgradepkg --reinstall",
"removepkg": "removepkg",
"colors": "on",
"wget_options": "-c -N"
}

22
configs/slpkg.yaml Normal file
View file

@ -0,0 +1,22 @@
configs:
os_arch: x86_64
tmp_path: /tmp
tmp_slpkg: /tmp/slpkg
build_path: /tmp/slpkg/build
lib_path: /var/lib/slpkg
etc_path: /etc/slpkg
db_path: /var/lib/slpkg/database
sbo_repo_path: /var/lib/slpkg/repository
log_packages: /var/log/packages
database: database.slpkg
repo_version: 15.0
sbo_url: http://slackbuilds.org/slackbuilds/15.0
sbo_txt: SLACKBUILDS.TXT
tar_suffix: .tar.gz
pkg_suffix: .tgz
repo_tag: _SBo
installpkg: upgradepkg --install-new
reinstall: upgradepkg --reinstall
removepkg: removepkg
colors: on
wget_options: -c -N

View file

@ -1,16 +1,16 @@
.TH slpkg 1 "Orestiada, Greece" "slpkg 4.1.0" dslackw .TH slpkg 1 "Orestiada, Greece" "slpkg 4.1.0" dslackw
.SH NAME .SH NAME
.P .P
slpkg - [OPTIONS] <packages> slpkg - [OPTIONS] [COMMAND] <packages>
.SH SYNAPSES .SH SYNAPSES
.P .P
slpkg [-h|-v] [update] [build] [install] [remove] [search] [clean-logs] --yes --resolve-off --reinstall slpkg [-h|-v] [update] [build] [install] [remove] [find] [search] [clean-logs] [clean-tmp] --yes --resolve-off --reinstall
.SH DESCRIPTION .SH DESCRIPTION
.P .P
Slpkg is a software package manager that installs, updates, and removes packages on Slackware based systems. It automatically computes dependencies and figures out what things should occur to install packages. Slpkg makes it easier to maintain groups of machines without having to manually update. Slpkg is a software package manager that installs, updates, and removes packages on Slackware based systems. It automatically computes dependencies and figures out what things should occur to install packages. Slpkg makes it easier to maintain groups of machines without having to manually update.
.P .P
Slpkg works in accordance with the standards of the organization SlackBuilds.org to build packages. Also uses the Slackware Linux instructions for installation, upgrading or removing packages. Slpkg works in accordance with the standards of the organization SlackBuilds.org to build packages. Also uses the Slackware Linux instructions for installation, upgrading or removing packages.
.SH OPTIONS .SH COMMANDS
.P .P
update update
.RS .RS
@ -32,16 +32,27 @@ remove
Removes packages with dependencies if the packages was installed with slpkg install method. Removes packages with dependencies if the packages was installed with slpkg install method.
.RE .RE
.P .P
find
.RS
Find sbo installed packages on your distribution.
.RE
.P
search search
.RS .RS
Search packages by name and view everything in your terminal. Search packages on repository and view everything in your terminal.
.RE .RE
.P .P
clean-logs clean-logs
.RS .RS
Purge logs of dependencies. Cleans dependencies log tracking.
.RE .RE
.P .P
clean-tmp
.RS
Deletes all the downloaded sources.
.RE
.SH OPTIONS
.P
--yes --yes
.RS .RS
Answer Yes to all questions. Answer Yes to all questions.
@ -74,9 +85,9 @@ Print version and exit.
.RE .RE
.SH CONFIGURATION FILES .SH CONFIGURATION FILES
.P .P
Configuration file in the /etc/slpkg/slpkg.json file. Configuration file in the /etc/slpkg/slpkg.yaml file.
.RE .RE
Blacklist file in the /etc/slpkg/blacklist.json file. Blacklist file in the /etc/slpkg/blacklist.yaml file.
.SH REPORT BUGS .SH REPORT BUGS
.P .P
Please report any found to https://gitlab.com/dslackw/slpkg/-/issues. Please report any found to https://gitlab.com/dslackw/slpkg/-/issues.

View file

@ -1,2 +1,3 @@
SQLAlchemy>=1.4.36 SQLAlchemy>=1.4.36
PyYAML>=6.0

View file

@ -6,7 +6,8 @@ from setuptools import setup
from slpkg.version import Version from slpkg.version import Version
install_requires = ['SQLAlchemy>=1.4.36'] install_requires = ['SQLAlchemy>=1.4.36',
'PyYAML>=6.0']
setup( setup(
@ -21,8 +22,8 @@ setup(
author='dslackw', author='dslackw',
url='https://dslackw.gitlab.io/slpkg/', url='https://dslackw.gitlab.io/slpkg/',
package_data={'': ['LICENSE.txt', 'README.rst', 'ChangeLog.txt']}, package_data={'': ['LICENSE.txt', 'README.rst', 'ChangeLog.txt']},
data_files=[('/etc/slpkg', ['configs/slpkg.json']), data_files=[('/etc/slpkg', ['configs/slpkg.yaml']),
('/etc/slpkg', ['configs/blacklist.json']), ('/etc/slpkg', ['configs/blacklist.yaml']),
('/var/lib/slpkg/database', []), ('/var/lib/slpkg/database', []),
('/var/lib/slpkg/repository', []), ('/var/lib/slpkg/repository', []),
('/tmp/slpkg/build', [])], ('/tmp/slpkg/build', [])],

View file

@ -8,8 +8,8 @@ config() {
fi fi
} }
config etc/slpkg/slpkg.json.new config etc/slpkg/slpkg.yaml.new
config etc/slpkg/blacklist.json.new config etc/slpkg/blacklist.yaml.new
if [ -x /usr/bin/update-desktop-database ]; then if [ -x /usr/bin/update-desktop-database ]; then
/usr/bin/update-desktop-database -q usr/share/applications >/dev/null 2>&1 /usr/bin/update-desktop-database -q usr/share/applications >/dev/null 2>&1

View file

@ -98,8 +98,8 @@ find $PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | gr
# install configuration files # install configuration files
mkdir -p $PKG/etc/slpkg mkdir -p $PKG/etc/slpkg
install -D -m0644 configs/slpkg.json $PKG/etc/slpkg/slpkg.json.new install -D -m0644 configs/slpkg.yaml $PKG/etc/slpkg/slpkg.yaml.new
install -D -m0644 configs/blacklist.json $PKG/etc/slpkg/blacklist.json.new install -D -m0644 configs/blacklist.yaml $PKG/etc/slpkg/blacklist.yaml.new
mkdir -p $PKG/usr/man/man1 mkdir -p $PKG/usr/man/man1
cp man/slpkg.1 $PKG/usr/man/man1 cp man/slpkg.1 $PKG/usr/man/man1

View file

@ -3,7 +3,7 @@
import os import os
import json import yaml
from dataclasses import dataclass from dataclasses import dataclass
from slpkg.configs import Configs from slpkg.configs import Configs
@ -15,7 +15,7 @@ class Blacklist:
etc_path: str = Configs.etc_path etc_path: str = Configs.etc_path
def get(self): def get(self):
file = f'{self.etc_path}/blacklist.json' file = f'{self.etc_path}/blacklist.yaml'
if os.path.isfile(file): if os.path.isfile(file):
with open(file, 'r') as black: with open(file, 'r') as black:
return json.load(black)['blacklist'] return yaml.safe_load(black)['blacklist']['packages']

View file

@ -3,7 +3,7 @@
import os import os
import json import yaml
from dataclasses import dataclass from dataclasses import dataclass
@ -49,11 +49,12 @@ class Configs:
wget_options = '-c -N' wget_options = '-c -N'
''' Overwrite with user configuration. ''' ''' Overwrite with user configuration. '''
config_file: str = f'{etc_path}/{prog_name}.json' config_file: str = f'{etc_path}/{prog_name}.yaml'
if os.path.isfile(config_file): if os.path.isfile(config_file):
with open(config_file, 'r') as conf: with open(config_file, 'r') as conf:
config = json.load(conf) configs = yaml.safe_load(conf)
config = configs['configs']
# OS architecture by default # OS architecture by default
os_arch: str = config['os_arch'] os_arch: str = config['os_arch']
@ -91,6 +92,7 @@ class Configs:
@classmethod @classmethod
def colour(cls): def colour(cls):
color = { color = {
'BOLD': '',
'RED': '', 'RED': '',
'GREEN': '', 'GREEN': '',
'YELLOW': '', 'YELLOW': '',
@ -100,8 +102,9 @@ class Configs:
'ENDC': '' 'ENDC': ''
} }
if cls.colors in ['on', 'ON']: if cls.colors:
color = { color = {
'BOLD': '\033[1m',
'RED': '\x1b[91m', 'RED': '\x1b[91m',
'GREEN': '\x1b[32m', 'GREEN': '\x1b[32m',
'YELLOW': '\x1b[93m', 'YELLOW': '\x1b[93m',

30
slpkg/find_installed.py Normal file
View file

@ -0,0 +1,30 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
from dataclasses import dataclass
from slpkg.configs import Configs
@dataclass
class FindInstalled:
log_packages: str = Configs.log_packages
colors: dict = Configs.colour
repo_tag: str = Configs.repo_tag
def find(self, packages: list):
matching = []
for pkg in packages:
for package in os.listdir(self.log_packages):
if pkg in package and self.repo_tag in package:
matching.append(package)
self.matched(matching)
def matched(self, matching: list):
color = self.colors()
if matching:
for package in matching:
print(f'{color["CYAN"]}{package}{color["ENDC"]}')
else:
print('\nDoes not match any package.\n')

View file

@ -8,8 +8,11 @@ from dataclasses import dataclass
from slpkg.checks import Check from slpkg.checks import Check
from slpkg.search import Search from slpkg.search import Search
from slpkg.version import Version from slpkg.version import Version
from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.views.cli_menu import usage from slpkg.views.cli_menu import usage
from slpkg.slackbuild import Slackbuilds from slpkg.slackbuild import Slackbuilds
from slpkg.find_installed import FindInstalled
from slpkg.remove_packages import RemovePackages from slpkg.remove_packages import RemovePackages
from slpkg.clean_logs import CleanLogsDependencies from slpkg.clean_logs import CleanLogsDependencies
from slpkg.update_repository import UpdateRepository from slpkg.update_repository import UpdateRepository
@ -19,114 +22,157 @@ from slpkg.update_repository import UpdateRepository
class Argparse: class Argparse:
args: list args: list
def flags(self): def __post_init__(self):
self.flags = [] self.flag()
yes = '--yes' self.check = Check()
jobs = '--jobs'
resolve_off = '--resolve-off'
reinstall = '--reinstall'
if yes in self.args: if len(self.args) == 0:
self.args.remove(yes)
self.flags.append(yes)
if jobs in self.args:
self.args.remove(jobs)
self.flags.append(jobs)
if resolve_off in self.args:
self.args.remove(resolve_off)
self.flags.append(resolve_off)
if reinstall in self.args:
self.args.remove(reinstall)
self.flags.append(reinstall)
def command(self):
self.flags()
check = Check()
if len(self.args) <= 0:
usage(1) usage(1)
def flag(self):
self.flags = []
self.options = ['--yes',
'--jobs',
'--resolve-off',
'--reinstall'
]
for option in self.options:
if option in self.args:
self.args.remove(option)
self.flags.append(option)
def help(self):
if len(self.args) == 1: if len(self.args) == 1:
if self.args[0] in ['--help', '-h']: usage(0)
usage(0) usage(1)
if self.args[0] in ['--version', '-v']: def version(self):
version = Version() if len(self.args) == 1:
version.view() version = Version()
raise SystemExit() version.view()
raise SystemExit()
usage(1)
if self.args[0] == 'clean-logs': def update(self):
logs = CleanLogsDependencies(self.flags) if len(self.args) == 1:
logs.clean() update = UpdateRepository()
raise SystemExit() update.sbo()
raise SystemExit()
usage(1)
# Update repository def build(self):
if self.args[0] == 'update': if len(self.args) >= 2 and '--reinstall' not in self.flags:
update = UpdateRepository() packages = list(set(self.args[1:]))
update.sbo()
raise SystemExit()
self.check.exists(packages)
self.check.unsupported(packages)
build = Slackbuilds(packages, self.flags, False)
build.execute()
raise SystemExit()
usage(1)
def install(self):
if len(self.args) >= 2:
packages = list(set(self.args[1:]))
self.check.exists(packages)
self.check.unsupported(packages)
install = Slackbuilds(packages, self.flags, True)
install.execute()
raise SystemExit()
usage(1)
def remove(self):
if [f for f in self.flags if f in self.options[1:]]:
usage(1) usage(1)
if len(self.args) >= 2: if len(self.args) >= 2:
# Build slackbuilds packages = list(set(self.args[1:]))
if self.args[0] == 'build': packages = self.check.blacklist(packages)
packages = list(set(self.args[1:]))
check.exists(packages) self.check.installed(packages)
check.unsupported(packages)
build = Slackbuilds(packages, self.flags, False) remove = RemovePackages(packages, self.flags)
build.execute() remove.remove()
raise SystemExit() raise SystemExit()
usage(1)
# Install packages
if self.args[0] == 'install':
packages = list(set(self.args[1:]))
check.exists(packages)
check.unsupported(packages)
install = Slackbuilds(packages, self.flags, True)
install.execute()
raise SystemExit()
# Remove packages
if self.args[0] == 'remove':
packages = list(set(self.args[1:]))
packages = check.blacklist(packages)
check.installed(packages)
remove = RemovePackages(packages, self.flags)
remove.remove()
raise SystemExit()
# Search package
if self.args[0] == 'search':
packages = list(set(self.args[1:]))
packages = check.blacklist(packages)
check.exists(packages)
search = Search()
search.package(packages)
raise SystemExit()
def search(self):
if [f for f in self.flags if f in self.options]:
usage(1) usage(1)
if len(self.args) >= 2:
packages = list(set(self.args[1:]))
packages = self.check.blacklist(packages)
self.check.exists(packages)
search = Search()
search.package(packages)
raise SystemExit()
usage(1)
def find(self):
if [f for f in self.flags if f in self.options]:
usage(1)
if len(self.args) >= 2:
packages = list(set(self.args[1:]))
packages = self.check.blacklist(packages)
find = FindInstalled()
find.find(packages)
raise SystemExit()
usage(1)
def clean_logs(self):
if len(self.args) == 1:
logs = CleanLogsDependencies(self.flags)
logs.clean()
raise SystemExit()
usage(1)
def clean_tmp(self):
if len(self.args) == 1:
path = Configs.tmp_path
tmp_slpkg = Configs.tmp_slpkg
folder = Configs.prog_name
utils = Utilities()
utils.remove_folder_if_exists(path, folder)
utils.create_folder(tmp_slpkg, 'build')
raise SystemExit()
usage(1)
def main(): def main():
args = sys.argv args = sys.argv
args.pop(0) args.pop(0)
argparse = Argparse(args) argparse = Argparse(args)
argparse.command()
arguments = {
'-h': argparse.help,
'--help': argparse.help,
'-v': argparse.version,
'--version': argparse.version,
'update': argparse.update,
'build': argparse.build,
'install': argparse.install,
'remove': argparse.remove,
'search': argparse.search,
'find': argparse.find,
'clean-logs': argparse.clean_logs,
'clean-tmp': argparse.clean_tmp
}
try:
arguments[args[0]]()
except KeyError:
usage(1)
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -30,7 +30,7 @@ class SBoQueries:
SBoTable.name).filter(SBoTable.name == self.name).first() SBoTable.name).filter(SBoTable.name == self.name).first()
if sbo: if sbo:
return sbo return sbo[0]
return '' return ''
def location(self): def location(self):

View file

@ -12,7 +12,7 @@ from slpkg.models.models import session as Session
@dataclass @dataclass
class Search: class Search:
session: str = Session session: str = Session
colors: list = Configs.colour colors: dict = Configs.colour
sbo_url: str = Configs.sbo_url sbo_url: str = Configs.sbo_url
def package(self, packages): def package(self, packages):

View file

@ -2,7 +2,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os import os
import shutil
import subprocess import subprocess
import multiprocessing import multiprocessing
@ -85,8 +84,7 @@ class Slackbuilds:
def creating_main_for_build(self): def creating_main_for_build(self):
''' List with the main slackbuilds. ''' ''' List with the main slackbuilds. '''
for main in self.sbos.keys(): [self.install_order.append(main) for main in self.sbos.keys()]
self.install_order.append(main)
def download_slackbuilds_and_build(self): def download_slackbuilds_and_build(self):
''' Downloads files and sources and starting the build. ''' ''' Downloads files and sources and starting the build. '''
@ -95,8 +93,8 @@ class Slackbuilds:
for sbo in self.install_order: for sbo in self.install_order:
file = f'{sbo}{self.tar_suffix}' file = f'{sbo}{self.tar_suffix}'
self.remove_file_if_exists(self.tmp_slpkg, file) self.utils.remove_file_if_exists(self.tmp_slpkg, file)
self.remove_folder_if_exists(self.build_path, sbo) self.utils.remove_folder_if_exists(self.build_path, sbo)
location = SBoQueries(sbo).location() location = SBoQueries(sbo).location()
url = f'{self.sbo_url}/{location}/{file}' url = f'{self.sbo_url}/{location}/{file}'
@ -183,15 +181,3 @@ class Slackbuilds:
wget.download(path, source) wget.download(path, source)
md5sum = Md5sum(self.flags) md5sum = Md5sum(self.flags)
md5sum.check(source, checksum, name) md5sum.check(source, checksum, name)
def remove_file_if_exists(self, path: str, file: str):
''' Clean the the old files. '''
archive = f'{path}/{file}'
if os.path.isfile(archive):
os.remove(archive)
def remove_folder_if_exists(self, path: str, folder: str):
''' Clean the the old folders. '''
directory = f'{path}/{folder}'
if os.path.isdir(directory):
shutil.rmtree(directory)

View file

@ -4,6 +4,7 @@
import os import os
import re import re
import shutil
import tarfile import tarfile
from dataclasses import dataclass from dataclasses import dataclass
@ -39,4 +40,22 @@ class Utilities:
''' Returns True if a package is installed. ''' ''' Returns True if a package is installed. '''
for pkg in os.listdir(self.log_packages): for pkg in os.listdir(self.log_packages):
if package in pkg: if package in pkg:
return True return pkg
def remove_file_if_exists(self, path: str, file: str):
''' Clean the the old files. '''
archive = f'{path}/{file}'
if os.path.isfile(archive):
os.remove(archive)
def remove_folder_if_exists(self, path: str, folder: str):
''' Clean the the old folders. '''
directory = f'{path}/{folder}'
if os.path.isdir(directory):
shutil.rmtree(directory)
def create_folder(self, path: str, folder: str):
''' Creates folder. '''
directory = f'{path}/{folder}'
if not os.path.isdir(directory):
os.makedirs(directory)

View file

@ -10,7 +10,7 @@ from slpkg.configs import Configs
@dataclass @dataclass
class Version: class Version:
prog_name: str = Configs.prog_name prog_name: str = Configs.prog_name
version_info: tuple = (4, 1, 0) version_info: tuple = (4, 1, 1)
version: str = '{0}.{1}.{2}'.format(*version_info) version: str = '{0}.{1}.{2}'.format(*version_info)
license: str = 'MIT License' license: str = 'MIT License'
author: str = 'dslackw' author: str = 'dslackw'

View file

@ -6,21 +6,34 @@ from slpkg.configs import Configs
def usage(status: int): def usage(status: int):
args = [f'Usage: {Configs.prog_name} [OPTIONS] [packages]\n', colors = Configs.colour
color = colors()
BOLD = color['BOLD']
RED = color['RED']
CYAN = color['CYAN']
YELLOW = color['YELLOW']
ENDC = color['ENDC']
args = [f'{BOLD}USAGE:{ENDC} {Configs.prog_name} [{YELLOW}OPTIONS{ENDC}] [{CYAN}COMMAND{ENDC}] <packages>\n',
f'{BOLD}DESCRIPTION:{ENDC}',
' Packaging tool that interacts with the SBo repository.\n', ' Packaging tool that interacts with the SBo repository.\n',
'Options:', f'{BOLD}COMMANDS:{ENDC}',
' update Update the package lists.', f' {RED}update{ENDC} Update the package lists.',
' build Build only the packages.', f' {CYAN}build{ENDC} <packages> Build only the packages.',
' install Build and install the packages.', f' {CYAN}install{ENDC} <packages> Build and install the packages.',
' remove Remove installed packages.', f' {CYAN}remove{ENDC} <packages> Remove installed packages.',
' search Search packages by name.', f' {CYAN}find{ENDC} <packages> Find installed packages.',
' clean-logs Purge logs of dependencies.\n', f' {CYAN}search{ENDC} <packages> Search packages on repository.',
' --yes Answer Yes to all questions.', f' {CYAN}clean-logs{ENDC} Clean dependencies log tracking.',
' --jobs Set it for multicore systems.', f' {CYAN}clean-tmp{ENDC} Delete all the downloaded sources.\n',
' --resolve-off Turns off dependency resolving.', f'{BOLD}OPTIONS:{ENDC}',
' --reinstall Use this option if you want to upgrade.\n', f' {YELLOW}--yes{ENDC} Answer Yes to all questions.',
' -h, --help Show this message and exit.', f' {YELLOW}--jobs{ENDC} Set it for multicore systems.',
' -v, --version Print version and exit.\n', f' {YELLOW}--resolve-off{ENDC} Turns off dependency resolving.',
f' {YELLOW}--reinstall{ENDC} Use this option if you want to upgrade.\n',
' -h, --help Show this message and exit.',
' -v, --version Print version and exit.\n',
'If you need more information try to use slpkg manpage.'] 'If you need more information try to use slpkg manpage.']
for opt in args: for opt in args:

View file

@ -15,9 +15,10 @@ from slpkg.models.models import session as Session
@dataclass @dataclass
class ViewMessage: class ViewMessage:
flags: list flags: list
colors: str = Configs.colour colors: dict = Configs.colour
log_packages: str = Configs.log_packages log_packages: str = Configs.log_packages
repo_tag: str = Configs.repo_tag repo_tag: str = Configs.repo_tag
arch: str = Configs.os_arch
session: str = Session session: str = Session
utils: str = Utilities() utils: str = Utilities()
black: list = Blacklist() black: list = Blacklist()
@ -78,7 +79,7 @@ class ViewMessage:
def _view_build(self, sbo: str, version: str): def _view_build(self, sbo: str, version: str):
color = self.colors() color = self.colors()
if self.utils.is_installed(f'{sbo}-{version}-'): if self.utils.is_installed(f'{sbo}-'):
print(f'[{color["YELLOW"]} build {color["ENDC"]}] -> ' print(f'[{color["YELLOW"]} build {color["ENDC"]}] -> '
f'{sbo}-{version}') f'{sbo}-{version}')
else: else:
@ -88,13 +89,17 @@ class ViewMessage:
def _view_install(self, sbo: str, version: str): def _view_install(self, sbo: str, version: str):
color = self.colors() color = self.colors()
installed = self.utils.is_installed(f'{sbo}-')
install, set_color = 'install', color['RED'] install, set_color = 'install', color['RED']
if '--reinstall' in self.flags: if '--reinstall' in self.flags:
install, set_color = 'upgrade', color['YELLOW'] install, set_color = 'upgrade', color['YELLOW']
if self.utils.is_installed(f'{sbo}-{version}-'): if installed:
print(f'[{set_color} {install} {color["ENDC"]}] -> ' print(f'[{set_color} {install} {color["ENDC"]}] -> '
f'{sbo}-{version}') f'{sbo}-{version} {set_color}'
f'({installed.split(self.arch)[0][:-1].split("-")[-1]})'
f'{color["ENDC"]}')
else: else:
print(f'[{color["CYAN"]} install {color["ENDC"]}] -> ' print(f'[{color["CYAN"]} install {color["ENDC"]}] -> '
f'{sbo}-{version}') f'{sbo}-{version}')
@ -118,8 +123,7 @@ class ViewMessage:
installed = upgraded = 0 installed = upgraded = 0
for sbo in slackbuilds: for sbo in slackbuilds:
version = SBoQueries(sbo).version() if self.utils.is_installed(f'{sbo}-'):
if self.utils.is_installed(f'{sbo}-{version}-'):
upgraded += 1 upgraded += 1
else: else:
installed += 1 installed += 1

13
tests/test_blacklist.py Normal file
View file

@ -0,0 +1,13 @@
import unittest
from slpkg.blacklist import Blacklist
class TestBlacklist(unittest.TestCase):
def test_blacklist(self):
black = Blacklist()
self.assertListEqual([], black.get())
if __name__ == '__main__':
unittest.main()

26
tests/test_checks.py Normal file
View file

@ -0,0 +1,26 @@
import unittest
from slpkg.checks import Check
class TestPkgInstalled(unittest.TestCase):
def setUp(self):
self.check = Check()
self.packages = ['Flask', 'colored', 'slpkg']
def test_check_exists(self):
self.assertIsNone(self.check.exists(self.packages))
def tect_check_unsupported(self):
self.assertIsNone(self.check.unsupported(self.packages))
def test_check_installed(self):
self.assertIsNone(self.check.installed(self.packages))
def test_check_blacklist(self):
self.assertListEqual(self.packages,
self.check.blacklist(self.packages))
if __name__ == "__main__":
unittest.main()

21
tests/test_colors.py Normal file
View file

@ -0,0 +1,21 @@
import unittest
from slpkg.configs import Configs
class TestColors(unittest.TestCase):
def setUp(self):
colors = Configs.colour
self.color = colors()
def test_colors(self):
self.assertIn('BOLD', self.color)
self.assertIn('RED', self.color)
self.assertIn('YELLOW', self.color)
self.assertIn('GREEN', self.color)
self.assertIn('BLUE', self.color)
self.assertIn('GREY', self.color)
if __name__ == '__main__':
unittest.main()

35
tests/test_configs.py Normal file
View file

@ -0,0 +1,35 @@
import unittest
from slpkg.configs import Configs
class TestConfigs(unittest.TestCase):
def setUp(self):
self.repo_version = Configs.repo_version
self.sbo_txt = Configs.sbo_txt
self.tar_suffix = Configs.tar_suffix
self.pkg_suffix = Configs.pkg_suffix
self.repo_tag = Configs.repo_tag
self.os_arch = Configs.os_arch
def test_repo_version(self):
self.assertEqual('15.0', self.repo_version)
def test_sbo_txt(self):
self.assertEqual('SLACKBUILDS.TXT', self.sbo_txt)
def test_tar_suffix(self):
self.assertEqual('.tar.gz', self.tar_suffix)
def test_pkg_suffix(self):
self.assertEqual('.tgz', self.pkg_suffix)
def test_repo_tag(self):
self.assertEqual('_SBo', self.repo_tag)
def test_os_arch(self):
self.assertEqual('x86_64', self.os_arch)
if __name__ == '__main__':
unittest.main()

42
tests/test_queries.py Normal file
View file

@ -0,0 +1,42 @@
import unittest
from slpkg.queries import SBoQueries
class TestSBoQueries(unittest.TestCase):
def setUp(self):
self.query = SBoQueries('slpkg')
def test_slackbuild(self):
self.assertEqual('slpkg', self.query.slackbuild())
def test_location(self):
self.assertEqual('system', self.query.location())
def test_sources(self):
self.assertEqual('https://gitlab.com/dslackw/slpkg/-/archive'
'/3.9.8/slpkg-3.9.8.tar.gz', self.query.sources())
def test_requires(self):
self.assertEqual([], self.query.requires())
def test_version(self):
self.assertEqual('3.9.8', self.query.version())
def test_checksum(self):
self.assertListEqual(['41b3f4f0f8fb8270e3b03abd2c73be2c'],
self.query.checksum())
def test_files(self):
self.assertEqual(5, len(self.query.files().split()))
def test_description(self):
self.assertEqual('slpkg (Slackware Packaging Tool)',
self.query.description())
def test_names(self):
self.assertIn('slpkg', self.query.names())
if __name__ == '__main__':
unittest.main()

21
tests/test_utilities.py Normal file
View file

@ -0,0 +1,21 @@
import unittest
from slpkg.utilities import Utilities
from slpkg.configs import Configs
class TestUtilities(unittest.TestCase):
def setUp(self):
self.utils = Utilities()
self.build_path = Configs.build_path
def test_build_tag(self):
self.assertEqual(['2'], self.utils.build_tag(self.build_path,
'fish'))
def test_ins_installed(self):
self.assertEqual(True, self.utils.is_installed('fish-3.4.0'))
if __name__ == '__main__':
unittest.main()