Merge branch 'develop'

This commit is contained in:
Dimitris Zlatanidis 2022-12-29 17:55:57 +02:00
commit d6aa1b2ac4
29 changed files with 268 additions and 120 deletions

View file

@ -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
Added:
- New command to tracking the dependencies

View file

@ -31,10 +31,31 @@ Install from the official third-party `SBo repository <https://slackbuilds.org/r
.. code-block:: bash
$ tar xvf slpkg-4.4.0.tar.gz
$ cd slpkg-4.4.0
$ tar xvf slpkg-4.4.1.tar.gz
$ cd slpkg-4.4.1
$ ./install.sh
Screenshots
-----------
.. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/configs.png
:target: https://gitlab.com/dslackw/slpkg
.. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/install.png
:target: https://gitlab.com/dslackw/slpkg
.. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/install_next.png
:target: https://gitlab.com/dslackw/slpkg
.. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/dependees_next.png
:target: https://gitlab.com/dslackw/slpkg
.. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/view_next.png
:target: https://gitlab.com/dslackw/slpkg
.. image:: https://gitlab.com/dslackw/images/raw/master/slpkg/remove_next.png
:target: https://gitlab.com/dslackw/slpkg
Usage
-----
@ -51,6 +72,7 @@ Usage
update Update the package lists.
upgrade Upgrade all the packages.
check-updates Check for news on ChangeLog.txt.
configs Edit the configuration file.
clean-logs Clean dependencies log tracking.
clean-tmp Deletes all the downloaded sources.
-b, build <packages> Build only the packages.
@ -112,7 +134,7 @@ Usage
Do you want to continue (y/N)?:
$ slpkg dependees vlc
$ slpkg dependees vlc --full-reverse
The list below shows the packages that dependees 'vlc' files:
Collecting the data...

View file

@ -4,7 +4,7 @@
slpkg - [OPTIONS] [COMMAND] <packages>
.SH SYNAPSES
.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,
--reinstall, --skip-installed, --full-reverse, --search
.SH DESCRIPTION
@ -32,6 +32,11 @@ check-updates
Check if there is any news on the SlackBuild's ChangeLog.txt file.
.RE
.P
configs
.RS
Edit the configuration /etc/slpkg/slpkg.toml file.
.RE
.P
clean-logs
.RS
Cleans dependencies log tracking. After that procedure you should remove dependencies by hand.

View file

@ -1,6 +1,6 @@
[metadata]
name = slpkg
version = 4.4.0
version = 4.4.1
license_file = LICENSE
author = Dimitris Zlatanidis
author_email = d.zlatanidis@gmail.com

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import tomli

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import urllib3

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import hashlib
from slpkg.views.views import ViewMessage
@ -30,7 +29,7 @@ class Md5sum:
view.question()
@staticmethod
def read_file(filename: str):
def read_file(filename: str) -> bytes:
""" Reads the text file. """
with open(filename, 'rb') as f:
return f.read()

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from slpkg.views.views import ViewMessage
from slpkg.models.models import LogsDependencies
from slpkg.models.models import session as Session

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import tomli
import platform
@ -9,6 +8,20 @@ import platform
from dataclasses import dataclass
class LoadConfigs:
@staticmethod
def file(path: str, file: str) -> dict:
try:
""" Load the configs from the file. """
config_file: str = f'{path}/{file}.toml'
if os.path.isfile(config_file):
with open(config_file, 'rb') as conf:
return tomli.load(conf)
except (KeyError, tomli.TOMLDecodeError) as error:
raise SystemExit(f"\nError: {error}: in the configuration file "
"'/etc/slpkg/slpkg.toml'\n")
@dataclass
class Configs:
""" Default configurations. """
@ -54,64 +67,56 @@ class Configs:
# Dialog utility
dialog: str = True
# Overwrite with user configuration.
config_file: str = f'{etc_path}/{prog_name}.toml'
if os.path.isfile(config_file):
with open(config_file, 'rb') as conf:
configs = tomli.load(conf)
load = LoadConfigs()
configs = load.file(etc_path, prog_name)
config = configs['configs']
try:
config = configs['configs']
if config:
# OS architecture by default
os_arch: str = config['os_arch']
# OS architecture by default
os_arch: str = config['os_arch']
# All necessary paths
tmp_slpkg: str = config['tmp_slpkg']
build_path: str = config['build_path']
download_only: str = config['download_only']
sbo_repo_path: str = config['sbo_repo_path']
# All necessary paths
tmp_slpkg: str = config['tmp_slpkg']
build_path: str = config['build_path']
download_only: str = config['download_only']
sbo_repo_path: str = config['sbo_repo_path']
# Database name
database: str = config['database']
# Database name
database: str = config['database']
# SBo repository details
sbo_repo_url: str = config['sbo_repo_url']
sbo_txt: str = config['sbo_txt']
sbo_chglog_txt: str = config['sbo_chglog_txt']
sbo_tar_suffix: str = config['sbo_tar_suffix']
sbo_repo_tag: str = config['sbo_repo_tag']
# SBo repository details
sbo_repo_url: str = config['sbo_repo_url']
sbo_txt: str = config['sbo_txt']
sbo_chglog_txt: str = config['sbo_chglog_txt']
sbo_tar_suffix: str = config['sbo_tar_suffix']
sbo_repo_tag: str = config['sbo_repo_tag']
# Slackware commands
installpkg: str = config['installpkg']
reinstall: str = config['reinstall']
removepkg: str = config['removepkg']
# Slackware commands
installpkg: str = config['installpkg']
reinstall: str = config['reinstall']
removepkg: str = config['removepkg']
# Cli menu colors configs
colors: str = config['colors']
# Cli menu colors configs
colors: str = config['colors']
# Wget options
wget_options: str = config['wget_options']
# Wget options
wget_options: str = config['wget_options']
# Dialog utility
dialog: str = config['dialog']
# Dialog utility
dialog: str = config['dialog']
# Creating the paths if not exists
paths = [tmp_slpkg,
build_path,
download_only,
sbo_repo_path,
lib_path,
etc_path,
db_path]
except KeyError as error:
print(f"Error: {error}: in the configuration file "
"'/etc/slpkg/slpkg.toml'\n")
# Creating the paths if not exists
paths = [tmp_slpkg,
build_path,
download_only,
sbo_repo_path,
lib_path,
etc_path,
db_path]
for path in paths:
if not os.path.isdir(path):
os.makedirs(path)
for path in paths:
if not os.path.isdir(path):
os.makedirs(path)
@classmethod
def colour(cls):

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from slpkg.configs import Configs
from slpkg.models.models import SBoTable
from slpkg.models.models import session as Session
@ -57,7 +56,7 @@ class CreateData:
self.session.commit()
@staticmethod
def read_file(file: str):
def read_file(file: str) -> list:
""" Reads the text file. """
with open(file, 'r', encoding='utf-8') as f:
return f.readlines()

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from slpkg.configs import Configs
from slpkg.queries import SBoQueries

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from slpkg.queries import SBoQueries

View file

@ -11,15 +11,16 @@ locale.setlocale(locale.LC_ALL, '')
class DialogBox:
""" Class for dialog box"""
def __init__(self):
self.configs = Configs()
self.d = Dialog(dialog="dialog")
self.d.set_background_title(f'{self.configs.prog_name} {Version().version} - Software Package Manager')
def checklist(self, text, title, height, width, list_height, choices, packages):
def checklist(self, text: str, title: str, height: int, width: int,
list_height: int, choices: list, packages: list):
""" Display a checklist box. """
if self.configs.dialog:
code, tags = self.d.checklist(text, title=title, height=height, width=width,
list_height=list_height, choices=choices)
@ -28,3 +29,24 @@ class DialogBox:
tags = packages
return code, tags
def mixedform(self, text: str, title: str, elements: list, height: int, width: int):
""" Display a mixedform box. """
if self.configs.dialog:
code, tags = self.d.mixedform(text=text, title=title, elements=elements,
height=height, width=width, help_button=True)
else:
code = False
tags = elements
return code, tags
def msgbox(self, text: str, height: int, width: int):
""" Display a message box. """
if self.configs.dialog:
self.d.msgbox(text, height, width)
def textbox(self, text: str, height: int, width: int):
""" Display a text box. """
if self.configs.dialog:
self.d.textbox(text, height, width)

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from slpkg.downloader import Wget
from slpkg.configs import Configs
from slpkg.queries import SBoQueries

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import subprocess
from slpkg.configs import Configs

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
from slpkg.configs import Configs

87
slpkg/form_configs.py Normal file
View file

@ -0,0 +1,87 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
from slpkg.configs import Configs
from slpkg.configs import LoadConfigs
from slpkg.dialog_box import DialogBox
class FormConfigs:
def __init__(self):
self.orig_configs = None
self.configs = Configs()
self.load_configs = LoadConfigs()
self.dialog = DialogBox()
self.config_file = f'{self.configs.etc_path}/{self.configs.prog_name}.toml'
def edit(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.
configs = self.load_configs.file(self.configs.etc_path,
self.configs.prog_name)
# 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')
]
height = 28
width = 70
text = f'Edit the configuration file: {config_file}'
title = ' Configuration File '
code, tags = self.dialog.mixedform(text, title, elements, height, width)
os.system('clear')
check = self.check_configs(configs, tags)
if code == 'ok' and check:
self.write_file(configs, tags)
elif not check:
self.edit()
elif code == 'help':
self.help()
def help(self):
""" Load the configuration file on a text box. """
self.read_file()
self.dialog.textbox(self.config_file, 40, 60)
self.edit()
def check_configs(self, configs: dict, tags: list) -> bool:
""" Check for true of false values. """
for key, value in zip(configs['configs'].keys(), tags):
if key in ['colors', 'dialog'] and value not in ['true', 'false']:
self.dialog.msgbox(f"\nError value for {key}. It must be 'true' or 'false'\n", height=7, width=60)
return False
return True
def read_file(self):
""" Read the original config file. """
with open(self.config_file, 'r') as toml_file:
self.orig_configs = toml_file.readlines()
def write_file(self, configs: dict, tags: list):
""" Write the new values to the config file. """
self.read_file()
with open(self.config_file, 'w') as patch_toml:
for line in self.orig_configs:
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)

View file

@ -17,6 +17,7 @@ from slpkg.dialog_box import DialogBox
from slpkg.views.version import Version
from slpkg.download_only import Download
from slpkg.slackbuild import Slackbuilds
from slpkg.form_configs import FormConfigs
from slpkg.check_updates import CheckUpdates
from slpkg.find_installed import FindInstalled
from slpkg.views.view_package import ViewPackage
@ -35,6 +36,7 @@ class Argparse:
self.utils = Utilities()
self.usage = Usage()
self.check = Check()
self.form_configs = FormConfigs()
if len(self.args) == 0:
self.usage.help_short()
@ -49,7 +51,8 @@ class Argparse:
self.flag_full_reverse = '--full-reverse'
self.flag_search = '--search'
if not self.configs.dialog and self.flag_search in self.args:
if (not self.configs.dialog and self.flag_search in self.args or
not self.configs.dialog and 'configs' in self.args):
print("Error: You should enable the dialog "
"in the '/etc/slpkg/' folder.\n")
self.usage.help(1)
@ -83,25 +86,24 @@ class Argparse:
title = f' Choose packages you want to {method} '
repo_packages = SBoQueries('').sbos()
if method == 'remove':
# Grab all the installed packages
installed = os.listdir(self.configs.log_packages)
# Grab all the installed packages
installed = os.listdir(self.configs.log_packages)
if method in ['remove', 'find']:
for package in installed:
inst_pkg_name = self.utils.split_installed_pkg(package)[0]
name = self.utils.split_installed_pkg(package)[0]
version = self.utils.split_installed_pkg(package)[1]
if package.endswith(self.configs.sbo_repo_tag):
for pkg in packages:
if pkg in inst_pkg_name:
repo_ver = SBoQueries(inst_pkg_name).version()
choices += [(inst_pkg_name, repo_ver, False)]
if pkg in name:
choices += [(name, version, False)]
else:
for package in repo_packages:
for pkg in packages:
if pkg in package:
repo_ver = SBoQueries(package).version()
if method == 'upgrade':
@ -185,6 +187,35 @@ class Argparse:
raise SystemExit()
self.usage.help(1)
def edit_configs(self):
if len(self.args) == 1 and not self.flags:
self.form_configs.edit()
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):
if [f for f in self.flags if f not in [self.flag_yes,
self.flag_jobs,
@ -274,9 +305,16 @@ class Argparse:
self.usage.help(1)
def find(self):
if len(self.args) >= 2 and not self.flags:
if [f for f in self.flags if f not in [self.flag_search]]:
self.usage.help(1)
if len(self.args) >= 2:
packages = list(set(self.args[1:]))
if '--search' in self.flags:
packages = self.choose_packages(packages,
Argparse.find.__name__)
self.check.database()
find = FindInstalled()
@ -360,29 +398,6 @@ class Argparse:
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 main():
args = sys.argv
@ -398,6 +413,7 @@ def main():
'update': argparse.update,
'upgrade': argparse.upgrade,
'check-updates': argparse.check_updates,
'configs': argparse.edit_configs,
'clean-logs': argparse.clean_logs,
'clean-tmp': argparse.clean_tmp,
'build': argparse.build,

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from dataclasses import dataclass
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from slpkg.configs import Configs
from slpkg.blacklist import Blacklist
from slpkg.models.models import SBoTable

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from slpkg.queries import SBoQueries
from slpkg.configs import Configs

View file

@ -75,7 +75,7 @@ class Slackbuilds:
self.install_order.extend(self.dependencies)
def choose_dependencies(self, dependencies):
def choose_dependencies(self, dependencies: list):
""" Choose packages for install. """
height = 10
width = 70

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from slpkg.configs import Configs
from slpkg.dependencies import Requires
@ -13,7 +12,7 @@ class Tracking:
self.configs = Configs
self.colors = self.configs.colour
def packages(self, packages):
def packages(self, packages: list):
""" Prints the packages dependencies. """
color = self.colors()
cyan = color['cyan']

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
from os import path
@ -18,7 +17,7 @@ from slpkg.models.models import session as Session
class UpdateRepository:
""" Deletes and install the data. """
def __init__(self, flags):
def __init__(self, flags: list):
self.flags = flags
self.configs = Configs
self.session = Session

View file

@ -1,8 +1,8 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import tomli
import shutil
import tarfile
@ -22,6 +22,7 @@ class Utilities:
pkg = self.split_installed_pkg(package)[0]
if pkg == name and self.configs.sbo_repo_tag in package and pkg not in self.black.get():
return package
return ''
@staticmethod
def untar_archive(path: str, archive: str, ext_path: str):

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from slpkg.configs import Configs
@ -21,12 +20,13 @@ class Usage:
""" Prints the short menu. """
args = (
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' 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'\n 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}] [-f, find, -w, view, -s, search, -e, dependees] <packages>\n'
f' slpkg [{self.cyan}COMMAND{self.endc}] [-t, tracking] <packages>\n'
f' 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'
" \nIf you need more information please try 'slpkg --help'.")
print(args)
@ -42,6 +42,7 @@ class Usage:
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}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-tmp{self.endc} Delete all the downloaded sources.\n'
f' {self.cyan}-b, build{self.endc} <packages> Build only the packages.\n'
@ -63,7 +64,8 @@ class Usage:
f' {self.yellow}--search{self.endc} Search packages from the repository.\n'
'\n -h, --help Show this message and exit.\n'
' -v, --version Print version and exit.\n'
'\nEdit the configuration file in the /etc/slpkg/slpkg.toml.\n'
'\nEdit the configuration file in the /etc/slpkg/slpkg.toml \n'
"or run 'slpkg configs'.\n"
'If you need more information try to use slpkg manpage.')
print(args)

View file

@ -1,12 +1,11 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
class Version:
""" Print the version. """
def __init__(self):
self.version_info = (4, 4, 0)
self.version_info = (4, 4, 1)
self.version = '{0}.{1}.{2}'.format(*self.version_info)
self.license = 'MIT License'
self.author = 'Dimitris Zlatanidis (dslackw)'

View file

@ -1,7 +1,6 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import urllib3
from slpkg.configs import Configs

View file

@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import os
from typing import Any
from slpkg.configs import Configs
from slpkg.queries import SBoQueries
@ -65,7 +66,7 @@ class ViewMessage:
version = SBoQueries(sbo).version()
self._view_download(sbo, version)
def remove_packages(self, packages: list):
def remove_packages(self, packages: list) -> Any:
""" View remove packages. """
slackbuilds, dependencies, deps = [], [], []
for pkg in packages:
@ -100,7 +101,7 @@ class ViewMessage:
return self.installed_packages, dependencies
def choose_dependencies_for_remove(self, dependencies):
def choose_dependencies_for_remove(self, dependencies: list) -> list:
""" Choose packages for remove. """
height = 10
width = 70