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 4.3.4 - 02/12/2022
Updated: Updated:
- Remove dataclasses and switch to __init__ - 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 .. code-block:: bash
$ tar xvf slpkg-4.3.4.tar.gz $ tar xvf slpkg-4.3.5.tar.gz
$ cd slpkg-4.3.4 $ cd slpkg-4.3.5
$ ./install.sh $ ./install.sh
@ -74,6 +74,40 @@ Usage
If you need more information try to use slpkg manpage. 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 Configuration files
------------------- -------------------

View file

@ -24,7 +24,7 @@
__version() { __version() {
# Grab version from __metadata_.py file # 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 PRGNAM=slpkg

View file

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

View file

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

View file

@ -24,7 +24,7 @@
__version() { __version() {
# Grab version from __metadata_.py file # 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) cd $(dirname $0) ; CWD=$(pwd)

View file

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

View file

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

View file

@ -9,13 +9,14 @@ from slpkg.blacklist import Blacklist
class Check: class Check:
''' Some checks before proceed. ''' """ Some checks before proceed. """
def __init__(self): def __init__(self):
self.configs: str = Configs self.configs = Configs
def exists(self, slackbuilds: list): @staticmethod
''' Checking if the slackbuild exists in the repository. ''' def exists(slackbuilds: list):
""" Checking if the slackbuild exists in the repository. """
packages = [] packages = []
for sbo in slackbuilds: for sbo in slackbuilds:
@ -26,8 +27,9 @@ class Check:
raise SystemExit(f'\nPackages \'{", ".join(packages)}\' ' raise SystemExit(f'\nPackages \'{", ".join(packages)}\' '
'does not exists.\n') 'does not exists.\n')
def unsupported(self, slackbuilds: list): @staticmethod
''' Checking for unsupported slackbuilds. ''' def unsupported(slackbuilds: list):
""" Checking for unsupported slackbuilds. """
for sbo in slackbuilds: for sbo in slackbuilds:
sources = SBoQueries(sbo).sources() sources = SBoQueries(sbo).sources()
@ -35,7 +37,7 @@ class Check:
raise SystemExit(f"\nPackage '{sbo}' unsupported by arch.\n") raise SystemExit(f"\nPackage '{sbo}' unsupported by arch.\n")
def installed(self, slackbuilds: list): def installed(self, slackbuilds: list):
''' Checking for installed packages. ''' """ Checking for installed packages. """
found, not_found = [], [] found, not_found = [], []
for sbo in slackbuilds: for sbo in slackbuilds:
@ -55,7 +57,7 @@ class Check:
return found return found
def blacklist(self, slackbuilds: list): def blacklist(self, slackbuilds: list):
''' Checking if the packages are blacklisted. ''' """ Checking if the packages are blacklisted. """
packages = [] packages = []
black = Blacklist() black = Blacklist()
@ -70,7 +72,7 @@ class Check:
f'{self.configs.etc_path} folder.\n') f'{self.configs.etc_path} folder.\n')
def database(self): def database(self):
''' Checking for empty table ''' """ Checking for empty table """
db = f'{self.configs.db_path}/{self.configs.database}' db = f'{self.configs.db_path}/{self.configs.database}'
if not SBoQueries('').names() or not os.path.isfile(db): if not SBoQueries('').names() or not os.path.isfile(db):
raise SystemExit('\nYou need to update the package lists first.\n' 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: class Md5sum:
''' Checksum the sources. ''' """ Checksum the sources. """
def __init__(self, flags): def __init__(self, flags):
self.flags: str = flags self.flags = flags
def check(self, path: str, source: str, checksum: str, name: str): def check(self, path: str, source: str, checksum: str, name: str):
filename = f'{path}/{source.split("/")[-1]}' filename = f'{path}/{source.split("/")[-1]}'
@ -25,9 +25,10 @@ class Md5sum:
print('Found:', file_check) print('Found:', file_check)
print(f'\nMD5SUM check for {name} FAILED.') print(f'\nMD5SUM check for {name} FAILED.')
view = ViewMessage() view = ViewMessage(self.flags)
view.question(self.flags) view.question()
def read_file(self, filename: str): @staticmethod
def read_file(filename: str):
with open(filename, 'rb') as f: with open(filename, 'rb') as f:
return f.read() return f.read()

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -22,7 +22,7 @@ Base = declarative_base()
@dataclass @dataclass
class SBoTable(Base): class SBoTable(Base):
''' The main table for the SBo repository. ''' """ The main table for the SBo repository. """
__tablename__ = 'sbotable' __tablename__ = 'sbotable'
@ -41,7 +41,7 @@ class SBoTable(Base):
@dataclass @dataclass
class LogsDependencies(Base): 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' __tablename__ = 'logsdependencies'

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -3,10 +3,10 @@
class Version: class Version:
''' Print the vesrsion. ''' """ Print the version. """
def __init__(self): 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.version: str = '{0}.{1}.{2}'.format(*self.version_info)
self.license: str = 'MIT License' self.license: str = 'MIT License'
self.author: str = 'Dimitris Zlatanidis (dslackw)' self.author: str = 'Dimitris Zlatanidis (dslackw)'

View file

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

View file

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