Added new-config command

This commit is contained in:
Dimitris Zlatanidis 2023-03-08 21:33:29 +02:00
parent a4cdd7ef4b
commit 2cf611dd70
7 changed files with 182 additions and 6 deletions

View file

@ -2,6 +2,7 @@
Added:
- Ignore comments for list.pkgs files (Thanks to rizitis)
- The file pattern in the config file
- Command new-configs to managing .new files
Updated:
- Blacklist config file
- To support '.sqf' files (Thanks to rizitis)

View file

@ -7,7 +7,7 @@ slpkg \- Package manager utility for Slackware.
slpkg \c
[\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]
slpkg [-h|-v] [-u, update] [-U, upgrade] [-c, check-updates] [-g, configs] [-N, new-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, --reinstall, -k, --skip-installed, -E, --full-reverse, -S, --search, -n, --no-silent, -p, --pkg-version, -z, -G, --generate-only, --directory=[\fIPATH\fR], -F, --file-pattern=[\fIPATTERN\fR]
.SH DESCRIPTION
@ -56,6 +56,11 @@ Deletes all the downloaded SlackBuilds scripts and sources.
Edit the configuration /etc/slpkg/slpkg.toml file.
.RE
.P
.B -N, new-configs
.RS
Managing the .new configuration files is easy and fast. Move, copy or remove them.
.RE
.P
.B -b, build
.RS
Builds the Slackbuilds scripts and adds them to the /tmp directory.

View file

@ -19,8 +19,9 @@ class CheckUpdates(Configs):
self.color = self.colour()
self.bold: str = self.color['bold']
self.bgreen: str = self.color['green']
self.green: str = self.color['green']
self.yellow: str = self.color['yellow']
self.bgreen: str = f'{self.bold}{self.green}'
self.endc: str = self.color['endc']
# Slackbuilds.org repository settings.

View file

@ -12,6 +12,7 @@ from slpkg.tracking import Tracking
from slpkg.queries import SBoQueries
from slpkg.dependees import Dependees
from slpkg.utilities import Utilities
from slpkg.new_config import NewConfig
from slpkg.search import SearchPackage
from slpkg.views.cli_menu import Usage
from slpkg.dialog_box import DialogBox
@ -138,6 +139,7 @@ class Argparse(Configs):
],
'check-updates': [],
'configs': [],
'new-configs': [],
'clean-logs': [
self.flag_yes,
self.flag_short_yes
@ -235,6 +237,7 @@ class Argparse(Configs):
self.commands['-U'] = self.commands['upgrade']
self.commands['-c'] = self.commands['check-updates']
self.commands['-g'] = self.commands['configs']
self.commands['-N'] = self.commands['new-configs']
self.commands['-L'] = self.commands['clean-logs']
self.commands['-D'] = self.commands['clean-tmp']
self.commands['-T'] = self.commands['clean-data']
@ -430,6 +433,13 @@ class Argparse(Configs):
raise SystemExit()
self.usage.help(1)
def new_configs(self) -> None:
if len(self.args) == 1:
new_config = NewConfig()
new_config.check()
raise SystemExit()
self.usage.help(1)
def clean_logs(self) -> None:
if len(self.args) == 1:
self.check.database()
@ -645,6 +655,8 @@ def main():
'-c': argparse.check_updates,
'configs': argparse.edit_configs,
'-g': argparse.edit_configs,
'new-configs': argparse.new_configs,
'-N': argparse.new_configs,
'clean-logs': argparse.clean_logs,
'-L': argparse.clean_logs,
'clean-data': argparse.clean_data,

154
slpkg/new_config.py Normal file
View file

@ -0,0 +1,154 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import shutil
from pathlib import Path
from slpkg.configs import Configs
class NewConfig(Configs):
def __init__(self):
super(Configs).__init__()
self.slpkg_config = Path(self.etc_path, f'{self.prog_name}.toml')
self.blacklist_config = Path(self.etc_path, 'blacklist.toml')
self.slpkg_config_new = Path(self.etc_path, f'{self.prog_name}.toml.new')
self.blacklist_config_new = Path(self.etc_path, 'blacklist.toml.new')
self.color = self.colour()
self.bold: str = self.color['bold']
self.green: str = self.color['green']
self.yellow: str = self.color['yellow']
self.bgreen: str = f'{self.bold}{self.green}'
self.byellow: str = f'{self.bold}{self.yellow}'
self.endc: str = self.color['endc']
self.choice = None
def check(self):
""" Checks for .new files. """
print('Checking for NEW configuration files...')
if self.slpkg_config_new.is_file() or self.blacklist_config_new.is_file():
print('There are NEW files:\n')
if self.slpkg_config_new.is_file():
print(f" {self.bgreen}{self.slpkg_config_new}{self.endc}")
if self.blacklist_config_new.is_file():
print(f" {self.bgreen}{self.blacklist_config_new}{self.endc}")
print(f'\nWhat would you like to do ({self.byellow}K{self.endc}/{self.byellow}O{self.endc}/'
f'{self.byellow}R{self.endc}/{self.byellow}P{self.endc})?\n')
print(f" ({self.byellow}K{self.endc})eep the old files and consider '.new' files later.\n"
f" ({self.byellow}O{self.endc})verwrite all old files with the new ones.\n"
f" The old files will be stored with the suffix '.orig'.\n"
f" ({self.byellow}R{self.endc})emove all '.new' files.\n"
f" ({self.byellow}P{self.endc})rompt K, O, R selection for every single file.\n")
self.menu()
elif not self.slpkg_config_new.is_file() and not self.blacklist_config_new.is_file():
print("\n No '.new' files found.\n")
def menu(self):
""" Menu of choices. """
choice = input('Choice: ')
choice = choice.lower()
arguments: dict = {
'k': self.keep,
'o': self.overwrite,
'r': self.remove,
'p': self.prompt
}
try:
arguments[choice]()
except KeyError:
self.keep()
@staticmethod
def keep():
print("\nNo changes were made.\n")
def overwrite(self):
""" Copy tne .new files and rename the olds to .orig. """
if self.slpkg_config_new.is_file():
self.overwrite_config_file()
if self.blacklist_config_new.is_file():
self.overwrite_blacklist_file()
print() # new line
def overwrite_config_file(self):
""" Copy tne slpkg.toml.new file and rename the old to .orig. """
if self.slpkg_config.is_file():
shutil.copy(self.slpkg_config, f"{self.slpkg_config}.orig")
print(f"\ncp {self.slpkg_config} -> {self.slpkg_config}.orig")
shutil.move(self.slpkg_config_new, self.slpkg_config)
print(f"mv {self.slpkg_config_new} -> {self.slpkg_config}")
def overwrite_blacklist_file(self):
""" Copy tne blacklist.toml.new file and rename the old to .orig. """
if self.blacklist_config.is_file():
shutil.copy(self.blacklist_config, f"{self.blacklist_config}.orig")
print(f"\ncp {self.blacklist_config} -> {self.blacklist_config}.orig")
shutil.move(self.blacklist_config_new, self.blacklist_config)
print(f"mv {self.blacklist_config_new} -> {self.blacklist_config}")
def remove(self):
""" Removes the .new files. """
print() # new line
self.remove_config_file()
self.remove_blacklist_file()
print() # new line
def remove_config_file(self):
""" Remove slpkg.toml.new file. """
if self.slpkg_config_new.is_file():
self.slpkg_config_new.unlink()
print(f"rm {self.slpkg_config_new}")
def remove_blacklist_file(self):
""" Remove blacklist.toml.new file. """
if self.blacklist_config_new.is_file():
self.blacklist_config_new.unlink()
print(f"rm {self.blacklist_config_new}")
def prompt(self):
""" Prompt K, O, R selection for every single file. """
print()
if self.slpkg_config_new.is_file():
make = input(f'{self.bgreen}{self.slpkg_config_new}{self.endc} - '
f'({self.byellow}K{self.endc}/{self.byellow}O{self.endc}/'
f'{self.byellow}R{self.endc}): ')
if make.lower() == 'k':
pass
if make.lower() == 'o':
self.overwrite_config_file()
print() # new line
if make.lower() == 'r':
print() # new line
self.remove_config_file()
print() # new line
if self.blacklist_config_new.is_file():
make = input(f'{self.bgreen}{self.blacklist_config_new}{self.endc} - '
f'({self.byellow}K{self.endc}/{self.byellow}O{self.endc}/'
f'{self.byellow}R{self.endc}): ')
if make.lower() == 'k':
pass
if make.lower() == 'o':
self.overwrite_blacklist_file()
print() # new line
if make.lower() == 'r':
print() # new line
self.remove_blacklist_file()
print() # new line

View file

@ -24,9 +24,9 @@ class Usage(Configs):
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'
f' slpkg [{self.cyan}COMMAND{self.endc}] [-R, remove, -f, find, -w, view, -s, search] [packages...]\n'
f' slpkg [{self.cyan}COMMAND{self.endc}] [-e, dependees, -t, tracking] [packages...]\n'
f' slpkg [{self.cyan}COMMAND{self.endc}] [-N, new-configs, -b, build, -i, install [packages...]\n'
f' slpkg [{self.cyan}COMMAND{self.endc}] [-d, download, -R, remove, -f, find, -w, view] [packages...]\n'
f' slpkg [{self.cyan}COMMAND{self.endc}] [-s, search, -e, dependees, -t, tracking] [packages...]\n'
f' slpkg [{self.yellow}OPTIONS{self.endc}] [-y, --yes, -j, --jobs, -o, --resolve-off, -r, --reinstall]\n'
f' slpkg [{self.yellow}OPTIONS{self.endc}] [-k, --skip-installed, -E, --full-reverse, -S, --search]\n'
f' slpkg [{self.yellow}OPTIONS{self.endc}] [-n, --no-silent, -p, --pkg-version, -G, --generate-only]\n'
@ -47,6 +47,7 @@ class Usage(Configs):
f' {self.cyan}-U, upgrade{self.endc} Upgrade all the packages.\n'
f' {self.cyan}-c, check-updates{self.endc} Check for news on ChangeLog.txt.\n'
f' {self.cyan}-g, configs{self.endc} Edit the configuration file.\n'
f' {self.cyan}-N, new-configs{self.endc} Managing the .new configuration files.\n'
f' {self.cyan}-L, clean-logs{self.endc} Clean dependencies log tracking.\n'
f' {self.cyan}-T, clean-data{self.endc} Clean all the repositories data.\n'
f' {self.cyan}-D, clean-tmp{self.endc} Delete all the downloaded sources.\n'

View file

@ -26,7 +26,8 @@ class Help(Configs):
'update': "Updates the package list and the database.",
'upgrade': "Upgrade all the installed packages if the newer version exists in the repository.",
'check-updates': "Check if there is any news on the SlackBuild's ChangeLog.txt file.",
'configs': "Edit the configuration /etc/slpkg/slpkg.toml file.",
'configs': "Edit the configuration '/etc/slpkg/slpkg.toml' file.",
'new-configs': "Managing the '.new' configuration files is easy and fast. Move, copy or remove them.",
'clean-logs': "Cleans dependencies log tracking. After that procedure you should remove dependencies "
"by hand.",
'clean-tmp': "Deletes all the downloaded SlackBuilds scripts and sources.",
@ -50,6 +51,7 @@ class Help(Configs):
help_commands['-U'] = help_commands['upgrade']
help_commands['-c'] = help_commands['check-updates']
help_commands['-g'] = help_commands['configs']
help_commands['-N'] = help_commands['new-configs']
help_commands['-L'] = help_commands['clean-logs']
help_commands['-D'] = help_commands['clean-tmp']
help_commands['-T'] = help_commands['clean-data']