diff --git a/ChangeLog.txt b/ChangeLog.txt index e264d876..f5e73847 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -6,6 +6,7 @@ Added: - Option --generate-only for ponce repository - Command clean-data for all the tables from the database - Dialog text help for items +- Read packages from file 4.5.5 - 02/03/2023 Fixed: diff --git a/configs/slpkg.toml b/configs/slpkg.toml index 59fe65bf..a278338a 100644 --- a/configs/slpkg.toml +++ b/configs/slpkg.toml @@ -23,6 +23,8 @@ # If true, it uses the extended characters, otherwise the basic ones. # Default is true. [true/false]. ASCII_CHARACTERS = true + # File suffix for list packages. + FILE_LIST_SUFFIX = ".pkgs" # SLACKBUILDS.ORG REPOSITORY CONFIGS. SBO_REPO_PATH = "/var/lib/slpkg/repositories/sbo/" diff --git a/man/slpkg.1 b/man/slpkg.1 index adde0dc2..03066fa6 100644 --- a/man/slpkg.1 +++ b/man/slpkg.1 @@ -5,7 +5,7 @@ slpkg \- Package manager utility for Slackware. .SH SYNOPSIS .P slpkg \c -[\fIOPTIONS\fR] [\fICOMMAND\fR] [\fIPACKAGES...\fR] +[\fIOPTIONS\fR] [\fICOMMAND\fR] [\fIFILELIST|PACKAGES...\fR] .P slpkg [-h|-v] [-u, update] [-U, upgrade] [-c, check-updates] [-g, configs] [-L, clean-logs] [-D, clean-tmp] [-T, clean-data] [-b, build] [-i, install] [-d, download] [-R, remove] [-f, find] [-w, view] [-s, search] [-e, dependees] [-t, tracking] -y, --yes, -j, --jobs, -o, --resolve-off, @@ -189,6 +189,11 @@ Show help information and exit. .RS Print version and exit. .RE +.SH FILELIST|PACKAGES +.P +Instead of packages, you can pass a text file with suffix '.pkgs' and with the names of the packages. Example: '\fIslpkg install list.pkgs\fR'. +Edit the config '/etc/slpkg/slpkg.toml' file to change the suffix if you want. +.RE .SH CONFIGURATION FILES .P Configuration file in the /etc/slpkg/slpkg.toml file. diff --git a/slpkg/configs.py b/slpkg/configs.py index a7c11f35..1de3188f 100644 --- a/slpkg/configs.py +++ b/slpkg/configs.py @@ -4,7 +4,6 @@ import os import tomli import platform - from pathlib import Path from dataclasses import dataclass @@ -92,6 +91,9 @@ class Configs: # If True use extended else basic. ascii_characters: bool = True + # File suffix for list packages. + file_list_suffix: str = '.pkgs' + # Load configurations from the file. load = LoadConfigs() configs = load.file(etc_path, prog_name) @@ -156,6 +158,9 @@ class Configs: # Choose ascii characters. Extended or basic. ascii_characters: bool = config['ASCII_CHARACTERS'] + # File suffix for list packages. + file_list_suffix: str = config['FILE_LIST_SUFFIX'] + except KeyError as error: raise SystemExit(f"\nKeyError: {error}: in the configuration file '/etc/slpkg/slpkg.toml'.\n" f"\nIf you have upgraded the '{prog_name}' probably you need to run:\n" diff --git a/slpkg/main.py b/slpkg/main.py index 37edc2f6..b4395de2 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -3,6 +3,7 @@ import os import sys +from pathlib import Path from slpkg.checks import Check from slpkg.upgrade import Upgrade @@ -309,6 +310,16 @@ class Argparse(Configs): if opt not in flags and opt not in ['--help', '--version']: self.usage.error_for_options(command, flags) + def is_file_list_packages(self): + """ Checks if the arg is filelist.pkgs. """ + if self.args[1].endswith(self.file_list_suffix): + file = Path(self.args[1]) + packages: list = self.utils.read_packages_from_file(file) + else: + packages: list = list(set(self.args[1:])) + + return packages + def choose_packages(self, packages: list, method: str) -> list: """ Choose packages with dialog utility and -S, --search flag. """ height: int = 10 @@ -449,7 +460,8 @@ class Argparse(Configs): command = Argparse.build.__name__ if len(self.args) >= 2: - packages: list = list(set(self.args[1:])) + + packages: list = self.is_file_list_packages() if self.utils.is_option(self.flag_searches, self.flags): packages: list = self.choose_packages(packages, command) @@ -467,7 +479,8 @@ class Argparse(Configs): command = Argparse.install.__name__ if len(self.args) >= 2: - packages: list = list(set(self.args[1:])) + + packages: list = self.is_file_list_packages() if self.utils.is_option(self.flag_searches, self.flags): packages: list = self.choose_packages(packages, command) @@ -485,7 +498,8 @@ class Argparse(Configs): command = Argparse.download.__name__ if len(self.args) >= 2: - packages: list = list(set(self.args[1:])) + + packages: list = self.is_file_list_packages() if self.utils.is_option(self.flag_searches, self.flags): packages: list = self.choose_packages(packages, command) @@ -501,7 +515,8 @@ class Argparse(Configs): command = Argparse.remove.__name__ if len(self.args) >= 2: - packages: list = list(set(self.args[1:])) + + packages: list = self.is_file_list_packages() if self.utils.is_option(self.flag_searches, self.flags): packages: list = self.choose_packages(packages, command) @@ -518,7 +533,8 @@ class Argparse(Configs): command = Argparse.find.__name__ if len(self.args) >= 2: - packages: list = list(set(self.args[1:])) + + packages: list = self.is_file_list_packages() if self.utils.is_option(self.flag_searches, self.flags): packages: list = self.choose_packages(packages, command) @@ -534,7 +550,8 @@ class Argparse(Configs): command = Argparse.view.__name__ if len(self.args) >= 2: - packages: list = list(set(self.args[1:])) + + packages: list = self.is_file_list_packages() if self.utils.is_option(self.flag_searches, self.flags): packages: list = self.choose_packages(packages, command) @@ -551,7 +568,8 @@ class Argparse(Configs): command = Argparse.search.__name__ if len(self.args) >= 2: - packages: list = list(set(self.args[1:])) + + packages: list = self.is_file_list_packages() if self.utils.is_option(self.flag_searches, self.flags): packages: list = self.choose_packages(packages, command) @@ -567,7 +585,8 @@ class Argparse(Configs): command = Argparse.dependees.__name__ if len(self.args) >= 2: - packages: list = list(set(self.args[1:])) + + packages: list = self.is_file_list_packages() if self.utils.is_option(self.flag_searches, self.flags): packages: list = self.choose_packages(packages, command) @@ -584,7 +603,8 @@ class Argparse(Configs): command = Argparse.tracking.__name__ if len(self.args) >= 2: - packages: list = list(set(self.args[1:])) + + packages: list = self.is_file_list_packages() if self.utils.is_option(self.flag_searches, self.flags): packages: list = self.choose_packages(packages, command) diff --git a/slpkg/utilities.py b/slpkg/utilities.py index 2efa2341..5142772c 100644 --- a/slpkg/utilities.py +++ b/slpkg/utilities.py @@ -105,3 +105,12 @@ class Utilities: def is_option(flag: list, flags: list) -> Any: """ Checking for flags. """ return [f for f in flag if f in flags] + + @staticmethod + def read_packages_from_file(file) -> list: + """ Reads packages from file and split these to list. """ + try: + with open(file, 'r', encoding='utf-8') as packages: + return packages.read().splitlines() + except FileNotFoundError as err: + raise SystemExit(f'Error: {err}') diff --git a/slpkg/views/cli_menu.py b/slpkg/views/cli_menu.py index 686de39e..450b99de 100644 --- a/slpkg/views/cli_menu.py +++ b/slpkg/views/cli_menu.py @@ -20,7 +20,8 @@ class Usage(Configs): def help_short(self) -> NoReturn: """ Prints the short menu. """ args = ( - f'Usage: {self.prog_name} [{self.yellow}OPTIONS{self.endc}] [{self.cyan}COMMAND{self.endc}] [PACKAGES...]\n' + f'Usage: {self.prog_name} [{self.yellow}OPTIONS{self.endc}] [{self.cyan}COMMAND{self.endc}] ' + f'[FILELIST|PACKAGES...]\n' f'\n slpkg [{self.cyan}COMMAND{self.endc}] [-u, update, -U, upgrade, -c, check-updates]\n' f' slpkg [{self.cyan}COMMAND{self.endc}] [-L, clean-logs, -T, clean-data, -D, clean-tmp, -g, configs]\n' f' slpkg [{self.cyan}COMMAND{self.endc}] [-b, build, -i, install, -d, download] [packages...]\n' @@ -39,7 +40,7 @@ class Usage(Configs): """ Prints the main menu. """ args: str = ( f'{self.bold}USAGE:{self.endc} {self.prog_name} [{self.yellow}OPTIONS{self.endc}] ' - f'[{self.cyan}COMMAND{self.endc}] [PACKAGES...]\n' + f'[{self.cyan}COMMAND{self.endc}] [FILELIST|PACKAGES...]\n' f'\n{self.bold}DESCRIPTION:{self.endc} Package manager utility for Slackware.\n' f'\n{self.bold}COMMANDS:{self.endc}\n' f' {self.red}-u, update{self.endc} Update the package lists.\n' @@ -84,7 +85,7 @@ class Usage(Configs): """ Error messages for flags. """ flags.reverse() # Put first the short options. print(f'Usage: {self.prog_name} [{self.yellow}OPTIONS{self.endc}] ' - f'[{self.cyan}COMMAND{self.endc}] [PACKAGES...]\n' + f'[{self.cyan}COMMAND{self.endc}] [FILELIST|PACKAGES...]\n' f"Try 'slpkg --help' for help.\n") print(f"{self.bold}{self.red}Error:{self.endc} Got an unexpected extra option.\n"