diff --git a/ChangeLog.txt b/ChangeLog.txt
index b0ceecf9..023dff0f 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -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
diff --git a/README.rst b/README.rst
index ce30645c..ef1b682d 100644
--- a/README.rst
+++ b/README.rst
@@ -4,7 +4,7 @@
About
-----
-Slpkg is a software package manager that installs, updates and removes packages on `Slackware `_ -based systems.
+Slpkg is a software package manager that installs, updates and removes packages on `Slackware `_-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
+ USAGE: slpkg [OPTIONS] [COMMAND]
+ 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 Build only the packages.
+ install Build and install the packages.
+ remove Remove installed packages.
+ find Find installed packages.
+ search 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
diff --git a/configs/blacklist.json b/configs/blacklist.json
deleted file mode 100644
index 550bdb9c..00000000
--- a/configs/blacklist.json
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "blacklist": []
-}
\ No newline at end of file
diff --git a/configs/blacklist.yaml b/configs/blacklist.yaml
new file mode 100644
index 00000000..348c014f
--- /dev/null
+++ b/configs/blacklist.yaml
@@ -0,0 +1,2 @@
+blacklist:
+ packages: []
diff --git a/configs/slpkg.json b/configs/slpkg.json
deleted file mode 100644
index 438d5512..00000000
--- a/configs/slpkg.json
+++ /dev/null
@@ -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"
-}
diff --git a/configs/slpkg.yaml b/configs/slpkg.yaml
new file mode 100644
index 00000000..7adcb108
--- /dev/null
+++ b/configs/slpkg.yaml
@@ -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
diff --git a/man/slpkg.1 b/man/slpkg.1
index 7c9e2b04..ee5b10de 100644
--- a/man/slpkg.1
+++ b/man/slpkg.1
@@ -1,16 +1,16 @@
.TH slpkg 1 "Orestiada, Greece" "slpkg 4.1.0" dslackw
.SH NAME
.P
-slpkg - [OPTIONS]
+slpkg - [OPTIONS] [COMMAND]
.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.
diff --git a/requirements.txt b/requirements.txt
index e6e2854c..5db7bd95 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,2 +1,3 @@
SQLAlchemy>=1.4.36
+PyYAML>=6.0
diff --git a/setup.py b/setup.py
index 14e97407..66a0c2c1 100755
--- a/setup.py
+++ b/setup.py
@@ -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', [])],
diff --git a/slackbuild/doinst.sh b/slackbuild/doinst.sh
index 01508eeb..c07a4c6f 100644
--- a/slackbuild/doinst.sh
+++ b/slackbuild/doinst.sh
@@ -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
diff --git a/slackbuild/slpkg.SlackBuild b/slackbuild/slpkg.SlackBuild
index 57bc21fd..2a5e3dbb 100755
--- a/slackbuild/slpkg.SlackBuild
+++ b/slackbuild/slpkg.SlackBuild
@@ -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
diff --git a/slpkg/blacklist.py b/slpkg/blacklist.py
index 3b9f3cfb..3f950fb2 100644
--- a/slpkg/blacklist.py
+++ b/slpkg/blacklist.py
@@ -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']
diff --git a/slpkg/configs.py b/slpkg/configs.py
index b5e62840..3cffa743 100644
--- a/slpkg/configs.py
+++ b/slpkg/configs.py
@@ -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',
diff --git a/slpkg/find_installed.py b/slpkg/find_installed.py
new file mode 100644
index 00000000..7e41e345
--- /dev/null
+++ b/slpkg/find_installed.py
@@ -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')
diff --git a/slpkg/main.py b/slpkg/main.py
index b926416b..5704aa7e 100644
--- a/slpkg/main.py
+++ b/slpkg/main.py
@@ -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__':
diff --git a/slpkg/queries.py b/slpkg/queries.py
index d78d88ee..f6b24c4b 100644
--- a/slpkg/queries.py
+++ b/slpkg/queries.py
@@ -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):
diff --git a/slpkg/search.py b/slpkg/search.py
index c0c760f2..048bbc87 100644
--- a/slpkg/search.py
+++ b/slpkg/search.py
@@ -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):
diff --git a/slpkg/slackbuild.py b/slpkg/slackbuild.py
index 983d9b59..25e56fc5 100644
--- a/slpkg/slackbuild.py
+++ b/slpkg/slackbuild.py
@@ -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)
diff --git a/slpkg/utilities.py b/slpkg/utilities.py
index 6b1d70ab..ef8bcbea 100644
--- a/slpkg/utilities.py
+++ b/slpkg/utilities.py
@@ -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)
diff --git a/slpkg/version.py b/slpkg/version.py
index a7067ebf..36d5f15e 100644
--- a/slpkg/version.py
+++ b/slpkg/version.py
@@ -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'
diff --git a/slpkg/views/cli_menu.py b/slpkg/views/cli_menu.py
index 083901f6..3db226b9 100644
--- a/slpkg/views/cli_menu.py
+++ b/slpkg/views/cli_menu.py
@@ -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}] \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} Build only the packages.',
+ f' {CYAN}install{ENDC} Build and install the packages.',
+ f' {CYAN}remove{ENDC} Remove installed packages.',
+ f' {CYAN}find{ENDC} Find installed packages.',
+ f' {CYAN}search{ENDC} 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:
diff --git a/slpkg/views/views.py b/slpkg/views/views.py
index 6e303db4..f2bfb6d4 100644
--- a/slpkg/views/views.py
+++ b/slpkg/views/views.py
@@ -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
diff --git a/tests/test_blacklist.py b/tests/test_blacklist.py
new file mode 100644
index 00000000..81a50cde
--- /dev/null
+++ b/tests/test_blacklist.py
@@ -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()
diff --git a/tests/test_checks.py b/tests/test_checks.py
new file mode 100644
index 00000000..76402be5
--- /dev/null
+++ b/tests/test_checks.py
@@ -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()
diff --git a/tests/test_colors.py b/tests/test_colors.py
new file mode 100644
index 00000000..235b0e24
--- /dev/null
+++ b/tests/test_colors.py
@@ -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()
diff --git a/tests/test_configs.py b/tests/test_configs.py
new file mode 100644
index 00000000..51aa9c00
--- /dev/null
+++ b/tests/test_configs.py
@@ -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()
diff --git a/tests/test_queries.py b/tests/test_queries.py
new file mode 100644
index 00000000..fe4a2180
--- /dev/null
+++ b/tests/test_queries.py
@@ -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()
diff --git a/tests/test_utilities.py b/tests/test_utilities.py
new file mode 100644
index 00000000..44a27c37
--- /dev/null
+++ b/tests/test_utilities.py
@@ -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()