Switch to python toml to load configuration files

Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
Dimitris Zlatanidis 2022-11-30 18:44:09 +02:00
parent 89105dc40a
commit dcd65c89c4
13 changed files with 45 additions and 42 deletions

View file

@ -1,6 +1,8 @@
4.3.2 - 28/11/2022
Fixed:
- Remove multiple packages with dependencies
Updated:
- Switch to python toml to load configuration files
4.3.1 - 26/11/2022
Added:

View file

@ -20,8 +20,8 @@ Requirements
.. code-block:: bash
SQLAlchemy>=1.4.36
PyYAML>=6.0
SQLAlchemy >= 1.4.36
toml >= 0.10.2
Install
-------
@ -79,10 +79,10 @@ Configuration files
.. code-block:: bash
/etc/slpkg/slpkg.yml
/etc/slpkg/slpkg.toml
General configuration of slpkg
/etc/slpkg/blacklist.yml
/etc/slpkg/blacklist.toml
Blacklist of packages
Donate

View file

@ -1,4 +1,6 @@
blacklist:
[blacklist]
# Add packages and separate them with commas.
packages: ["%README%",]
packages = [
"%README%"
]

View file

@ -1,52 +1,52 @@
configs:
[configs]
# OS architecture by default.
os_arch: x86_64
os_archi = "x86_64"
# Tmp path for slpkg.
tmp_slpkg: /tmp/slpkg
tmp_slpkg = "/tmp/slpkg"
# Path for building source and the script
build_path: /tmp/slpkg/build
build_path = "/tmp/slpkg/build"
# This path working only with the command download.
download_only: /tmp/slpkg
download_only = "/tmp/slpkg"
# The path that the SLACKBUILDS.TXT file downloaded.
sbo_repo_path: /var/lib/slpkg/repository
sbo_repo_pathi = "/var/lib/slpkg/repository"
# The name of the database. Default name is 'database.slpkg'.
database: database.slpkg
database = "database.slpkg"
# Slackbuilds.org repository url.
sbo_repo_url: http://slackbuilds.org/slackbuilds/15.0
sbo_repo_url = "http://slackbuilds.org/slackbuilds/15.0"
# The SLACKBUILDS.TXT repository file.
sbo_txt: SLACKBUILDS.TXT
sbo_txt = "SLACKBUILDS.TXT"
# The ChangeLog.txt file.
chglog_txt: ChangeLog.txt
chglog_txt = "ChangeLog.txt"
# The sbo tar suffix.
sbo_tar_suffix: .tar.gz
sbo_tar_suffix = ".tar.gz"
# The sbo repository tag.
sbo_repo_tag: _SBo
sbo_repo_tag = "_SBo"
# Slackware install command. Alternative you can
# use 'installpkg', if you want.
installpkg: upgradepkg --install-new
installpkg = "upgradepkg --install-new"
# Upgrade or reinstall slackware command.
reinstall: upgradepkg --reinstall
reinstall = "upgradepkg --reinstall"
# Slackware command to remove packages.
removepkg: removepkg
removepkg = "removepkg"
# Cli menu colors configs. Default is off. [on/off]
colors: off
colors = "off"
# Wget downloader options.
# -c, --continue: resume getting a partially-downloaded file.
# -N, --timestamping: don't re-retrieve files unless newer
# than local.
wget_options: -c -N
wget_options = "-c -N"

View file

@ -110,9 +110,9 @@ Print version and exit.
.RE
.SH CONFIGURATION FILES
.P
Configuration file in the /etc/slpkg/slpkg.yml file.
Configuration file in the /etc/slpkg/slpkg.toml file.
.RE
Blacklist file in the /etc/slpkg/blacklist.yml file.
Blacklist file in the /etc/slpkg/blacklist.toml file.
.SH REPORT BUGS
.P
Please report any found to https://gitlab.com/dslackw/slpkg/-/issues.

View file

@ -1,2 +1,2 @@
SQLAlchemy>=1.4.36
PyYAML>=6.0
toml>=0.10.2

View file

@ -39,7 +39,7 @@ packages =
python_requires = >=3.7
install_requires =
SQLAlchemy >= 1.4.36
PyYAML >= 6.0
toml >= 0.10.2
include_package_data = True
[options.packages.find]

View file

@ -8,8 +8,8 @@ config() {
fi
}
config etc/slpkg/slpkg.yml.new
config etc/slpkg/blacklist.yml.new
config etc/slpkg/slpkg.toml.new
config etc/slpkg/blacklist.toml.new
if [ -x /usr/bin/update-desktop-database ]; then
/usr/bin/update-desktop-database -q usr/share/applications >/dev/null 2>&1

View file

@ -98,8 +98,8 @@ find $PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | gr
# Install configuration files and creating lib directory
mkdir -p $PKG/etc/$PRGNAM
install -D -m0644 configs/slpkg.yml $PKG/etc/slpkg/slpkg.yml.new
install -D -m0645 configs/blacklist.yml $PKG/etc/slpkg/blacklist.yml.new
install -D -m0644 configs/slpkg.toml $PKG/etc/slpkg/slpkg.toml.new
install -D -m0645 configs/blacklist.toml $PKG/etc/slpkg/blacklist.toml.new
mkdir -p $PKG/usr/man/man1
cp man/slpkg.1 $PKG/usr/man/man1

View file

@ -3,7 +3,7 @@
import os
import yaml
import tomli
from dataclasses import dataclass
from slpkg.configs import Configs
@ -15,7 +15,7 @@ class Blacklist:
etc_path: str = Configs.etc_path
def get(self):
file = f'{self.etc_path}/blacklist.yml'
file = f'{self.etc_path}/blacklist.toml'
if os.path.isfile(file):
with open(file, 'r') as black:
return yaml.safe_load(black)['blacklist']['packages']
with open(file, 'rb') as black:
return tomli.load(black)['blacklist']['packages']

View file

@ -70,7 +70,7 @@ class Check:
if packages:
raise SystemExit(
f'\nThe packages \'{", ".join(packages)}\' is blacklisted.\n'
f'Please edit the blacklist.yml file in {self.etc_path} '
f'Please edit the blacklist.toml file in {self.etc_path} '
'folder.\n')
def database(self):

View file

@ -3,7 +3,7 @@
import os
import yaml
import tomli
from dataclasses import dataclass
@ -51,13 +51,12 @@ class Configs:
wget_options = '-c -N'
''' Overwrite with user configuration. '''
config_file: str = f'{etc_path}/{prog_name}.yml'
config_file: str = f'{etc_path}/{prog_name}.toml'
if os.path.isfile(config_file):
with open(config_file, 'r') as conf:
configs = yaml.safe_load(conf)
with open(config_file, 'rb') as conf:
configs = tomli.load(conf)
try:
config = configs['configs']
# OS architecture by default

View file

@ -39,7 +39,7 @@ def usage(status: int):
f' {YELLOW}--skip-installed{ENDC} Skip installed packages.\n',
' -h, --help Show this message and exit.',
' -v, --version Print version and exit.\n',
'Edit the configuration file in the /etc/slpkg/slpkg.yml.',
'Edit the configuration file in the /etc/slpkg/slpkg.toml.',
'If you need more information try to use slpkg manpage.']
for opt in args: