Merge branch 'develop'

This commit is contained in:
Dimitris Zlatanidis 2022-12-08 19:50:40 +02:00
commit dbeb46b2ab
30 changed files with 290 additions and 235 deletions

View file

@ -1,3 +1,9 @@
4.3.5 - 07/12/2022
Updated:
- Code style
Fixed:
- Flags parameter
4.3.4 - 02/12/2022
Updated:
- Remove dataclasses and switch to __init__

View file

@ -30,8 +30,8 @@ Install from the official third-party `SBo repository <https://slackbuilds.org/r
.. code-block:: bash
$ tar xvf slpkg-4.3.4.tar.gz
$ cd slpkg-4.3.4
$ tar xvf slpkg-4.3.5.tar.gz
$ cd slpkg-4.3.5
$ ./install.sh
@ -74,6 +74,40 @@ Usage
If you need more information try to use slpkg manpage.
$ slpkg install Flask
The following packages will be installed or upgraded:
[ install ] -> Flask-2.1.2
Dependencies:
[ install ] -> python-zipp-3.8.0
[ install ] -> python-importlib_metadata-4.10.1
[ install ] -> click-8.1.3
[ install ] -> python3-itsdangerous-2.1.2
[ install ] -> werkzeug-2.1.2
Total 6 packages will be installed and 0 will be upgraded.
Do you want to continue [y/N]:
$ slpkg remove Flask
The following packages will be removed:
[ delete ] -> Flask-2.1.2-x86_64-1_SBo
Dependencies:
[ delete ] -> python-zipp-3.8.0-x86_64-2_SBo
[ delete ] -> python-importlib_metadata-4.10.1-x86_64-1_SBo
[ delete ] -> click-8.1.3-x86_64-1_SBo
[ delete ] -> python3-itsdangerous-2.1.2-x86_64-1_SBo
[ delete ] -> werkzeug-2.1.2-x86_64-1_SBo
Total 6 packages will be removed.
Do you want to continue [y/N]:
Configuration files
-------------------

View file

@ -24,7 +24,7 @@
__version() {
# Grab version from __metadata_.py file
cat setup.cfg | grep "version =" | tr -d [[:space:]] | cut -c9-13 | tr , .
cat setup.cfg | grep "version =" | tr -d "[:space:]" | cut -c9-13 | tr , .
}
PRGNAM=slpkg

View file

@ -1,2 +1,3 @@
SQLAlchemy>=1.4.36
toml>=0.10.2
setuptools~=60.2.0

View file

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

View file

@ -24,7 +24,7 @@
__version() {
# Grab version from __metadata_.py file
cat ../setup.cfg | grep "version =" | tr -d [[:space:]] | cut -c9-13 | tr , .
cat ../setup.cfg | grep "version =" | tr -d "[:space:]" | cut -c9-13 | tr , .
}
cd $(dirname $0) ; CWD=$(pwd)

View file

@ -9,10 +9,10 @@ from slpkg.configs import Configs
class Blacklist:
''' Reads and returns the blacklist. '''
""" Reads and returns the blacklist. """
def __init__(self):
self.configs: str = Configs
self.configs = Configs
def get(self):
file = f'{self.configs.etc_path}/blacklist.toml'

View file

@ -9,10 +9,10 @@ from slpkg.configs import Configs
class CheckUpdates:
''' Check for changes in the ChangeLog file. '''
""" Check for changes in the ChangeLog file. """
def __init__(self):
self.configs: str = Configs
self.configs = Configs
def updates(self):
local_date = 0

View file

@ -9,13 +9,14 @@ from slpkg.blacklist import Blacklist
class Check:
''' Some checks before proceed. '''
""" Some checks before proceed. """
def __init__(self):
self.configs: str = Configs
self.configs = Configs
def exists(self, slackbuilds: list):
''' Checking if the slackbuild exists in the repository. '''
@staticmethod
def exists(slackbuilds: list):
""" Checking if the slackbuild exists in the repository. """
packages = []
for sbo in slackbuilds:
@ -26,8 +27,9 @@ class Check:
raise SystemExit(f'\nPackages \'{", ".join(packages)}\' '
'does not exists.\n')
def unsupported(self, slackbuilds: list):
''' Checking for unsupported slackbuilds. '''
@staticmethod
def unsupported(slackbuilds: list):
""" Checking for unsupported slackbuilds. """
for sbo in slackbuilds:
sources = SBoQueries(sbo).sources()
@ -35,7 +37,7 @@ class Check:
raise SystemExit(f"\nPackage '{sbo}' unsupported by arch.\n")
def installed(self, slackbuilds: list):
''' Checking for installed packages. '''
""" Checking for installed packages. """
found, not_found = [], []
for sbo in slackbuilds:
@ -55,7 +57,7 @@ class Check:
return found
def blacklist(self, slackbuilds: list):
''' Checking if the packages are blacklisted. '''
""" Checking if the packages are blacklisted. """
packages = []
black = Blacklist()
@ -70,7 +72,7 @@ class Check:
f'{self.configs.etc_path} folder.\n')
def database(self):
''' Checking for empty table '''
""" Checking for empty table """
db = f'{self.configs.db_path}/{self.configs.database}'
if not SBoQueries('').names() or not os.path.isfile(db):
raise SystemExit('\nYou need to update the package lists first.\n'

View file

@ -8,10 +8,10 @@ from slpkg.views.views import ViewMessage
class Md5sum:
''' Checksum the sources. '''
""" Checksum the sources. """
def __init__(self, flags):
self.flags: str = flags
self.flags = flags
def check(self, path: str, source: str, checksum: str, name: str):
filename = f'{path}/{source.split("/")[-1]}'
@ -25,9 +25,10 @@ class Md5sum:
print('Found:', file_check)
print(f'\nMD5SUM check for {name} FAILED.')
view = ViewMessage()
view.question(self.flags)
view = ViewMessage(self.flags)
view.question()
def read_file(self, filename: str):
@staticmethod
def read_file(filename: str):
with open(filename, 'rb') as f:
return f.read()

View file

@ -8,11 +8,11 @@ from slpkg.models.models import session as Session
class CleanLogsDependencies:
''' Cleans the logs from packages. '''
""" Cleans the logs from packages. """
def __init__(self, flags):
self.flags: str = flags
self.session: str = Session
self.flags = flags
self.session = Session
def clean(self):
dependencies = self.session.query(

View file

@ -11,11 +11,11 @@ from dataclasses import dataclass
@dataclass
class Configs:
""" Default configurations. """
# Programme name
prog_name: str = 'slpkg'
''' Default configurations. '''
# OS architecture by default
os_arch: str = platform.machine()
@ -51,7 +51,7 @@ class Configs:
# Wget options
wget_options = '-c -N'
''' Overwrite with user configuration. '''
# 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:
@ -93,7 +93,7 @@ class Configs:
except KeyError:
pass
# Creating the paths if they doesn't exists
# Creating the paths if not exists
paths = [tmp_slpkg,
build_path,
download_only,
@ -109,26 +109,26 @@ class Configs:
@classmethod
def colour(cls):
color = {
'BOLD': '',
'RED': '',
'GREEN': '',
'YELLOW': '',
'CYAN': '',
'BLUE': '',
'GREY': '',
'ENDC': ''
'bold': '',
'red': '',
'green': '',
'yellow': '',
'cyan': '',
'blue': '',
'grey': '',
'endc': ''
}
if cls.colors:
color = {
'BOLD': '\033[1m',
'RED': '\x1b[91m',
'GREEN': '\x1b[32m',
'YELLOW': '\x1b[93m',
'CYAN': '\x1b[96m',
'BLUE': '\x1b[94m',
'GREY': '\x1b[38;5;247m',
'ENDC': '\x1b[0m'
'bold': '\033[1m',
'red': '\x1b[91m',
'green': '\x1b[32m',
'yellow': '\x1b[93m',
'cyan': '\x1b[96m',
'blue': '\x1b[94m',
'grey': '\x1b[38;5;247m',
'endc': '\x1b[0m'
}
return color

View file

@ -8,11 +8,11 @@ from slpkg.models.models import session as Session
class CreateData:
''' Reads the SLACKBUILDS.TXT file and inserts them into the database. '''
""" Reads the SLACKBUILDS.TXT file and inserts them into the database. """
def __init__(self):
self.configs: str = Configs
self.session: str = Session
self.configs = Configs
self.session = Session
def insert_sbo_table(self):
sbo_tags = [
@ -28,8 +28,7 @@ class CreateData:
'SLACKBUILD SHORT DESCRIPTION:'
]
sbo_file = self.read_file(
f'{self.configs.sbo_repo_path}/SLACKBUILDS.TXT')
sbo_file = self.read_file(f'{self.configs.sbo_repo_path}/SLACKBUILDS.TXT')
cache = [] # init cache
@ -56,6 +55,7 @@ class CreateData:
self.session.commit()
def read_file(self, file: str):
@staticmethod
def read_file(file: str):
with open(file, 'r', encoding='utf-8') as f:
return f.readlines()

View file

@ -6,8 +6,8 @@ from slpkg.queries import SBoQueries
class Requires:
''' Creates a list of dependencies with
the right order to install. '''
""" Creates a list of dependencies with
the right order to install. """
def __init__(self, name):
self.name: str = name

View file

@ -10,12 +10,12 @@ from slpkg.models.models import session as Session
class Download:
''' Download the slackbuilds with the sources only. '''
""" Download the slackbuilds with the sources only. """
def __init__(self, flags):
self.flags: list = flags
self.configs: str = Configs
self.session: str = Session
self.configs = Configs
self.session = Session
def packages(self, slackbuilds: list):
view = ViewMessage(self.flags)

View file

@ -8,7 +8,7 @@ from slpkg.configs import Configs
class Wget:
''' Wget donwloader. '''
""" Wget downloader. """
def __init__(self):
self.wget_options: str = Configs.wget_options

View file

@ -8,10 +8,10 @@ from slpkg.configs import Configs
class FindInstalled:
''' Find installed packages. '''
""" Find installed packages. """
def __init__(self):
self.configs: str = Configs
self.configs = Configs
colors = self.configs.colour
self.color = colors()
@ -30,6 +30,6 @@ class FindInstalled:
def matched(self, matching: list):
if matching:
for package in matching:
print(f'{self.color["CYAN"]}{package}{self.color["ENDC"]}')
print(f'{self.color["cyan"]}{package}{self.color["endc"]}')
else:
print('\nDoes not match any package.\n')

View file

@ -25,19 +25,15 @@ class Argparse:
def __init__(self, args):
self.args: list = args
self.configs = Configs
self.usage = Usage()
self.flag()
self.check = Check()
if len(self.args) == 0:
self.usage.help_short()
self.check.blacklist(self.args)
def flag(self):
self.flags = []
self.check = Check()
self.configs = Configs
self.check.blacklist(self.args)
self.options = ['--yes',
'--jobs',

View file

@ -22,7 +22,7 @@ Base = declarative_base()
@dataclass
class SBoTable(Base):
''' The main table for the SBo repository. '''
""" The main table for the SBo repository. """
__tablename__ = 'sbotable'
@ -41,7 +41,7 @@ class SBoTable(Base):
@dataclass
class LogsDependencies(Base):
''' The table that stores the dependencies after installing a package. '''
""" The table that stores the dependencies after installing a package. """
__tablename__ = 'logsdependencies'

View file

@ -9,12 +9,12 @@ from slpkg.models.models import session as Session
class SBoQueries:
''' Queries class for the sbo repository. '''
""" Queries class for the sbo repository. """
def __init__(self, name):
self.name: str = name
self.session: str = Session
self.configs: str = Configs
self.name = name
self.session = Session
self.configs = Configs
self.black = Blacklist()
if self.name in self.black.get():

View file

@ -11,19 +11,18 @@ from slpkg.models.models import session as Session
class RemovePackages:
''' Removes installed packages. '''
""" Removes installed packages. """
def __init__(self, packages, flags):
self.packages: str = packages
self.flags: list = flags
self.session: str = Session
self.configs: str = Configs
def remove(self):
''' Removes package with dependencies. '''
self.packages = packages
self.flags = flags
self.session = Session
self.configs = Configs
self.installed_packages = []
self.dependencies = []
def remove(self):
""" Removes package with dependencies. """
view = ViewMessage(self.flags)
self.installed_packages, self.dependencies = view.remove_packages(
@ -38,20 +37,20 @@ class RemovePackages:
self.delete_deps_logs()
def remove_packages(self):
''' Run Slackware command to remove the packages. '''
""" Run Slackware command to remove the packages. """
for package in self.installed_packages:
command = f'{self.configs.removepkg} {package}'
subprocess.call(command, shell=True)
def delete_main_logs(self):
''' Deletes main packages from logs. '''
""" Deletes main packages from logs. """
for pkg in self.packages:
self.session.query(LogsDependencies).filter(
LogsDependencies.name == pkg).delete()
self.session.commit()
def delete_deps_logs(self):
''' Deletes depends packages from logs. '''
""" Deletes depends packages from logs. """
for pkg in self.dependencies[0].split():
self.session.query(LogsDependencies).filter(
LogsDependencies.name == pkg).delete()

View file

@ -7,15 +7,15 @@ from slpkg.configs import Configs
class SearchPackage:
''' Search slackbuilds from the repository. '''
""" Search slackbuilds from the repository. """
def __init__(self):
self.colors: dict = Configs.colour
self.colors = Configs.colour
def package(self, packages):
color = self.colors()
CYAN = color['CYAN']
ENDC = color['ENDC']
cyan = color['cyan']
endc = color['endc']
matching = 0
names = SBoQueries('').names()
@ -29,6 +29,6 @@ class SearchPackage:
matching += 1
desc = SBoQueries(name).description().replace(name, '')
print(f'{name}-{SBoQueries(name).version()}'
f'{CYAN}{desc}{ENDC}')
f'{cyan}{desc}{endc}')
if not matching:
print('\nDoes not match any package.\n')

View file

@ -19,20 +19,21 @@ from slpkg.models.models import session as Session
class Slackbuilds:
''' Download build and install the SlackBuilds. '''
""" Download build and install the SlackBuilds. """
def __init__(self, slackbuilds, flags, install):
self.slackbuilds: str = slackbuilds
self.flags: list = flags
self.install: bool = install
self.session: str = Session
self.utils: str = Utilities()
self.configs: str = Configs
def execute(self):
''' Starting build or install the slackbuilds. '''
self.slackbuilds = slackbuilds
self.flags = flags
self.install = install
self.session = Session
self.utils = Utilities()
self.configs = Configs
self.install_order = []
self.dependencies = []
self.sbos = {}
def execute(self):
""" Starting build or install the slackbuilds. """
self.creating_dictionary()
if '--resolve-off' not in self.flags:
@ -44,7 +45,7 @@ class Slackbuilds:
self.download_slackbuilds_and_build()
def view_before_build(self):
''' View slackbuilds before proceed. '''
""" View slackbuilds before proceed. """
view = ViewMessage(self.flags)
if self.install:
@ -57,13 +58,12 @@ class Slackbuilds:
view.question()
def creating_dictionary(self):
''' Dictionary with the main slackbuilds and dependencies. '''
self.sbos = {}
""" Dictionary with the main slackbuilds and dependencies. """
for sbo in self.slackbuilds:
self.sbos[sbo] = Requires(sbo).resolve()
def creating_dependencies_for_build(self):
''' List with the dependencies. '''
""" List with the dependencies. """
for deps in self.sbos.values():
for dep in deps:
@ -80,11 +80,11 @@ class Slackbuilds:
self.install_order.extend(self.dependencies)
def creating_main_for_build(self):
''' List with the main slackbuilds. '''
""" List with the main slackbuilds. """
[self.install_order.append(main) for main in self.sbos.keys()]
def download_slackbuilds_and_build(self):
''' Downloads files and sources and starting the build. '''
""" Downloads files and sources and starting the build. """
wget = Wget()
for sbo in self.install_order:
@ -116,7 +116,7 @@ class Slackbuilds:
self.logging_installed_dependencies(sbo)
def patch_sbo_tag(self, sbo):
''' Patching SBo TAG from the configuration file. '''
""" Patching SBo TAG from the configuration file. """
sbo_script = f'{self.configs.build_path}/{sbo}/{sbo}.SlackBuild'
if os.path.isfile(sbo_script):
@ -130,7 +130,7 @@ class Slackbuilds:
script.write(line)
def logging_installed_dependencies(self, name: str):
''' Logging installed dependencies and used for remove. '''
""" Logging installed dependencies and used for remove. """
exist = self.session.query(LogsDependencies.name).filter(
LogsDependencies.name == name).first()
@ -149,19 +149,19 @@ class Slackbuilds:
self.session.commit()
def install_package(self, package: str):
''' Install the packages that before created in the tmp directory. '''
""" Install the packages that before created in the tmp directory. """
execute = self.configs.installpkg
if ('--reinstall' in self.flags and
self.utils.is_installed(package[:-4])):
execute = self.reinstall
execute = self.configs.reinstall
command = f'{execute} {self.configs.tmp_path}/{package}'
subprocess.call(command, shell=True)
def creating_package_for_install(self, name: str):
''' Creating a list with all the finished packages for
""" Creating a list with all the finished packages for
installation.
'''
"""
version = SBoQueries(name).version()
packages = []
@ -174,7 +174,7 @@ class Slackbuilds:
return max(packages)
def build_the_script(self, path: str, name: str):
''' Run the .SlackBuild script. '''
""" Run the .SlackBuild script. """
folder = f'{path}/{name}/'
slackbuild = f'./{name}.SlackBuild'
execute = folder + slackbuild
@ -187,13 +187,14 @@ class Slackbuilds:
if stdout > 0:
raise SystemExit(stdout)
def set_makeflags(self):
''' Set number of processors. '''
@staticmethod
def set_makeflags():
""" Set number of processors. """
cpus = multiprocessing.cpu_count()
os.environ['MAKEFLAGS'] = f'-j {cpus}'
def download_sources(self, name: str, sources: str):
''' Download the sources. '''
""" Download the sources. """
wget = Wget()
path = f'{self.configs.build_path}/{name}'

View file

@ -14,11 +14,11 @@ from slpkg.models.models import session as Session
class UpdateRepository:
''' Deletes and install the data. '''
""" Deletes and install the data. """
def __init__(self):
self.configs: str = Configs
self.session: str = Session
self.configs = Configs
self.session = Session
def sbo(self):
print('Updating the package list...\n')
@ -36,8 +36,9 @@ class UpdateRepository:
data = CreateData()
data.insert_sbo_table()
def delete_file(self, dir: str, txt_file: str):
file = f'{dir}/{txt_file}'
@staticmethod
def delete_file(folder: str, txt_file: str):
file = f'{folder}/{txt_file}'
if path.exists(file):
os.remove(file)

View file

@ -10,13 +10,13 @@ from slpkg.blacklist import Blacklist
class Upgrade:
''' Upgrade the installed packages. '''
""" Upgrade the installed packages. """
def __init__(self):
self.configs: str = Configs
self.configs = Configs
def packages(self):
''' Compares version of packages and returns the maximum. '''
""" Compares version of packages and returns the maximum. """
print("Do not forget to run 'slpkg update' before.")
repo_packages = SBoQueries('').names()
@ -28,8 +28,7 @@ class Upgrade:
and inst_pkg_name not in black):
if inst_pkg_name in repo_packages:
installed_ver = pkg.replace(f'{inst_pkg_name}-',
'').split('-')[0]
installed_ver = pkg.replace(f'{inst_pkg_name}-', '').split('-')[0]
repo_ver = SBoQueries(inst_pkg_name).version()
if LooseVersion(repo_ver) > LooseVersion(installed_ver):

View file

@ -13,35 +13,39 @@ from slpkg.configs import Configs
class Utilities:
def __init__(self):
self.configs: str = Configs
self.configs = Configs
def untar_archive(self, path: str, archive: str, ext_path: str):
''' Untar the file to the build folder. '''
def is_installed(self, package: str):
""" Returns True if a package is installed. """
for pkg in os.listdir(self.configs.log_packages):
if package in pkg:
return pkg
@staticmethod
def untar_archive(path: str, archive: str, ext_path: str):
""" Untar the file to the build folder. """
tar_file = f'{path}/{archive}'
untar = tarfile.open(tar_file)
untar.extractall(ext_path)
untar.close()
def is_installed(self, package: str):
''' Returns True if a package is installed. '''
for pkg in os.listdir(self.configs.log_packages):
if package in pkg:
return pkg
def remove_file_if_exists(self, path: str, file: str):
''' Clean the the old files. '''
@staticmethod
def remove_file_if_exists(path: str, file: str):
""" Clean the old files. """
archive = f'{path}/{file}'
if os.path.isfile(archive):
os.remove(archive)
def remove_folder_if_exists(self, path: str, folder: str):
''' Clean the the old folders. '''
@staticmethod
def remove_folder_if_exists(path: str, folder: str):
""" Clean the old folders. """
directory = f'{path}/{folder}'
if os.path.isdir(directory):
shutil.rmtree(directory)
def create_folder(self, path: str, folder: str):
''' Creates folder. '''
@staticmethod
def create_folder(path: str, folder: str):
""" Creates folder. """
directory = f'{path}/{folder}'
if not os.path.isdir(directory):
os.makedirs(directory)

View file

@ -11,52 +11,52 @@ class Usage:
colors = Configs.colour
color = colors()
self.BOLD = color['BOLD']
self.RED = color['RED']
self.CYAN = color['CYAN']
self.YELLOW = color['YELLOW']
self.ENDC = color['ENDC']
self.bold = color['bold']
self.red = color['red']
self.cyan = color['cyan']
self.yellow = color['yellow']
self.endc = color['endc']
def help_short(self):
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, --skip-installed]\n'
f' slpkg [{self.CYAN}COMMAND{self.ENDC}] [update, upgrade, check-updates, clean-logs, clean-tmp]\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'
" \nIf you need more information please try 'slpkg --help'.")
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, --skip-installed]\n'
f' slpkg [{self.cyan}COMMAND{self.endc}] [update, upgrade, check-updates, clean-logs, clean-tmp]\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'
" \nIf you need more information please try 'slpkg --help'.")
print(args)
raise SystemExit()
def help(self, status: int):
args = [f'{self.BOLD}USAGE:{self.ENDC} {Configs.prog_name} [{self.YELLOW}OPTIONS{self.ENDC}] [{self.CYAN}COMMAND{self.ENDC}] <packages>\n',
f'{self.BOLD}DESCRIPTION:{self.ENDC}',
' Packaging tool that interacts with the SBo repository.\n',
f'{self.BOLD}COMMANDS:{self.ENDC}',
f' {self.RED}update{self.ENDC} Update the package lists.',
f' {self.CYAN}upgrade{self.ENDC} Upgrade all the packages.',
f' {self.CYAN}check-updates{self.ENDC} Check for news on ChangeLog.txt.',
f' {self.CYAN}clean-logs{self.ENDC} Clean dependencies log tracking.',
f' {self.CYAN}clean-tmp{self.ENDC} Delete all the downloaded sources.',
f' {self.CYAN}-b, build{self.ENDC} <packages> Build only the packages.',
f' {self.CYAN}-i, install{self.ENDC} <packages> Build and install the packages.',
f' {self.CYAN}-d, download{self.ENDC} <packages> Download only the scripts and sources.',
f' {self.CYAN}-r, remove{self.ENDC} <packages> Remove installed packages.',
f' {self.CYAN}-f, find{self.ENDC} <packages> Find installed packages.',
f' {self.CYAN}-w, view{self.ENDC} <packages> View packages from the repository.',
f' {self.CYAN}-s, search{self.ENDC} <packages> Search packages from the repository.\n',
f'{self.BOLD}OPTIONS:{self.ENDC}',
f' {self.YELLOW}--yes{self.ENDC} Answer Yes to all questions.',
f' {self.YELLOW}--jobs{self.ENDC} Set it for multicore systems.',
f' {self.YELLOW}--resolve-off{self.ENDC} Turns off dependency resolving.',
f' {self.YELLOW}--reinstall{self.ENDC} Upgrade packages of the same version.',
f' {self.YELLOW}--skip-installed{self.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.toml.',
'If you need more information try to use slpkg manpage.']
args = [
f'{self.bold}USAGE:{self.endc} {Configs.prog_name} [{self.yellow}OPTIONS{self.endc}] [{self.cyan}COMMAND{self.endc}] <packages>\n',
f'{self.bold}DESCRIPTION:{self.endc}',
' Packaging tool that interacts with the SBo repository.\n',
f'{self.bold}COMMANDS:{self.endc}',
f' {self.red}update{self.endc} Update the package lists.',
f' {self.cyan}upgrade{self.endc} Upgrade all the packages.',
f' {self.cyan}check-updates{self.endc} Check for news on ChangeLog.txt.',
f' {self.cyan}clean-logs{self.endc} Clean dependencies log tracking.',
f' {self.cyan}clean-tmp{self.endc} Delete all the downloaded sources.',
f' {self.cyan}-b, build{self.endc} <packages> Build only the packages.',
f' {self.cyan}-i, install{self.endc} <packages> Build and install the packages.',
f' {self.cyan}-d, download{self.endc} <packages> Download only the scripts and sources.',
f' {self.cyan}-r, remove{self.endc} <packages> Remove installed packages.',
f' {self.cyan}-f, find{self.endc} <packages> Find installed packages.',
f' {self.cyan}-w, view{self.endc} <packages> View packages from the repository.',
f' {self.cyan}-s, search{self.endc} <packages> Search packages from the repository.\n',
f'{self.bold}OPTIONS:{self.endc}',
f' {self.yellow}--yes{self.endc} Answer Yes to all questions.',
f' {self.yellow}--jobs{self.endc} Set it for multicore systems.',
f' {self.yellow}--resolve-off{self.endc} Turns off dependency resolving.',
f' {self.yellow}--reinstall{self.endc} Upgrade packages of the same version.',
f' {self.yellow}--skip-installed{self.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.toml.',
'If you need more information try to use slpkg manpage.']
for opt in args:
print(opt)

View file

@ -3,10 +3,10 @@
class Version:
''' Print the vesrsion. '''
""" Print the version. """
def __init__(self):
self.version_info: tuple = (4, 3, 4)
self.version_info: tuple = (4, 3, 5)
self.version: str = '{0}.{1}.{2}'.format(*self.version_info)
self.license: str = 'MIT License'
self.author: str = 'Dimitris Zlatanidis (dslackw)'

View file

@ -11,22 +11,23 @@ from slpkg.models.models import session as Session
class ViewPackage:
''' View the repository packages. '''
""" View the repository packages. """
def __init__(self):
self.session: str = Session
self.configs: str = Configs
self.colors: dict = self.configs.colour
self.session = Session
self.configs = Configs
self.colors = self.configs.colour
def package(self, packages):
""" View the packages from the repository. """
http = urllib3.PoolManager()
color = self.colors()
GREEN = color['GREEN']
BLUE = color['BLUE']
YELLOW = color['YELLOW']
CYAN = color['CYAN']
RED = color['RED']
ENDC = color['ENDC']
green = color['green']
blue = color['blue']
yellow = color['yellow']
cyan = color['cyan']
red = color['red']
endc = color['endc']
for package in packages:
info = self.session.query(
@ -59,20 +60,20 @@ class ViewPackage:
deps = (', '.join([f'{pkg} ({SBoQueries(pkg).version()})' for pkg in info[2].split()]))
print(f'Name: {GREEN}{info[0]}{ENDC}\n'
f'Version: {GREEN}{info[1]}{ENDC}\n'
f'Requires: {GREEN}{deps}{ENDC}\n'
f'Homepage: {BLUE}{homepage}{ENDC}\n'
f'Download SlackBuild: {BLUE}{self.configs.sbo_repo_url}/{info[9]}/{info[0]}{self.configs.sbo_tar_suffix}{ENDC}\n'
f'Download sources: {BLUE}{info[3]}{ENDC}\n'
f'Download_x86_64 sources: {BLUE}{info[4]}{ENDC}\n'
f'Md5sum: {YELLOW}{info[5]}{ENDC}\n'
f'Md5sum_x86_64: {YELLOW}{info[6]}{ENDC}\n'
f'Files: {GREEN}{info[7]}{ENDC}\n'
f'Description: {GREEN}{info[8]}{ENDC}\n'
f'Slackware: {CYAN}{self.configs.sbo_repo_url.split("/")[-1]}{ENDC}\n'
f'Category: {RED}{info[9]}{ENDC}\n'
f'SBo url: {BLUE}{self.configs.sbo_repo_url}/{info[9]}/{info[0]}{ENDC}\n'
f'Maintainer: {YELLOW}{maintainer}{ENDC}\n'
f'Email: {YELLOW}{email}{ENDC}\n'
f'\nREADME: {CYAN}{readme.data.decode()}{ENDC}')
print(f'Name: {green}{info[0]}{endc}\n'
f'Version: {green}{info[1]}{endc}\n'
f'Requires: {green}{deps}{endc}\n'
f'Homepage: {blue}{homepage}{endc}\n'
f'Download SlackBuild: {blue}{self.configs.sbo_repo_url}/{info[9]}/{info[0]}{self.configs.sbo_tar_suffix}{endc}\n'
f'Download sources: {blue}{info[3]}{endc}\n'
f'Download_x86_64 sources: {blue}{info[4]}{endc}\n'
f'Md5sum: {yellow}{info[5]}{endc}\n'
f'Md5sum_x86_64: {yellow}{info[6]}{endc}\n'
f'Files: {green}{info[7]}{endc}\n'
f'Description: {green}{info[8]}{endc}\n'
f'Slackware: {cyan}{self.configs.sbo_repo_url.split("/")[-1]}{endc}\n'
f'Category: {red}{info[9]}{endc}\n'
f'SBo url: {blue}{self.configs.sbo_repo_url}/{info[9]}/{info[0]}{endc}\n'
f'Maintainer: {yellow}{maintainer}{endc}\n'
f'Email: {yellow}{email}{endc}\n'
f'\nREADME: {cyan}{readme.data.decode()}{endc}')

View file

@ -12,17 +12,19 @@ from slpkg.models.models import session as Session
class ViewMessage:
''' Print some messages before. '''
""" Print some messages before. """
def __init__(self, flags):
self.flags: list = flags
self.configs: str = Configs
self.colors: dict = self.configs.colour
self.session: str = Session
self.utils: str = Utilities()
self.black: list = Blacklist()
self.flags = flags
self.configs = Configs
self.colors = self.configs.colour
self.session = Session
self.utils = Utilities()
self.black = Blacklist()
self.installed_packages = []
def build_packages(self, slackbuilds: list, dependencies: list):
""" View packages for build only. """
print('The following packages will be build:\n')
for sbo in slackbuilds:
@ -38,6 +40,7 @@ class ViewMessage:
self._view_total(slackbuilds, dependencies, option='build')
def install_packages(self, slackbuilds: list, dependencies: list):
""" View packages for install. """
print('The following packages will be installed or upgraded:\n')
for sbo in slackbuilds:
@ -53,6 +56,7 @@ class ViewMessage:
self._view_total(slackbuilds, dependencies, option='install')
def download_packages(self, slackbuilds: list):
""" View downloaded packages. """
print('The following packages will be downloaded:\n')
for sbo in slackbuilds:
@ -60,8 +64,8 @@ class ViewMessage:
self._view_download(sbo, version)
def remove_packages(self, packages: list):
""" View remove packages. """
print('The following packages will be removed:\n')
self.installed_packages = []
slackbuilds, dependencies, deps = [], [], []
for pkg in packages:
@ -88,33 +92,36 @@ class ViewMessage:
return self.installed_packages, dependencies
def _view_download(self, sbo: str, version: str):
""" View packages for download only. """
color = self.colors()
if self.utils.is_installed(f'{sbo}-'):
print(f'[{color["YELLOW"]} download {color["ENDC"]}] -> '
print(f'[{color["yellow"]} download {color["endc"]}] -> '
f'{sbo}-{version}')
else:
print(f'[{color["CYAN"]} download {color["ENDC"]}] -> '
print(f'[{color["cyan"]} download {color["endc"]}] -> '
f'{sbo}-{version}')
def _view_build(self, sbo: str, version: str):
""" View packages for build. """
color = self.colors()
if self.utils.is_installed(f'{sbo}-'):
print(f'[{color["YELLOW"]} build {color["ENDC"]}] -> '
print(f'[{color["yellow"]} build {color["endc"]}] -> '
f'{sbo}-{version}')
else:
print(f'[{color["CYAN"]} build {color["ENDC"]}] -> '
print(f'[{color["cyan"]} build {color["endc"]}] -> '
f'{sbo}-{version}')
def _view_install(self, sbo: str, version: str):
""" View the packages for install. """
color = self.colors()
installed = self.utils.is_installed(f'{sbo}-')
install, set_color = 'install', color['RED']
install, set_color = 'install', color['red']
if '--reinstall' in self.flags:
install, set_color = 'upgrade', color['YELLOW']
install, set_color = 'upgrade', color['yellow']
if installed and 'noarch' in installed:
self.configs.os_arch = 'noarch'
@ -124,16 +131,16 @@ class ViewMessage:
if '--reinstall' not in self.flags:
install = 'installed'
print(f'[{set_color} {install} {color["ENDC"]}] -> '
print(f'[{set_color} {install} {color["endc"]}] -> '
f'{sbo}-{version} {set_color}'
f'({installed.split(self.configs.os_arch)[0][:-1].split("-")[-1]})'
f'{color["ENDC"]}')
f'{color["endc"]}')
else:
print(f'[{color["CYAN"]} install {color["ENDC"]}] -> '
print(f'[{color["cyan"]} install {color["endc"]}] -> '
f'{sbo}-{version}')
def _view_installed_packages(self, name: str):
''' View and creates list with packages for remove. '''
""" View and creates list with packages for remove. """
installed = os.listdir(self.configs.log_packages)
color = self.colors()
@ -143,9 +150,10 @@ class ViewMessage:
self.configs.sbo_repo_tag in package and
black not in self.black.get()):
self.installed_packages.append(package)
print(f'[{color["RED"]} delete {color["ENDC"]}] -> {package}')
print(f'[{color["red"]} delete {color["endc"]}] -> {package}')
def _view_total(self, slackbuilds: list, dependencies: list, option: str):
""" View the status of the packages action. """
color = self.colors()
slackbuilds.extend(dependencies)
@ -158,28 +166,30 @@ class ViewMessage:
installed += 1
if option == 'install':
print(f'\n{color["GREY"]}Total {installed} packages will be '
f'installed and {upgraded} will be upgraded.{color["ENDC"]}')
print(f'\n{color["grey"]}Total {installed} packages will be '
f'installed and {upgraded} will be upgraded.{color["endc"]}')
elif option == 'build':
print(f'\n{color["GREY"]}Total {installed + upgraded} packages '
f'will be build.{color["ENDC"]}')
print(f'\n{color["grey"]}Total {installed + upgraded} packages '
f'will be build.{color["endc"]}')
elif option == 'remove':
print(f'\n{color["GREY"]}Total {installed + upgraded} packages '
f'will be removed.{color["ENDC"]}')
print(f'\n{color["grey"]}Total {installed + upgraded} packages '
f'will be removed.{color["endc"]}')
def logs_packages(self, dependencies):
""" View the logging packages. """
print('The following logs will be removed:\n')
color = self.colors()
for dep in dependencies:
print(f'{color["CYAN"]}{dep[0]}{color["ENDC"]}')
print(f'{color["cyan"]}{dep[0]}{color["endc"]}')
print(' |')
print(f' +->{color["CYAN"]} {dep[1]}{color["ENDC"]}\n')
print(f' +->{color["cyan"]} {dep[1]}{color["endc"]}\n')
print('Note: After cleaning you should remove them one by one.')
def question(self):
""" Manage to proceed. """
if '--yes' not in self.flags:
answer = input('\nDo you want to continue [y/N]: ')
print()