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
Updated:
- slpkg code re-written from the beginning and currently supports only the SBo repository

View file

@ -4,7 +4,7 @@
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.
Slpkg makes it easier to manage groups of machines without the need for manual updates.
@ -21,6 +21,7 @@ Requirements
.. code-block:: bash
SQLAlchemy>=1.4.36
PyYAML>=6.0
Install
-------
@ -29,8 +30,8 @@ Install from the official third-party `SBo repository <https://slackbuilds.org/r
.. code-block:: bash
$ tar xvf slpkg-4.1.0.tar.gz
$ cd slpkg-4.1.0
$ tar xvf slpkg-4.1.1.tar.gz
$ cd slpkg-4.1.1
$ ./install.sh
@ -41,25 +42,31 @@ Usage
$ slpkg --help
Usage: slpkg [OPTIONS] <packages>
USAGE: slpkg [OPTIONS] [COMMAND] <packages>
DESCRIPTION:
Packaging tool that interacts with the SBo repository.
Options:
update Update the package lists.
build Build only the packages.
install Build and install the packages.
remove Remove installed packages.
search Search packages by name.
clean-logs Purge logs of dependencies.
COMMANDS:
update Update the package lists.
build <packages> Build only the packages.
install <packages> Build and install the packages.
remove <packages> Remove installed packages.
find <packages> Find installed packages.
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.
--jobs Set it for multicore systems.
--resolve-off Turns off dependency resolving.
--reinstall Use this option if you want to upgrade.
OPTIONS:
--yes Answer Yes to all questions.
--jobs Set it for multicore systems.
--resolve-off Turns off dependency resolving.
--reinstall Use this option if you want to upgrade.
-h, --help Show this message and exit.
-v, --version Print version and exit.
-h, --help Show this message and exit.
-v, --version Print version and exit.
If you need more information try to use slpkg manpage.
Configuration files
@ -67,10 +74,10 @@ Configuration files
.. code-block:: bash
/etc/slpkg/slpkg.json
/etc/slpkg/slpkg.yaml
General configuration of slpkg
/etc/slpkg/blacklist.json
/etc/slpkg/blacklist.yaml
Blacklist of packages
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
.SH NAME
.P
slpkg - [OPTIONS] <packages>
slpkg - [OPTIONS] [COMMAND] <packages>
.SH SYNAPSES
.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
.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.
.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.
.SH OPTIONS
.SH COMMANDS
.P
update
.RS
@ -32,16 +32,27 @@ remove
Removes packages with dependencies if the packages was installed with slpkg install method.
.RE
.P
find
.RS
Find sbo installed packages on your distribution.
.RE
.P
search
.RS
Search packages by name and view everything in your terminal.
Search packages on repository and view everything in your terminal.
.RE
.P
clean-logs
.RS
Purge logs of dependencies.
Cleans dependencies log tracking.
.RE
.P
clean-tmp
.RS
Deletes all the downloaded sources.
.RE
.SH OPTIONS
.P
--yes
.RS
Answer Yes to all questions.
@ -74,9 +85,9 @@ Print version and exit.
.RE
.SH CONFIGURATION FILES
.P
Configuration file in the /etc/slpkg/slpkg.json file.
Configuration file in the /etc/slpkg/slpkg.yaml file.
.RE
Blacklist file in the /etc/slpkg/blacklist.json file.
Blacklist file in the /etc/slpkg/blacklist.yaml file.
.SH REPORT BUGS
.P
Please report any found to https://gitlab.com/dslackw/slpkg/-/issues.

View file

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

View file

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

View file

@ -8,8 +8,8 @@ config() {
fi
}
config etc/slpkg/slpkg.json.new
config etc/slpkg/blacklist.json.new
config etc/slpkg/slpkg.yaml.new
config etc/slpkg/blacklist.yaml.new
if [ -x /usr/bin/update-desktop-database ]; then
/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
mkdir -p $PKG/etc/slpkg
install -D -m0644 configs/slpkg.json $PKG/etc/slpkg/slpkg.json.new
install -D -m0644 configs/blacklist.json $PKG/etc/slpkg/blacklist.json.new
install -D -m0644 configs/slpkg.yaml $PKG/etc/slpkg/slpkg.yaml.new
install -D -m0644 configs/blacklist.yaml $PKG/etc/slpkg/blacklist.yaml.new
mkdir -p $PKG/usr/man/man1
cp man/slpkg.1 $PKG/usr/man/man1

View file

@ -3,7 +3,7 @@
import os
import json
import yaml
from dataclasses import dataclass
from slpkg.configs import Configs
@ -15,7 +15,7 @@ class Blacklist:
etc_path: str = Configs.etc_path
def get(self):
file = f'{self.etc_path}/blacklist.json'
file = f'{self.etc_path}/blacklist.yaml'
if os.path.isfile(file):
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 json
import yaml
from dataclasses import dataclass
@ -49,11 +49,12 @@ class Configs:
wget_options = '-c -N'
''' 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):
with open(config_file, 'r') as conf:
config = json.load(conf)
configs = yaml.safe_load(conf)
config = configs['configs']
# OS architecture by default
os_arch: str = config['os_arch']
@ -91,6 +92,7 @@ class Configs:
@classmethod
def colour(cls):
color = {
'BOLD': '',
'RED': '',
'GREEN': '',
'YELLOW': '',
@ -100,8 +102,9 @@ class Configs:
'ENDC': ''
}
if cls.colors in ['on', 'ON']:
if cls.colors:
color = {
'BOLD': '\033[1m',
'RED': '\x1b[91m',
'GREEN': '\x1b[32m',
'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.search import Search
from slpkg.version import Version
from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.views.cli_menu import usage
from slpkg.slackbuild import Slackbuilds
from slpkg.find_installed import FindInstalled
from slpkg.remove_packages import RemovePackages
from slpkg.clean_logs import CleanLogsDependencies
from slpkg.update_repository import UpdateRepository
@ -19,114 +22,157 @@ from slpkg.update_repository import UpdateRepository
class Argparse:
args: list
def flags(self):
self.flags = []
yes = '--yes'
jobs = '--jobs'
resolve_off = '--resolve-off'
reinstall = '--reinstall'
def __post_init__(self):
self.flag()
self.check = Check()
if yes in self.args:
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:
if len(self.args) == 0:
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 self.args[0] in ['--help', '-h']:
usage(0)
usage(0)
usage(1)
if self.args[0] in ['--version', '-v']:
version = Version()
version.view()
raise SystemExit()
def version(self):
if len(self.args) == 1:
version = Version()
version.view()
raise SystemExit()
usage(1)
if self.args[0] == 'clean-logs':
logs = CleanLogsDependencies(self.flags)
logs.clean()
raise SystemExit()
def update(self):
if len(self.args) == 1:
update = UpdateRepository()
update.sbo()
raise SystemExit()
usage(1)
# Update repository
if self.args[0] == 'update':
update = UpdateRepository()
update.sbo()
raise SystemExit()
def build(self):
if len(self.args) >= 2 and '--reinstall' not in self.flags:
packages = list(set(self.args[1:]))
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)
if len(self.args) >= 2:
# Build slackbuilds
if self.args[0] == 'build':
packages = list(set(self.args[1:]))
packages = list(set(self.args[1:]))
packages = self.check.blacklist(packages)
check.exists(packages)
check.unsupported(packages)
self.check.installed(packages)
build = Slackbuilds(packages, self.flags, False)
build.execute()
raise SystemExit()
# 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()
remove = RemovePackages(packages, self.flags)
remove.remove()
raise SystemExit()
usage(1)
def search(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)
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():
args = sys.argv
args.pop(0)
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__':

View file

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

View file

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

View file

@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
import os
import shutil
import subprocess
import multiprocessing
@ -85,8 +84,7 @@ class Slackbuilds:
def creating_main_for_build(self):
''' List with the main slackbuilds. '''
for main in self.sbos.keys():
self.install_order.append(main)
[self.install_order.append(main) for main in self.sbos.keys()]
def download_slackbuilds_and_build(self):
''' Downloads files and sources and starting the build. '''
@ -95,8 +93,8 @@ class Slackbuilds:
for sbo in self.install_order:
file = f'{sbo}{self.tar_suffix}'
self.remove_file_if_exists(self.tmp_slpkg, file)
self.remove_folder_if_exists(self.build_path, sbo)
self.utils.remove_file_if_exists(self.tmp_slpkg, file)
self.utils.remove_folder_if_exists(self.build_path, sbo)
location = SBoQueries(sbo).location()
url = f'{self.sbo_url}/{location}/{file}'
@ -183,15 +181,3 @@ class Slackbuilds:
wget.download(path, source)
md5sum = Md5sum(self.flags)
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 re
import shutil
import tarfile
from dataclasses import dataclass
@ -39,4 +40,22 @@ class Utilities:
''' Returns True if a package is installed. '''
for pkg in os.listdir(self.log_packages):
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
class Version:
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)
license: str = 'MIT License'
author: str = 'dslackw'

View file

@ -6,21 +6,34 @@ from slpkg.configs import Configs
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',
'Options:',
' update Update the package lists.',
' build Build only the packages.',
' install Build and install the packages.',
' remove Remove installed packages.',
' search Search packages by name.',
' clean-logs Purge logs of dependencies.\n',
' --yes Answer Yes to all questions.',
' --jobs Set it for multicore systems.',
' --resolve-off Turns off dependency resolving.',
' --reinstall Use this option if you want to upgrade.\n',
' -h, --help Show this message and exit.',
' -v, --version Print version and exit.\n',
f'{BOLD}COMMANDS:{ENDC}',
f' {RED}update{ENDC} Update the package lists.',
f' {CYAN}build{ENDC} <packages> Build only the packages.',
f' {CYAN}install{ENDC} <packages> Build and install the packages.',
f' {CYAN}remove{ENDC} <packages> Remove installed packages.',
f' {CYAN}find{ENDC} <packages> Find installed packages.',
f' {CYAN}search{ENDC} <packages> Search packages on repository.',
f' {CYAN}clean-logs{ENDC} Clean dependencies log tracking.',
f' {CYAN}clean-tmp{ENDC} Delete all the downloaded sources.\n',
f'{BOLD}OPTIONS:{ENDC}',
f' {YELLOW}--yes{ENDC} Answer Yes to all questions.',
f' {YELLOW}--jobs{ENDC} Set it for multicore systems.',
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.']
for opt in args:

View file

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