mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-18 10:26:29 +01:00
Added configs command
This commit is contained in:
parent
a811fbbb82
commit
dcd950b1d4
7 changed files with 96 additions and 30 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
4.4.1 - 28/12/2022
|
||||||
|
Added:
|
||||||
|
- configs command to read and edit configuration file
|
||||||
|
|
||||||
4.4.0 - 23/12/2022
|
4.4.0 - 23/12/2022
|
||||||
Added:
|
Added:
|
||||||
- New command to tracking the dependencies
|
- New command to tracking the dependencies
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
slpkg - [OPTIONS] [COMMAND] <packages>
|
slpkg - [OPTIONS] [COMMAND] <packages>
|
||||||
.SH SYNAPSES
|
.SH SYNAPSES
|
||||||
.P
|
.P
|
||||||
slpkg [-h|-v] [update] [upgrade] [check-updates] [clean-logs] [clean-tmp] [-b, build] [-i, install] [-d, download]
|
slpkg [-h|-v] [update] [upgrade] [check-updates] [configs] [clean-logs] [clean-tmp] [-b, build] [-i, install] [-d, download]
|
||||||
[-r, remove] [-f, find] [-w, view] [-s, search] [-e, dependees] [-t, tracking] --yes, --jobs, --resolve-off,
|
[-r, remove] [-f, find] [-w, view] [-s, search] [-e, dependees] [-t, tracking] --yes, --jobs, --resolve-off,
|
||||||
--reinstall, --skip-installed, --full-reverse, --search
|
--reinstall, --skip-installed, --full-reverse, --search
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
|
@ -32,6 +32,11 @@ check-updates
|
||||||
Check if there is any news on the SlackBuild's ChangeLog.txt file.
|
Check if there is any news on the SlackBuild's ChangeLog.txt file.
|
||||||
.RE
|
.RE
|
||||||
.P
|
.P
|
||||||
|
configs
|
||||||
|
.RS
|
||||||
|
Edit the configuration /etc/slpkg/slpkg.toml file.
|
||||||
|
.RE
|
||||||
|
.P
|
||||||
clean-logs
|
clean-logs
|
||||||
.RS
|
.RS
|
||||||
Cleans dependencies log tracking. After that procedure you should remove dependencies by hand.
|
Cleans dependencies log tracking. After that procedure you should remove dependencies by hand.
|
||||||
|
|
|
@ -57,10 +57,10 @@ class Configs:
|
||||||
# Overwrite with user configuration.
|
# Overwrite with user configuration.
|
||||||
config_file: str = f'{etc_path}/{prog_name}.toml'
|
config_file: str = f'{etc_path}/{prog_name}.toml'
|
||||||
if os.path.isfile(config_file):
|
if os.path.isfile(config_file):
|
||||||
|
try:
|
||||||
with open(config_file, 'rb') as conf:
|
with open(config_file, 'rb') as conf:
|
||||||
configs = tomli.load(conf)
|
configs = tomli.load(conf)
|
||||||
|
|
||||||
try:
|
|
||||||
config = configs['configs']
|
config = configs['configs']
|
||||||
|
|
||||||
# OS architecture by default
|
# OS architecture by default
|
||||||
|
@ -96,8 +96,8 @@ class Configs:
|
||||||
# Dialog utility
|
# Dialog utility
|
||||||
dialog: str = config['dialog']
|
dialog: str = config['dialog']
|
||||||
|
|
||||||
except KeyError as error:
|
except (KeyError, tomli.TOMLDecodeError) as error:
|
||||||
print(f"Error: {error}: in the configuration file "
|
raise SystemExit(f"\nError: {error}: in the configuration file "
|
||||||
"'/etc/slpkg/slpkg.toml'\n")
|
"'/etc/slpkg/slpkg.toml'\n")
|
||||||
|
|
||||||
# Creating the paths if not exists
|
# Creating the paths if not exists
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import os
|
||||||
|
import tomli
|
||||||
import locale
|
import locale
|
||||||
|
|
||||||
from dialog import Dialog
|
from dialog import Dialog
|
||||||
|
@ -28,3 +30,47 @@ class DialogBox:
|
||||||
tags = packages
|
tags = packages
|
||||||
|
|
||||||
return code, tags
|
return code, tags
|
||||||
|
|
||||||
|
def form_configs(self):
|
||||||
|
""" Read and write the configuration file. """
|
||||||
|
elements = []
|
||||||
|
config_file: str = f'{self.configs.etc_path}/{self.configs.prog_name}.toml'
|
||||||
|
|
||||||
|
if os.path.isfile(config_file):
|
||||||
|
# Load the toml config file.
|
||||||
|
try:
|
||||||
|
with open(config_file, 'rb') as conf:
|
||||||
|
configs = tomli.load(conf)
|
||||||
|
except (KeyError, tomli.TOMLDecodeError) as error:
|
||||||
|
raise SystemExit(f"\nError: {error}: in the configuration file "
|
||||||
|
"'/etc/slpkg/slpkg.toml'\n")
|
||||||
|
|
||||||
|
# Creating the elements for the dialog form.
|
||||||
|
for i, (key, value) in enumerate(configs['configs'].items(), start=1):
|
||||||
|
if value is True:
|
||||||
|
value = 'true'
|
||||||
|
elif value is False:
|
||||||
|
value = 'false'
|
||||||
|
elements += [
|
||||||
|
(key, i, 1, value, i, 17, 47, 200, '0x0')
|
||||||
|
]
|
||||||
|
text = f'Edit the configuration file: {config_file}.'
|
||||||
|
title = ' Configuration File '
|
||||||
|
code, tags = self.d.mixedform(text=text, title=title, elements=elements,
|
||||||
|
height=30, width=70)
|
||||||
|
os.system('clear')
|
||||||
|
|
||||||
|
if code == 'ok':
|
||||||
|
# Read the original config file.
|
||||||
|
with open(config_file, 'r') as toml_file:
|
||||||
|
orig_config = toml_file.readlines()
|
||||||
|
|
||||||
|
# Write the new values to the config file.
|
||||||
|
with open(config_file, 'w') as patch_toml:
|
||||||
|
for line in orig_config:
|
||||||
|
for key, value in zip(configs['configs'].keys(), tags):
|
||||||
|
if line.lstrip().startswith(key):
|
||||||
|
line = f' {key} = "{value}"\n'
|
||||||
|
if line.lstrip().startswith(('colors =', 'dialog =')):
|
||||||
|
line = line.replace('"', '')
|
||||||
|
patch_toml.write(line)
|
||||||
|
|
|
@ -185,6 +185,35 @@ class Argparse:
|
||||||
raise SystemExit()
|
raise SystemExit()
|
||||||
self.usage.help(1)
|
self.usage.help(1)
|
||||||
|
|
||||||
|
def edit_configs(self):
|
||||||
|
if len(self.args) == 1 and not self.flags:
|
||||||
|
self.dialog.form_configs()
|
||||||
|
raise SystemExit()
|
||||||
|
self.usage.help(1)
|
||||||
|
|
||||||
|
def clean_logs(self):
|
||||||
|
if [f for f in self.flags if f not in [self.flag_yes]]:
|
||||||
|
self.usage.help(1)
|
||||||
|
|
||||||
|
if len(self.args) == 1:
|
||||||
|
self.check.database()
|
||||||
|
|
||||||
|
logs = CleanLogsDependencies(self.flags)
|
||||||
|
logs.clean()
|
||||||
|
raise SystemExit()
|
||||||
|
self.usage.help(1)
|
||||||
|
|
||||||
|
def clean_tmp(self):
|
||||||
|
if len(self.args) == 1 and not self.flags:
|
||||||
|
path = self.configs.tmp_path
|
||||||
|
tmp_slpkg = self.configs.tmp_slpkg
|
||||||
|
folder = self.configs.prog_name
|
||||||
|
|
||||||
|
self.utils.remove_folder_if_exists(path, folder)
|
||||||
|
self.utils.create_folder(tmp_slpkg, 'build')
|
||||||
|
raise SystemExit()
|
||||||
|
self.usage.help(1)
|
||||||
|
|
||||||
def build(self):
|
def build(self):
|
||||||
if [f for f in self.flags if f not in [self.flag_yes,
|
if [f for f in self.flags if f not in [self.flag_yes,
|
||||||
self.flag_jobs,
|
self.flag_jobs,
|
||||||
|
@ -360,29 +389,6 @@ class Argparse:
|
||||||
raise SystemExit()
|
raise SystemExit()
|
||||||
self.usage.help(1)
|
self.usage.help(1)
|
||||||
|
|
||||||
def clean_logs(self):
|
|
||||||
if [f for f in self.flags if f not in [self.flag_yes]]:
|
|
||||||
self.usage.help(1)
|
|
||||||
|
|
||||||
if len(self.args) == 1:
|
|
||||||
self.check.database()
|
|
||||||
|
|
||||||
logs = CleanLogsDependencies(self.flags)
|
|
||||||
logs.clean()
|
|
||||||
raise SystemExit()
|
|
||||||
self.usage.help(1)
|
|
||||||
|
|
||||||
def clean_tmp(self):
|
|
||||||
if len(self.args) == 1 and not self.flags:
|
|
||||||
path = self.configs.tmp_path
|
|
||||||
tmp_slpkg = self.configs.tmp_slpkg
|
|
||||||
folder = self.configs.prog_name
|
|
||||||
|
|
||||||
self.utils.remove_folder_if_exists(path, folder)
|
|
||||||
self.utils.create_folder(tmp_slpkg, 'build')
|
|
||||||
raise SystemExit()
|
|
||||||
self.usage.help(1)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = sys.argv
|
args = sys.argv
|
||||||
|
@ -398,6 +404,7 @@ def main():
|
||||||
'update': argparse.update,
|
'update': argparse.update,
|
||||||
'upgrade': argparse.upgrade,
|
'upgrade': argparse.upgrade,
|
||||||
'check-updates': argparse.check_updates,
|
'check-updates': argparse.check_updates,
|
||||||
|
'configs': argparse.edit_configs,
|
||||||
'clean-logs': argparse.clean_logs,
|
'clean-logs': argparse.clean_logs,
|
||||||
'clean-tmp': argparse.clean_tmp,
|
'clean-tmp': argparse.clean_tmp,
|
||||||
'build': argparse.build,
|
'build': argparse.build,
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import tomli
|
||||||
import shutil
|
import shutil
|
||||||
import tarfile
|
import tarfile
|
||||||
|
|
||||||
|
@ -61,3 +62,4 @@ class Utilities:
|
||||||
tag = ''.join(package[len(name + version + arch + build) + 4:].split('-'))
|
tag = ''.join(package[len(name + version + arch + build) + 4:].split('-'))
|
||||||
|
|
||||||
return [name, version, arch, build, tag]
|
return [name, version, arch, build, tag]
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,8 @@ class Usage:
|
||||||
f'Usage: {Configs.prog_name} [{self.yellow}OPTIONS{self.endc}] [{self.cyan}COMMAND{self.endc}] <packages>\n'
|
f'Usage: {Configs.prog_name} [{self.yellow}OPTIONS{self.endc}] [{self.cyan}COMMAND{self.endc}] <packages>\n'
|
||||||
f'\n slpkg [{self.yellow}OPTIONS{self.endc}] [--yes, --jobs, --resolve-off, --reinstall]\n'
|
f'\n slpkg [{self.yellow}OPTIONS{self.endc}] [--yes, --jobs, --resolve-off, --reinstall]\n'
|
||||||
f' slpkg [{self.yellow}OPTIONS{self.endc}] [--skip-installed, --full-reverse, --search]\n'
|
f' slpkg [{self.yellow}OPTIONS{self.endc}] [--skip-installed, --full-reverse, --search]\n'
|
||||||
f' slpkg [{self.cyan}COMMAND{self.endc}] [update, upgrade, check-updates, clean-logs, clean-tmp]\n'
|
f' slpkg [{self.cyan}COMMAND{self.endc}] [update, upgrade, check-updates, configs]\n'
|
||||||
|
f' slpkg [{self.cyan}COMMAND{self.endc}] [clean-logs, clean-tmp]\n'
|
||||||
f' slpkg [{self.cyan}COMMAND{self.endc}] [-b, build, -i, install, -d, download, -r, remove] <packages>\n'
|
f' slpkg [{self.cyan}COMMAND{self.endc}] [-b, build, -i, install, -d, download, -r, remove] <packages>\n'
|
||||||
f' slpkg [{self.cyan}COMMAND{self.endc}] [-f, find, -w, view, -s, search, -e, dependees] <packages>\n'
|
f' slpkg [{self.cyan}COMMAND{self.endc}] [-f, find, -w, view, -s, search, -e, dependees] <packages>\n'
|
||||||
f' slpkg [{self.cyan}COMMAND{self.endc}] [-t, tracking] <packages>\n'
|
f' slpkg [{self.cyan}COMMAND{self.endc}] [-t, tracking] <packages>\n'
|
||||||
|
@ -42,6 +43,7 @@ class Usage:
|
||||||
f' {self.red}update{self.endc} Update the package lists.\n'
|
f' {self.red}update{self.endc} Update the package lists.\n'
|
||||||
f' {self.cyan}upgrade{self.endc} Upgrade all the packages.\n'
|
f' {self.cyan}upgrade{self.endc} Upgrade all the packages.\n'
|
||||||
f' {self.cyan}check-updates{self.endc} Check for news on ChangeLog.txt.\n'
|
f' {self.cyan}check-updates{self.endc} Check for news on ChangeLog.txt.\n'
|
||||||
|
f' {self.cyan}configs{self.endc} Edit the configuration file.\n'
|
||||||
f' {self.cyan}clean-logs{self.endc} Clean dependencies log tracking.\n'
|
f' {self.cyan}clean-logs{self.endc} Clean dependencies log tracking.\n'
|
||||||
f' {self.cyan}clean-tmp{self.endc} Delete all the downloaded sources.\n'
|
f' {self.cyan}clean-tmp{self.endc} Delete all the downloaded sources.\n'
|
||||||
f' {self.cyan}-b, build{self.endc} <packages> Build only the packages.\n'
|
f' {self.cyan}-b, build{self.endc} <packages> Build only the packages.\n'
|
||||||
|
|
Loading…
Reference in a new issue