mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-29 20:34:22 +01:00
Added read packages from file
This commit is contained in:
parent
c51488abad
commit
bc64dea4d4
7 changed files with 57 additions and 14 deletions
|
@ -6,6 +6,7 @@ Added:
|
||||||
- Option --generate-only for ponce repository
|
- Option --generate-only for ponce repository
|
||||||
- Command clean-data for all the tables from the database
|
- Command clean-data for all the tables from the database
|
||||||
- Dialog text help for items
|
- Dialog text help for items
|
||||||
|
- Read packages from file
|
||||||
|
|
||||||
4.5.5 - 02/03/2023
|
4.5.5 - 02/03/2023
|
||||||
Fixed:
|
Fixed:
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
# If true, it uses the extended characters, otherwise the basic ones.
|
# If true, it uses the extended characters, otherwise the basic ones.
|
||||||
# Default is true. [true/false].
|
# Default is true. [true/false].
|
||||||
ASCII_CHARACTERS = true
|
ASCII_CHARACTERS = true
|
||||||
|
# File suffix for list packages.
|
||||||
|
FILE_LIST_SUFFIX = ".pkgs"
|
||||||
|
|
||||||
# SLACKBUILDS.ORG REPOSITORY CONFIGS.
|
# SLACKBUILDS.ORG REPOSITORY CONFIGS.
|
||||||
SBO_REPO_PATH = "/var/lib/slpkg/repositories/sbo/"
|
SBO_REPO_PATH = "/var/lib/slpkg/repositories/sbo/"
|
||||||
|
|
|
@ -5,7 +5,7 @@ slpkg \- Package manager utility for Slackware.
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
.P
|
.P
|
||||||
slpkg \c
|
slpkg \c
|
||||||
[\fIOPTIONS\fR] [\fICOMMAND\fR] [\fIPACKAGES...\fR]
|
[\fIOPTIONS\fR] [\fICOMMAND\fR] [\fIFILELIST|PACKAGES...\fR]
|
||||||
.P
|
.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]
|
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,
|
[-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
|
.RS
|
||||||
Print version and exit.
|
Print version and exit.
|
||||||
.RE
|
.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
|
.SH CONFIGURATION FILES
|
||||||
.P
|
.P
|
||||||
Configuration file in the /etc/slpkg/slpkg.toml file.
|
Configuration file in the /etc/slpkg/slpkg.toml file.
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
import os
|
import os
|
||||||
import tomli
|
import tomli
|
||||||
import platform
|
import platform
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
@ -92,6 +91,9 @@ class Configs:
|
||||||
# If True use extended else basic.
|
# If True use extended else basic.
|
||||||
ascii_characters: bool = True
|
ascii_characters: bool = True
|
||||||
|
|
||||||
|
# File suffix for list packages.
|
||||||
|
file_list_suffix: str = '.pkgs'
|
||||||
|
|
||||||
# Load configurations from the file.
|
# Load configurations from the file.
|
||||||
load = LoadConfigs()
|
load = LoadConfigs()
|
||||||
configs = load.file(etc_path, prog_name)
|
configs = load.file(etc_path, prog_name)
|
||||||
|
@ -156,6 +158,9 @@ class Configs:
|
||||||
# Choose ascii characters. Extended or basic.
|
# Choose ascii characters. Extended or basic.
|
||||||
ascii_characters: bool = config['ASCII_CHARACTERS']
|
ascii_characters: bool = config['ASCII_CHARACTERS']
|
||||||
|
|
||||||
|
# File suffix for list packages.
|
||||||
|
file_list_suffix: str = config['FILE_LIST_SUFFIX']
|
||||||
|
|
||||||
except KeyError as error:
|
except KeyError as error:
|
||||||
raise SystemExit(f"\nKeyError: {error}: in the configuration file '/etc/slpkg/slpkg.toml'.\n"
|
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"
|
f"\nIf you have upgraded the '{prog_name}' probably you need to run:\n"
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from slpkg.checks import Check
|
from slpkg.checks import Check
|
||||||
from slpkg.upgrade import Upgrade
|
from slpkg.upgrade import Upgrade
|
||||||
|
@ -309,6 +310,16 @@ class Argparse(Configs):
|
||||||
if opt not in flags and opt not in ['--help', '--version']:
|
if opt not in flags and opt not in ['--help', '--version']:
|
||||||
self.usage.error_for_options(command, flags)
|
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:
|
def choose_packages(self, packages: list, method: str) -> list:
|
||||||
""" Choose packages with dialog utility and -S, --search flag. """
|
""" Choose packages with dialog utility and -S, --search flag. """
|
||||||
height: int = 10
|
height: int = 10
|
||||||
|
@ -449,7 +460,8 @@ class Argparse(Configs):
|
||||||
command = Argparse.build.__name__
|
command = Argparse.build.__name__
|
||||||
|
|
||||||
if len(self.args) >= 2:
|
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):
|
if self.utils.is_option(self.flag_searches, self.flags):
|
||||||
packages: list = self.choose_packages(packages, command)
|
packages: list = self.choose_packages(packages, command)
|
||||||
|
@ -467,7 +479,8 @@ class Argparse(Configs):
|
||||||
command = Argparse.install.__name__
|
command = Argparse.install.__name__
|
||||||
|
|
||||||
if len(self.args) >= 2:
|
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):
|
if self.utils.is_option(self.flag_searches, self.flags):
|
||||||
packages: list = self.choose_packages(packages, command)
|
packages: list = self.choose_packages(packages, command)
|
||||||
|
@ -485,7 +498,8 @@ class Argparse(Configs):
|
||||||
command = Argparse.download.__name__
|
command = Argparse.download.__name__
|
||||||
|
|
||||||
if len(self.args) >= 2:
|
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):
|
if self.utils.is_option(self.flag_searches, self.flags):
|
||||||
packages: list = self.choose_packages(packages, command)
|
packages: list = self.choose_packages(packages, command)
|
||||||
|
@ -501,7 +515,8 @@ class Argparse(Configs):
|
||||||
command = Argparse.remove.__name__
|
command = Argparse.remove.__name__
|
||||||
|
|
||||||
if len(self.args) >= 2:
|
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):
|
if self.utils.is_option(self.flag_searches, self.flags):
|
||||||
packages: list = self.choose_packages(packages, command)
|
packages: list = self.choose_packages(packages, command)
|
||||||
|
@ -518,7 +533,8 @@ class Argparse(Configs):
|
||||||
command = Argparse.find.__name__
|
command = Argparse.find.__name__
|
||||||
|
|
||||||
if len(self.args) >= 2:
|
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):
|
if self.utils.is_option(self.flag_searches, self.flags):
|
||||||
packages: list = self.choose_packages(packages, command)
|
packages: list = self.choose_packages(packages, command)
|
||||||
|
@ -534,7 +550,8 @@ class Argparse(Configs):
|
||||||
command = Argparse.view.__name__
|
command = Argparse.view.__name__
|
||||||
|
|
||||||
if len(self.args) >= 2:
|
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):
|
if self.utils.is_option(self.flag_searches, self.flags):
|
||||||
packages: list = self.choose_packages(packages, command)
|
packages: list = self.choose_packages(packages, command)
|
||||||
|
@ -551,7 +568,8 @@ class Argparse(Configs):
|
||||||
command = Argparse.search.__name__
|
command = Argparse.search.__name__
|
||||||
|
|
||||||
if len(self.args) >= 2:
|
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):
|
if self.utils.is_option(self.flag_searches, self.flags):
|
||||||
packages: list = self.choose_packages(packages, command)
|
packages: list = self.choose_packages(packages, command)
|
||||||
|
@ -567,7 +585,8 @@ class Argparse(Configs):
|
||||||
command = Argparse.dependees.__name__
|
command = Argparse.dependees.__name__
|
||||||
|
|
||||||
if len(self.args) >= 2:
|
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):
|
if self.utils.is_option(self.flag_searches, self.flags):
|
||||||
packages: list = self.choose_packages(packages, command)
|
packages: list = self.choose_packages(packages, command)
|
||||||
|
@ -584,7 +603,8 @@ class Argparse(Configs):
|
||||||
command = Argparse.tracking.__name__
|
command = Argparse.tracking.__name__
|
||||||
|
|
||||||
if len(self.args) >= 2:
|
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):
|
if self.utils.is_option(self.flag_searches, self.flags):
|
||||||
packages: list = self.choose_packages(packages, command)
|
packages: list = self.choose_packages(packages, command)
|
||||||
|
|
|
@ -105,3 +105,12 @@ class Utilities:
|
||||||
def is_option(flag: list, flags: list) -> Any:
|
def is_option(flag: list, flags: list) -> Any:
|
||||||
""" Checking for flags. """
|
""" Checking for flags. """
|
||||||
return [f for f in flag if f in 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}')
|
||||||
|
|
|
@ -20,7 +20,8 @@ class Usage(Configs):
|
||||||
def help_short(self) -> NoReturn:
|
def help_short(self) -> NoReturn:
|
||||||
""" Prints the short menu. """
|
""" Prints the short menu. """
|
||||||
args = (
|
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'\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}] [-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'
|
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. """
|
""" Prints the main menu. """
|
||||||
args: str = (
|
args: str = (
|
||||||
f'{self.bold}USAGE:{self.endc} {self.prog_name} [{self.yellow}OPTIONS{self.endc}] '
|
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}DESCRIPTION:{self.endc} Package manager utility for Slackware.\n'
|
||||||
f'\n{self.bold}COMMANDS:{self.endc}\n'
|
f'\n{self.bold}COMMANDS:{self.endc}\n'
|
||||||
f' {self.red}-u, update{self.endc} Update the package lists.\n'
|
f' {self.red}-u, update{self.endc} Update the package lists.\n'
|
||||||
|
@ -84,7 +85,7 @@ class Usage(Configs):
|
||||||
""" Error messages for flags. """
|
""" Error messages for flags. """
|
||||||
flags.reverse() # Put first the short options.
|
flags.reverse() # Put first the short options.
|
||||||
print(f'Usage: {self.prog_name} [{self.yellow}OPTIONS{self.endc}] '
|
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")
|
f"Try 'slpkg --help' for help.\n")
|
||||||
|
|
||||||
print(f"{self.bold}{self.red}Error:{self.endc} Got an unexpected extra option.\n"
|
print(f"{self.bold}{self.red}Error:{self.endc} Got an unexpected extra option.\n"
|
||||||
|
|
Loading…
Add table
Reference in a new issue