From 7c3069983b48db5869e6638e35ecfc45e9b5e52e Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Mon, 20 Jun 2022 23:14:46 +0300 Subject: [PATCH 01/30] Fixed typo --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index ce30645c..dbc8beb5 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. From 9ca9d286337999569408255abeb72e6f00ef8647 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Tue, 21 Jun 2022 00:52:24 +0300 Subject: [PATCH 02/30] Update cli menu view --- ChangeLog.txt | 4 ++++ README.rst | 32 +++++++++++++++++--------------- slpkg/views/cli_menu.py | 36 ++++++++++++++++++++++-------------- 3 files changed, 43 insertions(+), 29 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index b0ceecf9..7fd27e2d 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,3 +1,7 @@ +4.1.1 - 21/06/2022 +Updated: +- Cli menu view with colors + 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 dbc8beb5..d3253036 100644 --- a/README.rst +++ b/README.rst @@ -41,25 +41,27 @@ Usage $ slpkg --help - Usage: slpkg [OPTIONS] + USAGE: slpkg [OPTIONS] - Packaging tool that interacts with the SBo repository. + 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. + 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. - --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. + --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 diff --git a/slpkg/views/cli_menu.py b/slpkg/views/cli_menu.py index 083901f6..87daa478 100644 --- a/slpkg/views/cli_menu.py +++ b/slpkg/views/cli_menu.py @@ -6,21 +6,29 @@ from slpkg.configs import Configs def usage(status: int): - args = [f'Usage: {Configs.prog_name} [OPTIONS] [packages]\n', + colors = Configs.colour + color = colors() + + RED = color['RED'] + CYAN = color['CYAN'] + YELLOW = color['YELLOW'] + ENDC = color['ENDC'] + + args = [f'USAGE: {Configs.prog_name} [{CYAN}OPTIONS{ENDC}] \n', ' 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', + 'OPTIONS:', + 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}search{ENDC} Search packages by name.', + f' {CYAN}clean-logs{ENDC} Purge logs of dependencies.\n', + 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: From fe44576d96fb211c841817bb717d1d4c7118701e Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Tue, 21 Jun 2022 09:35:35 +0300 Subject: [PATCH 03/30] Update cli menu view --- README.rst | 30 ++++++++++++++++-------------- man/slpkg.1 | 3 ++- slpkg/configs.py | 1 + slpkg/views/cli_menu.py | 7 +++++-- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/README.rst b/README.rst index d3253036..281bce06 100644 --- a/README.rst +++ b/README.rst @@ -43,23 +43,25 @@ Usage USAGE: slpkg [OPTIONS] - Packaging tool that interacts with the SBo repository. + DESCRIPTION: + Packaging tool that interacts with the SBo repository. + + COMMANDS: + 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. 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. + --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. - --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. diff --git a/man/slpkg.1 b/man/slpkg.1 index 7c9e2b04..3f26d72d 100644 --- a/man/slpkg.1 +++ b/man/slpkg.1 @@ -10,7 +10,7 @@ slpkg [-h|-v] [update] [build] [install] [remove] [search] [clean-logs] --yes -- 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 @@ -41,6 +41,7 @@ clean-logs .RS Purge logs of dependencies. .RE +.SH OPTIONS .P --yes .RS diff --git a/slpkg/configs.py b/slpkg/configs.py index b5e62840..6e53cee9 100644 --- a/slpkg/configs.py +++ b/slpkg/configs.py @@ -102,6 +102,7 @@ class Configs: if cls.colors in ['on', 'ON']: color = { + 'BOLD': '\033[1m', 'RED': '\x1b[91m', 'GREEN': '\x1b[32m', 'YELLOW': '\x1b[93m', diff --git a/slpkg/views/cli_menu.py b/slpkg/views/cli_menu.py index 87daa478..4456178f 100644 --- a/slpkg/views/cli_menu.py +++ b/slpkg/views/cli_menu.py @@ -9,20 +9,23 @@ def usage(status: int): colors = Configs.colour color = colors() + BOLD = color['BOLD'] RED = color['RED'] CYAN = color['CYAN'] YELLOW = color['YELLOW'] ENDC = color['ENDC'] - args = [f'USAGE: {Configs.prog_name} [{CYAN}OPTIONS{ENDC}] \n', + args = [f'{BOLD}USAGE:{ENDC} {Configs.prog_name} [{CYAN}OPTIONS{ENDC}] \n', + f'{BOLD}DESCRIPTION:{ENDC}', ' Packaging tool that interacts with the SBo repository.\n', - 'OPTIONS:', + 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}search{ENDC} Search packages by name.', f' {CYAN}clean-logs{ENDC} Purge logs of dependencies.\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.', From 104bba298a2cffab95d580bff948bf1a32657535 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Tue, 21 Jun 2022 09:53:26 +0300 Subject: [PATCH 04/30] Updated for version 4.1.1 --- slpkg/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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' From 9556d73258b60ea3504619bc635a645ad4cb95b5 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Tue, 21 Jun 2022 18:40:06 +0300 Subject: [PATCH 05/30] Added tests --- tests/test_blacklist.py | 13 +++++++++++++ tests/test_checks.py | 26 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/test_blacklist.py create mode 100644 tests/test_checks.py 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() From c3c6396770c266a0ea3ee3acc3df0cee3f69b7fa Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Tue, 21 Jun 2022 19:00:05 +0300 Subject: [PATCH 06/30] Added tests --- tests/test_colors.py | 21 +++++++++++++++++++++ tests/test_configs.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tests/test_colors.py create mode 100644 tests/test_configs.py 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() From a5ebc25d37140b8c1b1fffd2c428f29b452edb93 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Tue, 21 Jun 2022 20:44:49 +0300 Subject: [PATCH 07/30] Fixed returns --- slpkg/queries.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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): From 1016d799f1542f63106d39fe97385cd5c9a8f774 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Tue, 21 Jun 2022 20:46:20 +0300 Subject: [PATCH 08/30] Added queries and utils tests --- tests/test_queries.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tests/test_queries.py 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() From 62c358ae8a57beea0256bd0c4653fde29dcaa414 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Tue, 21 Jun 2022 21:07:06 +0300 Subject: [PATCH 09/30] Updated changelog --- ChangeLog.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 7fd27e2d..435d4110 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,8 @@ 4.1.1 - 21/06/2022 Updated: - Cli menu view with colors +Added: +- Unittests 4.1.0 - 20/06/2022 Updated: From e4ac36fbe2a011ca889798eb22cc4842381403a7 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Tue, 21 Jun 2022 21:59:29 +0300 Subject: [PATCH 10/30] Move methods to utilities --- slpkg/slackbuild.py | 17 ++--------------- slpkg/utilities.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/slpkg/slackbuild.py b/slpkg/slackbuild.py index 983d9b59..75b4257c 100644 --- a/slpkg/slackbuild.py +++ b/slpkg/slackbuild.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- import os -import shutil import subprocess import multiprocessing @@ -95,8 +94,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 +182,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..43b8a8bb 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 @@ -40,3 +41,15 @@ class Utilities: for pkg in os.listdir(self.log_packages): if package in pkg: return True + + 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) From a1c7bd807a44758b4189a7261f78c22b3fa5cfea Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Tue, 21 Jun 2022 22:00:20 +0300 Subject: [PATCH 11/30] Added utils test --- tests/test_utilities.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/test_utilities.py 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() From 2c387c06bada4c941acef9ee021315a9d17b9308 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Tue, 21 Jun 2022 22:44:54 +0300 Subject: [PATCH 12/30] Added command clean-tmp --- ChangeLog.txt | 1 + README.rst | 3 ++- man/slpkg.1 | 9 +++++++-- slpkg/main.py | 11 +++++++++++ slpkg/utilities.py | 6 ++++++ slpkg/views/cli_menu.py | 3 ++- 6 files changed, 29 insertions(+), 4 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 435d4110..df950983 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -3,6 +3,7 @@ Updated: - Cli menu view with colors Added: - Unittests +- Command clean-tmp to deletes all downloaded sources from /tmp/slpkg folder 4.1.0 - 20/06/2022 Updated: diff --git a/README.rst b/README.rst index 281bce06..d6e58cfb 100644 --- a/README.rst +++ b/README.rst @@ -52,7 +52,8 @@ Usage install Build and install the packages. remove Remove installed packages. search Search packages by name. - clean-logs Purge logs of dependencies. + clean-logs Clean dependencies log tracking. + clean-tmp Deletes all the downloaded sources. OPTIONS: --yes Answer Yes to all questions. diff --git a/man/slpkg.1 b/man/slpkg.1 index 3f26d72d..ffe5b8db 100644 --- a/man/slpkg.1 +++ b/man/slpkg.1 @@ -4,7 +4,7 @@ slpkg - [OPTIONS] .SH SYNAPSES .P -slpkg [-h|-v] [update] [build] [install] [remove] [search] [clean-logs] --yes --resolve-off --reinstall +slpkg [-h|-v] [update] [build] [install] [remove] [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. @@ -39,7 +39,12 @@ Search packages by name and view everything in your terminal. .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 diff --git a/slpkg/main.py b/slpkg/main.py index b926416b..caf5af78 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -8,6 +8,8 @@ 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.remove_packages import RemovePackages @@ -64,6 +66,15 @@ class Argparse: logs.clean() raise SystemExit() + if self.args[0] == 'clean-tmp': + 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() + # Update repository if self.args[0] == 'update': update = UpdateRepository() diff --git a/slpkg/utilities.py b/slpkg/utilities.py index 43b8a8bb..af0e4ee0 100644 --- a/slpkg/utilities.py +++ b/slpkg/utilities.py @@ -53,3 +53,9 @@ class Utilities: 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/views/cli_menu.py b/slpkg/views/cli_menu.py index 4456178f..50b59d4e 100644 --- a/slpkg/views/cli_menu.py +++ b/slpkg/views/cli_menu.py @@ -24,7 +24,8 @@ def usage(status: int): f' {CYAN}install{ENDC} Build and install the packages.', f' {CYAN}remove{ENDC} Remove installed packages.', f' {CYAN}search{ENDC} Search packages by name.', - f' {CYAN}clean-logs{ENDC} Purge logs of dependencies.\n', + 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.', From cf17321c014181a71ca8d115a97c8e8c304d26b8 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 22 Jun 2022 14:09:24 +0300 Subject: [PATCH 13/30] Fixed complexity --- slpkg/main.py | 191 +++++++++++++++++++++++++++----------------------- 1 file changed, 103 insertions(+), 88 deletions(-) diff --git a/slpkg/main.py b/slpkg/main.py index caf5af78..8709040d 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -21,115 +21,112 @@ 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' - - 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() + def __post_init__(self): + self.flag() + self.check = Check() if len(self.args) <= 0: usage(1) + def flag(self): + self.flags = [] + + options = ['--yes', + '--jobs', + '--resolve-off', + '--reinstall' + ] + + for option in 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() - - if self.args[0] == 'clean-tmp': - 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() - - # Update repository - if self.args[0] == 'update': - update = UpdateRepository() - update.sbo() - raise SystemExit() - - usage(1) + def update(self): + if len(self.args) == 1: + update = UpdateRepository() + update.sbo() + raise SystemExit() + usage(1) + def build(self): if len(self.args) >= 2: - # Build slackbuilds - if self.args[0] == 'build': - packages = list(set(self.args[1:])) + packages = list(set(self.args[1:])) - check.exists(packages) - check.unsupported(packages) + self.check.exists(packages) + self.check.unsupported(packages) - build = Slackbuilds(packages, self.flags, False) - build.execute() - raise SystemExit() + build = Slackbuilds(packages, self.flags, False) + build.execute() + raise SystemExit() + usage(1) - # Install packages - if self.args[0] == 'install': - packages = list(set(self.args[1:])) + def install(self): + if len(self.args) >= 2: + packages = list(set(self.args[1:])) - check.exists(packages) - check.unsupported(packages) + self.check.exists(packages) + self.check.unsupported(packages) - install = Slackbuilds(packages, self.flags, True) - install.execute() - raise SystemExit() + install = Slackbuilds(packages, self.flags, True) + install.execute() + raise SystemExit() + usage(1) - # Remove packages - if self.args[0] == 'remove': - packages = list(set(self.args[1:])) - packages = check.blacklist(packages) + def remove(self): + if len(self.args) >= 2: + packages = list(set(self.args[1:])) + packages = self.check.blacklist(packages) - check.installed(packages) + self.check.installed(packages) - remove = RemovePackages(packages, self.flags) - remove.remove() - raise SystemExit() + remove = RemovePackages(packages, self.flags) + remove.remove() + raise SystemExit() + usage(1) - # Search package - if self.args[0] == 'search': - packages = list(set(self.args[1:])) - packages = check.blacklist(packages) + def search(self): + # Search package + if len(self.args) >= 2: + packages = list(set(self.args[1:])) + packages = self.check.blacklist(packages) - check.exists(packages) + self.check.exists(packages) - search = Search() - search.package(packages) + search = Search() + search.package(packages) + raise SystemExit() + usage(1) - raise SystemExit() + def clean_logs(self): + if len(self.args) == 1: + logs = CleanLogsDependencies(self.flags) + logs.clean() + raise SystemExit() + usage(1) - 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(): @@ -137,7 +134,25 @@ def main(): 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, + 'clean-logs': argparse.clean_logs, + 'clean-tmp': argparse.clean_tmp, + } + + try: + arguments[args[0]]() + except KeyError: + usage(1) if __name__ == '__main__': From 9d33105970cb2bae4aefc2c9f09f0aaf02800a83 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 22 Jun 2022 22:05:56 +0300 Subject: [PATCH 14/30] Switch from json to yaml configs --- configs/blacklist.json | 3 --- configs/blacklist.yaml | 2 ++ configs/slpkg.json | 23 ----------------------- configs/slpkg.yaml | 22 ++++++++++++++++++++++ slpkg/blacklist.py | 6 +++--- slpkg/configs.py | 12 ++++++++---- slpkg/main.py | 7 +++---- 7 files changed, 38 insertions(+), 37 deletions(-) delete mode 100644 configs/blacklist.json create mode 100644 configs/blacklist.yaml delete mode 100644 configs/slpkg.json create mode 100644 configs/slpkg.yaml 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..0d3da6a8 --- /dev/null +++ b/configs/slpkg.yaml @@ -0,0 +1,22 @@ +config: + 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/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 6e53cee9..095de564 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,14 @@ 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 +94,7 @@ class Configs: @classmethod def colour(cls): color = { + 'BOLD': '', 'RED': '', 'GREEN': '', 'YELLOW': '', @@ -100,7 +104,7 @@ class Configs: 'ENDC': '' } - if cls.colors in ['on', 'ON']: + if cls.colors: color = { 'BOLD': '\033[1m', 'RED': '\x1b[91m', diff --git a/slpkg/main.py b/slpkg/main.py index 8709040d..7016bbac 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -25,7 +25,7 @@ class Argparse: self.flag() self.check = Check() - if len(self.args) <= 0: + if len(self.args) == 0: usage(1) def flag(self): @@ -98,7 +98,6 @@ class Argparse: usage(1) def search(self): - # Search package if len(self.args) >= 2: packages = list(set(self.args[1:])) packages = self.check.blacklist(packages) @@ -124,7 +123,7 @@ class Argparse: folder = Configs.prog_name utils = Utilities() utils.remove_folder_if_exists(path, folder) - utils.create_folder(tmp_slpkg, 'build/') + utils.create_folder(tmp_slpkg, 'build') raise SystemExit() usage(1) @@ -146,7 +145,7 @@ def main(): 'remove': argparse.remove, 'search': argparse.search, 'clean-logs': argparse.clean_logs, - 'clean-tmp': argparse.clean_tmp, + 'clean-tmp': argparse.clean_tmp } try: From 580c9f78507e7b546a8d49438fc5b017b6d2af33 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 22 Jun 2022 22:10:31 +0300 Subject: [PATCH 15/30] Updated for yaml --- ChangeLog.txt | 3 ++- README.rst | 4 ++-- man/slpkg.1 | 4 ++-- slackbuild/doinst.sh | 4 ++-- slackbuild/slpkg.SlackBuild | 4 ++-- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index df950983..3b479de0 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,6 +1,7 @@ -4.1.1 - 21/06/2022 +4.1.1 - 22/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 diff --git a/README.rst b/README.rst index d6e58cfb..17e1b68a 100644 --- a/README.rst +++ b/README.rst @@ -72,10 +72,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/man/slpkg.1 b/man/slpkg.1 index ffe5b8db..1402ad41 100644 --- a/man/slpkg.1 +++ b/man/slpkg.1 @@ -80,9 +80,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/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 From b7c98c6ad1d9ec4169ba5212b841d7f327c5e1c0 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Wed, 22 Jun 2022 22:12:16 +0300 Subject: [PATCH 16/30] Updated setup.py for yaml files --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 14e97407..9589d43d 100755 --- a/setup.py +++ b/setup.py @@ -21,8 +21,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', [])], From 96a530488b7691ec6c37bfb7839b3e0368789d86 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Thu, 23 Jun 2022 17:11:50 +0300 Subject: [PATCH 17/30] Added command find installed packages --- ChangeLog.txt | 3 ++- README.rst | 3 ++- man/slpkg.1 | 7 ++++++- slpkg/find_installed.py | 26 ++++++++++++++++++++++++++ slpkg/main.py | 12 ++++++++++++ slpkg/search.py | 2 +- slpkg/views/cli_menu.py | 3 ++- slpkg/views/views.py | 2 +- 8 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 slpkg/find_installed.py diff --git a/ChangeLog.txt b/ChangeLog.txt index 3b479de0..023dff0f 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,10 +1,11 @@ -4.1.1 - 22/06/2022 +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: diff --git a/README.rst b/README.rst index 17e1b68a..8f5eaa5e 100644 --- a/README.rst +++ b/README.rst @@ -51,7 +51,8 @@ Usage build Build only the packages. install Build and install the packages. remove Remove installed packages. - search Search packages by name. + find Find installed packages. + search Search packages on repository. clean-logs Clean dependencies log tracking. clean-tmp Deletes all the downloaded sources. diff --git a/man/slpkg.1 b/man/slpkg.1 index 1402ad41..1b75290a 100644 --- a/man/slpkg.1 +++ b/man/slpkg.1 @@ -32,9 +32,14 @@ remove Removes packages with dependencies if the packages was installed with slpkg install method. .RE .P +find +.RS +Find 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 diff --git a/slpkg/find_installed.py b/slpkg/find_installed.py new file mode 100644 index 00000000..4dbe3988 --- /dev/null +++ b/slpkg/find_installed.py @@ -0,0 +1,26 @@ +#!/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 + + def find(self, packages: list): + matching = [] + for pkg in packages: + for package in os.listdir(self.log_packages): + if pkg in package: + matching.append(package) + self.matched(matching) + + def matched(self, matching: list): + color = self.colors() + for package in matching: + print(f'{color["CYAN"]}{package}{color["ENDC"]}') diff --git a/slpkg/main.py b/slpkg/main.py index 7016bbac..8b5e8a0a 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -12,6 +12,7 @@ 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 @@ -109,6 +110,16 @@ class Argparse: raise SystemExit() usage(1) + def find(self): + 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) @@ -144,6 +155,7 @@ def main(): 'install': argparse.install, 'remove': argparse.remove, 'search': argparse.search, + 'find': argparse.find, 'clean-logs': argparse.clean_logs, 'clean-tmp': argparse.clean_tmp } 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/views/cli_menu.py b/slpkg/views/cli_menu.py index 50b59d4e..04f1925d 100644 --- a/slpkg/views/cli_menu.py +++ b/slpkg/views/cli_menu.py @@ -23,7 +23,8 @@ def usage(status: int): 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}search{ENDC} Search packages by name.', + 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}', diff --git a/slpkg/views/views.py b/slpkg/views/views.py index 6e303db4..ad587a7e 100644 --- a/slpkg/views/views.py +++ b/slpkg/views/views.py @@ -15,7 +15,7 @@ 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 session: str = Session From dbe91586514b71db2b4cf018ec7c74fbf79e84f4 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Thu, 23 Jun 2022 17:28:13 +0300 Subject: [PATCH 18/30] Fixed configs --- configs/slpkg.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/slpkg.yaml b/configs/slpkg.yaml index 0d3da6a8..7adcb108 100644 --- a/configs/slpkg.yaml +++ b/configs/slpkg.yaml @@ -1,4 +1,4 @@ -config: +configs: os_arch: x86_64 tmp_path: /tmp tmp_slpkg: /tmp/slpkg From bcfcfc6f4e78ea7eab874178dbd6bd434f6d8c79 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Thu, 23 Jun 2022 17:28:30 +0300 Subject: [PATCH 19/30] Fixed requirements --- requirements.txt | 1 + setup.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) 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 9589d43d..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( From 845cbe24c1ef8c63bb74ea61227422cbe4067216 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Thu, 23 Jun 2022 18:25:28 +0300 Subject: [PATCH 20/30] Updated manpage --- man/slpkg.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/slpkg.1 b/man/slpkg.1 index 1b75290a..2812663d 100644 --- a/man/slpkg.1 +++ b/man/slpkg.1 @@ -4,7 +4,7 @@ slpkg - [OPTIONS] .SH SYNAPSES .P -slpkg [-h|-v] [update] [build] [install] [remove] [search] [clean-logs] [clean-tmp] --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. From 48f9f7875867a25c4e065148ffd8b7c0040e2241 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Thu, 23 Jun 2022 18:43:04 +0300 Subject: [PATCH 21/30] Updated matching --- slpkg/find_installed.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/slpkg/find_installed.py b/slpkg/find_installed.py index 4dbe3988..5c6319b3 100644 --- a/slpkg/find_installed.py +++ b/slpkg/find_installed.py @@ -22,5 +22,8 @@ class FindInstalled: def matched(self, matching: list): color = self.colors() - for package in matching: - print(f'{color["CYAN"]}{package}{color["ENDC"]}') + if matching: + for package in matching: + print(f'{color["CYAN"]}{package}{color["ENDC"]}') + else: + print('\nDoes not match any package.\n') From aec74047c0246827e7d2e253554aedfe07aaf2ae Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Thu, 23 Jun 2022 21:39:43 +0300 Subject: [PATCH 22/30] Updated cli menu --- README.rst | 2 +- man/slpkg.1 | 2 +- slpkg/views/cli_menu.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 8f5eaa5e..683f9983 100644 --- a/README.rst +++ b/README.rst @@ -41,7 +41,7 @@ Usage $ slpkg --help - USAGE: slpkg [OPTIONS] + USAGE: slpkg [OPTIONS] [COMMAND] DESCRIPTION: Packaging tool that interacts with the SBo repository. diff --git a/man/slpkg.1 b/man/slpkg.1 index 2812663d..06af5c08 100644 --- a/man/slpkg.1 +++ b/man/slpkg.1 @@ -1,7 +1,7 @@ .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] [find] [search] [clean-logs] [clean-tmp] --yes --resolve-off --reinstall diff --git a/slpkg/views/cli_menu.py b/slpkg/views/cli_menu.py index 04f1925d..3db226b9 100644 --- a/slpkg/views/cli_menu.py +++ b/slpkg/views/cli_menu.py @@ -15,7 +15,7 @@ def usage(status: int): YELLOW = color['YELLOW'] ENDC = color['ENDC'] - args = [f'{BOLD}USAGE:{ENDC} {Configs.prog_name} [{CYAN}OPTIONS{ENDC}] \n', + 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', f'{BOLD}COMMANDS:{ENDC}', From dd22e28087551f75650ee704e3a16d6a1a860bf4 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Thu, 23 Jun 2022 22:24:35 +0300 Subject: [PATCH 23/30] Fixed view installed packages --- slpkg/views/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/slpkg/views/views.py b/slpkg/views/views.py index ad587a7e..3a731308 100644 --- a/slpkg/views/views.py +++ b/slpkg/views/views.py @@ -78,7 +78,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: @@ -92,7 +92,7 @@ class ViewMessage: if '--reinstall' in self.flags: install, set_color = 'upgrade', color['YELLOW'] - if self.utils.is_installed(f'{sbo}-{version}-'): + if self.utils.is_installed(f'{sbo}-'): print(f'[{set_color} {install} {color["ENDC"]}] -> ' f'{sbo}-{version}') else: From 94fc303bb7508dd4ed06ca1cf3f151fb1e15297a Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Thu, 23 Jun 2022 23:14:43 +0300 Subject: [PATCH 24/30] Updated view installed --- slpkg/utilities.py | 2 +- slpkg/views/views.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/slpkg/utilities.py b/slpkg/utilities.py index af0e4ee0..ef8bcbea 100644 --- a/slpkg/utilities.py +++ b/slpkg/utilities.py @@ -40,7 +40,7 @@ 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. ''' diff --git a/slpkg/views/views.py b/slpkg/views/views.py index 3a731308..9cb1d89a 100644 --- a/slpkg/views/views.py +++ b/slpkg/views/views.py @@ -18,6 +18,7 @@ class ViewMessage: 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() @@ -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}-'): + if installed: print(f'[{set_color} {install} {color["ENDC"]}] -> ' - f'{sbo}-{version}') + f'{sbo}-{version} -> {set_color}' + f'{installed.split(self.arch)[0][:-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 From 78d6b0916bb4fcae9efefaa8cfea1abd1e373260 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Thu, 23 Jun 2022 23:57:43 +0300 Subject: [PATCH 25/30] Fixed arguments with flags --- slpkg/main.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/slpkg/main.py b/slpkg/main.py index 8b5e8a0a..5704aa7e 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -32,13 +32,13 @@ class Argparse: def flag(self): self.flags = [] - options = ['--yes', - '--jobs', - '--resolve-off', - '--reinstall' - ] + self.options = ['--yes', + '--jobs', + '--resolve-off', + '--reinstall' + ] - for option in options: + for option in self.options: if option in self.args: self.args.remove(option) self.flags.append(option) @@ -63,7 +63,7 @@ class Argparse: usage(1) def build(self): - if len(self.args) >= 2: + if len(self.args) >= 2 and '--reinstall' not in self.flags: packages = list(set(self.args[1:])) self.check.exists(packages) @@ -87,6 +87,9 @@ class Argparse: 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: packages = list(set(self.args[1:])) packages = self.check.blacklist(packages) @@ -99,6 +102,9 @@ class Argparse: 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) @@ -111,6 +117,9 @@ class Argparse: 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) From 18f5dd2243b726e689b6bc77c1af41d510fe86af Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Fri, 24 Jun 2022 00:25:33 +0300 Subject: [PATCH 26/30] Updated view installed --- slpkg/slackbuild.py | 3 +-- slpkg/views/views.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/slpkg/slackbuild.py b/slpkg/slackbuild.py index 75b4257c..25e56fc5 100644 --- a/slpkg/slackbuild.py +++ b/slpkg/slackbuild.py @@ -84,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. ''' diff --git a/slpkg/views/views.py b/slpkg/views/views.py index 9cb1d89a..f2bfb6d4 100644 --- a/slpkg/views/views.py +++ b/slpkg/views/views.py @@ -97,8 +97,8 @@ class ViewMessage: if installed: print(f'[{set_color} {install} {color["ENDC"]}] -> ' - f'{sbo}-{version} -> {set_color}' - f'{installed.split(self.arch)[0][:-1]}' + 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"]}] -> ' From f1899f6e87390471334fc9a871b9c9bc82fe2470 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Fri, 24 Jun 2022 18:45:35 +0300 Subject: [PATCH 27/30] Updated find sbo packages --- slpkg/find_installed.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/slpkg/find_installed.py b/slpkg/find_installed.py index 5c6319b3..7e41e345 100644 --- a/slpkg/find_installed.py +++ b/slpkg/find_installed.py @@ -11,12 +11,13 @@ from slpkg.configs import Configs 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: + if pkg in package and self.repo_tag in package: matching.append(package) self.matched(matching) From 6fc9a6e1a6090a2d04dbd9ccc3aefbc1e94cf543 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Fri, 24 Jun 2022 18:58:33 +0300 Subject: [PATCH 28/30] Updated manpage --- man/slpkg.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/slpkg.1 b/man/slpkg.1 index 06af5c08..ee5b10de 100644 --- a/man/slpkg.1 +++ b/man/slpkg.1 @@ -34,7 +34,7 @@ Removes packages with dependencies if the packages was installed with slpkg inst .P find .RS -Find installed packages on your distribution. +Find sbo installed packages on your distribution. .RE .P search From d88a7ff8e4cd11efe1b0ee5a40cd0cbd72bbc7b8 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Fri, 24 Jun 2022 19:27:42 +0300 Subject: [PATCH 29/30] Updated readme --- README.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 683f9983..ef1b682d 100644 --- a/README.rst +++ b/README.rst @@ -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 Date: Fri, 24 Jun 2022 19:27:59 +0300 Subject: [PATCH 30/30] Updated configs --- slpkg/configs.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/slpkg/configs.py b/slpkg/configs.py index 095de564..3cffa743 100644 --- a/slpkg/configs.py +++ b/slpkg/configs.py @@ -50,9 +50,7 @@ class Configs: ''' Overwrite with user configuration. ''' config_file: str = f'{etc_path}/{prog_name}.yaml' - if os.path.isfile(config_file): - with open(config_file, 'r') as conf: configs = yaml.safe_load(conf)