From 72249c0f1e55f70afc2975f5cbb8db77b56a3d17 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Mon, 24 Oct 2022 19:59:51 +0300 Subject: [PATCH] Added a new search command Signed-off-by: Dimitris Zlatanidis --- ChangeLog.txt | 2 ++ README.rst | 1 + man/slpkg.1 | 7 ++++++- slpkg/main.py | 16 +++++++++++++++- slpkg/search.py | 20 ++++++++++++++++++++ slpkg/views/cli_menu.py | 1 + 6 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 slpkg/search.py diff --git a/ChangeLog.txt b/ChangeLog.txt index 37334a94..a0edf413 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -3,6 +3,8 @@ Updated: - Removed version for skip installed option - Removed unused configurations - Search command to view +Added: +- A new search command to search and match packages from the repository 4.2.1 - 18/10/2022 Added: diff --git a/README.rst b/README.rst index b503f515..82f0a21c 100644 --- a/README.rst +++ b/README.rst @@ -56,6 +56,7 @@ Usage remove Remove installed packages. find Find installed packages. view View packages from the repository. + search Search packages from the 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 eb4ff38e..74932573 100644 --- a/man/slpkg.1 +++ b/man/slpkg.1 @@ -4,7 +4,7 @@ slpkg - [OPTIONS] [COMMAND] .SH SYNAPSES .P -slpkg [-h|-v] [update] [upgrade] [build] [install] [download] [remove] [find] [view] [clean-logs] [clean-tmp] --yes --jobs --resolve-off --reinstall --skip-installed +slpkg [-h|-v] [update] [upgrade] [build] [install] [download] [remove] [find] [view] [search] [clean-logs] [clean-tmp] --yes --jobs --resolve-off --reinstall --skip-installed .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. @@ -52,6 +52,11 @@ view View packages from the repository and get everything in your terminal. .RE .P +search +.RS +Search and match packages from the repository. +.RE +.P clean-logs .RS Cleans dependencies log tracking. diff --git a/slpkg/main.py b/slpkg/main.py index b2c9888a..d81f21c1 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -6,14 +6,15 @@ import sys from dataclasses import dataclass from slpkg.checks import Check -from slpkg.view_package import ViewPackage from slpkg.upgrade import Upgrade from slpkg.version import Version from slpkg.configs import Configs from slpkg.utilities import Utilities +from slpkg.search import SearchPackage from slpkg.views.cli_menu import usage from slpkg.download_only import Download from slpkg.slackbuild import Slackbuilds +from slpkg.view_package import ViewPackage from slpkg.find_installed import FindInstalled from slpkg.remove_packages import RemovePackages from slpkg.clean_logs import CleanLogsDependencies @@ -143,6 +144,18 @@ class Argparse: raise SystemExit() usage(1) + def search(self): + if len(self.args) >= 2 and not self.flags: + packages = list(set(self.args[1:])) + packages = self.check.blacklist(packages) + + # self.check.exists(packages) + + search = SearchPackage() + search.package(packages) + raise SystemExit() + usage(1) + def find(self): if len(self.args) >= 2 and not self.flags: packages = list(set(self.args[1:])) @@ -195,6 +208,7 @@ def main(): 'remove': argparse.remove, 'view': argparse.view, 'find': argparse.find, + 'search': argparse.search, 'clean-logs': argparse.clean_logs, 'clean-tmp': argparse.clean_tmp } diff --git a/slpkg/search.py b/slpkg/search.py new file mode 100644 index 00000000..3e1a1e99 --- /dev/null +++ b/slpkg/search.py @@ -0,0 +1,20 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + + +from dataclasses import dataclass + +from slpkg.queries import SBoQueries + + +@dataclass +class SearchPackage: + + def package(self, packages): + names = SBoQueries('').names() + + for name in names: + for package in packages: + if package in name: + print(f'{name}-{SBoQueries(name).version()} ' + f'{SBoQueries(name).description()}') diff --git a/slpkg/views/cli_menu.py b/slpkg/views/cli_menu.py index 696d67ee..5cf78c30 100644 --- a/slpkg/views/cli_menu.py +++ b/slpkg/views/cli_menu.py @@ -27,6 +27,7 @@ def usage(status: int): f' {CYAN}remove{ENDC} Remove installed packages.', f' {CYAN}find{ENDC} Find installed packages.', f' {CYAN}view{ENDC} View packages from the repository.', + f' {CYAN}search{ENDC} Search packages from the 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}',