Merge branch 'develop'

This commit is contained in:
Dimitris Zlatanidis 2022-12-23 12:55:10 +02:00
commit 32ac1d0809
32 changed files with 303 additions and 146 deletions

View file

@ -1,4 +1,8 @@
4.3.8 - 17/12/2022 4.3.9 - 22/12/2022
Added:
- Feature to check the ChangeLog.txt file before update #153
- Dependees command
BugFixed: BugFixed:
- View installed version - View installed version
- slpkg issue : permission denied #152 - slpkg issue : permission denied #152

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.8.tar.gz $ tar xvf slpkg-4.3.9.tar.gz
$ cd slpkg-4.3.8 $ cd slpkg-4.3.9
$ ./install.sh $ ./install.sh
@ -41,7 +41,6 @@ Usage
.. code-block:: bash .. code-block:: bash
$ slpkg --help $ slpkg --help
USAGE: slpkg [OPTIONS] [COMMAND] <packages> USAGE: slpkg [OPTIONS] [COMMAND] <packages>
DESCRIPTION: DESCRIPTION:
@ -60,6 +59,7 @@ Usage
-f, find <packages> Find installed packages. -f, find <packages> Find installed packages.
-w, view <packages> View packages from the repository. -w, view <packages> View packages from the repository.
-s, search <packages> Search packages from the repository. -s, search <packages> Search packages from the repository.
-e, dependees <packages> Show which packages depend.
OPTIONS: OPTIONS:
--yes Answer Yes to all questions. --yes Answer Yes to all questions.
@ -88,7 +88,7 @@ Usage
Total 6 packages will be installed and 0 will be upgraded. Total 6 packages will be installed and 0 will be upgraded.
Do you want to continue [y/N]: Do you want to continue (y/N)?:
$ slpkg remove Flask $ slpkg remove Flask
@ -105,7 +105,28 @@ Usage
Total 6 packages will be removed. Total 6 packages will be removed.
Do you want to continue [y/N]: Do you want to continue (y/N)?:
$ slpkg dependees vlc
The list below shows the packages that dependees 'vlc' files:
Collecting the data...
vlc
└─kaffeine
├─ vlc
obs-studio
├─ faac luajit rtmpdump x264 jack libfdk-aac mbedtls vlc
vlsub
├─ vlc
sopcast-player
└─ sopcast vlc
4 dependees for vlc
Configuration files Configuration files

View file

@ -1,10 +1,10 @@
.TH slpkg 1 "Orestiada, Greece" "slpkg 4.3.1" dslackw .TH slpkg 1 "Orestiada, Greece" "slpkg 4.3.9" dslackw
.SH NAME .SH NAME
.P .P
slpkg - [OPTIONS] [COMMAND] <packages> slpkg - [OPTIONS] [COMMAND] <packages>
.SH SYNAPSES .SH SYNAPSES
.P .P
slpkg [-h|-v] [update] [upgrade] [check-updates] [clean-logs] [clean-tmp] [-b, build] [-i, install] [-d, download] [-r, remove] [-f, find] [-w, view] [-s, search] --yes --jobs --resolve-off --reinstall --skip-installed slpkg [-h|-v] [update] [upgrade] [check-updates] [clean-logs] [clean-tmp] [-b, build] [-i, install] [-d, download] [-r, remove] [-f, find] [-w, view] [-s, search] [-e, dependees] --yes --jobs --resolve-off --reinstall --skip-installed
.SH DESCRIPTION .SH DESCRIPTION
.P .P
Slpkg is a software package manager that installs, updates, and removes packages on Slackware based systems. It automatically computes dependencies and figures out what things should occur to install packages. Slpkg makes it easier to maintain groups of machines without having to manually update. Slpkg is a software package manager that installs, updates, and removes packages on Slackware based systems. It automatically computes dependencies and figures out what things should occur to install packages. Slpkg makes it easier to maintain groups of machines without having to manually update.
@ -71,6 +71,11 @@ View packages from the repository and get everything in your terminal.
.RS .RS
Search and match packages from the repository. Search and match packages from the repository.
.RE .RE
.P
-e, dependees
.RS
Show which SlackBuilds depend on.
.RE
.SH OPTIONS .SH OPTIONS
.P .P
--yes --yes
@ -98,10 +103,11 @@ Use this option if you want to upgrade all packages even if the same version is
This a helpful option if you want to avoid building and reinstalling packages. This a helpful option if you want to avoid building and reinstalling packages.
Note: This option affects only the dependencies. Note: This option affects only the dependencies.
.RE .RE
.RE
.P .P
-h | --help -h | --help
.RS .RS
Show help informatio and exit. Show help information and exit.
.RE .RE
.P .P
-v | --version -v | --version

View file

@ -1,3 +1,2 @@
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.8 version = 4.3.9
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

@ -14,7 +14,8 @@ class Blacklist:
def __init__(self): def __init__(self):
self.configs = Configs self.configs = Configs
def get(self): def get(self) -> list:
""" Reads the blacklist file. """
file = f'{self.configs.etc_path}/blacklist.toml' file = f'{self.configs.etc_path}/blacklist.toml'
if os.path.isfile(file): if os.path.isfile(file):
with open(file, 'rb') as black: with open(file, 'rb') as black:

View file

@ -14,7 +14,9 @@ class CheckUpdates:
def __init__(self): def __init__(self):
self.configs = Configs self.configs = Configs
def updates(self): def check(self) -> bool:
""" Checks the ChangeLogs and returns True or False. """
print(end='\rChecking for news in the Changelog.txt file... ')
local_date = 0 local_date = 0
local_chg_txt = (f'{self.configs.sbo_repo_path}/' local_chg_txt = (f'{self.configs.sbo_repo_path}/'
f'{self.configs.chglog_txt}') f'{self.configs.chglog_txt}')
@ -28,7 +30,10 @@ class CheckUpdates:
repo_date = int(repo.headers['Content-Length']) repo_date = int(repo.headers['Content-Length'])
if repo_date != local_date: return repo_date != local_date
print('\nThere are new updates available.\n')
def updates(self):
if self.check():
print('\n\nThere are new updates available!\n')
else: else:
print('\nNo updated packages since the last check.\n') print('\n\nNo updated packages since the last check.\n')

View file

@ -38,7 +38,7 @@ class Check:
if 'UNSUPPORTED' in sources: if 'UNSUPPORTED' in sources:
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) -> list:
""" Checking for installed packages. """ """ Checking for installed packages. """
found, not_found = [], [] found, not_found = [], []

View file

@ -10,10 +10,11 @@ from slpkg.views.views import ViewMessage
class Md5sum: class Md5sum:
""" Checksum the sources. """ """ Checksum the sources. """
def __init__(self, flags): def __init__(self, flags: list):
self.flags = 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):
""" Checksum the source. """
filename = f'{path}/{source.split("/")[-1]}' filename = f'{path}/{source.split("/")[-1]}'
md5 = self.read_file(filename) md5 = self.read_file(filename)
@ -30,5 +31,6 @@ class Md5sum:
@staticmethod @staticmethod
def read_file(filename: str): def read_file(filename: str):
""" Reads the text file. """
with open(filename, 'rb') as f: with open(filename, 'rb') as f:
return f.read() return f.read()

View file

@ -10,11 +10,12 @@ 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: list):
self.flags = flags self.flags = flags
self.session = Session self.session = Session
def clean(self): def clean(self):
""" Deletes the log table from the database. """
dependencies = self.session.query( dependencies = self.session.query(
LogsDependencies.name, LogsDependencies.requires).all() LogsDependencies.name, LogsDependencies.requires).all()

View file

@ -90,8 +90,9 @@ class Configs:
# Wget options # Wget options
wget_options: str = config['wget_options'] wget_options: str = config['wget_options']
except KeyError as err: except KeyError:
raise KeyError(f"ERROR: {err} in the configurations.") print("Error: check the configuration file "
"in the '/etc/slpkg/' folder.\n")
# Creating the paths if not exists # Creating the paths if not exists
paths = [tmp_slpkg, paths = [tmp_slpkg,

View file

@ -15,6 +15,7 @@ class CreateData:
self.session = Session self.session = Session
def insert_sbo_table(self): def insert_sbo_table(self):
""" Install the data. """
sbo_tags = [ sbo_tags = [
'SLACKBUILD NAME:', 'SLACKBUILD NAME:',
'SLACKBUILD LOCATION:', 'SLACKBUILD LOCATION:',
@ -57,5 +58,6 @@ class CreateData:
@staticmethod @staticmethod
def read_file(file: str): def read_file(file: str):
""" Reads the text file. """
with open(file, 'r', encoding='utf-8') as f: with open(file, 'r', encoding='utf-8') as f:
return f.readlines() return f.readlines()

61
slpkg/dependees.py Normal file
View file

@ -0,0 +1,61 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from slpkg.configs import Configs
from slpkg.queries import SBoQueries
class Dependees:
""" Show which packages depend. """
def __init__(self, packages: list):
self.packages = packages
self.configs = Configs
self.colors = self.configs.colour
def slackbuilds(self):
""" Collecting the dependees. """
color = self.colors()
cyan = color['cyan']
grey = color['grey']
yellow = color['yellow']
endc = color['endc']
print(f"The list below shows the "
f"packages that dependees '{', '.join([p for p in self.packages])}' files:\n")
print(end='\rCollecting the data... ')
dependees = {}
for package in self.packages:
found = [] # Reset list every package
sbos = SBoQueries('').names()
for sbo in sbos:
requires = SBoQueries(sbo).requires()
if package in requires:
found.append(sbo)
dependees[package] = found
last = ' └─'
print('\n')
for key, value in dependees.items():
print(f'{yellow}{key}{endc}')
print(end=f'\r{last}')
char = ' ├─'
for i, v in enumerate(value, start=1):
if i == len(value):
char = last
if i == 1:
print(f'{cyan}{v}{endc}')
else:
print(f'{" " * 3}{cyan}{v}{endc}')
print(f'{" " * 4}{char} {" ".join([req for req in SBoQueries(v).requires()])}')
print(f'\n{grey}{len(value)} dependees for {key}{endc}\n')

View file

@ -9,10 +9,11 @@ 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: str):
self.name = name self.name = name
def resolve(self) -> list: def resolve(self) -> list:
""" Resolve the dependencies. """
requires = SBoQueries(self.name).requires() requires = SBoQueries(self.name).requires()
for req in requires: for req in requires:

View file

@ -12,12 +12,13 @@ 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: list):
self.flags: list = flags self.flags: list = flags
self.configs = Configs self.configs = Configs
self.session = Session self.session = Session
def packages(self, slackbuilds: list): def packages(self, slackbuilds: list):
""" Download the package only. """
view = ViewMessage(self.flags) view = ViewMessage(self.flags)
view.download_packages(slackbuilds) view.download_packages(slackbuilds)
view.question() view.question()
@ -31,5 +32,5 @@ class Download:
wget.download(self.configs.download_only, url) wget.download(self.configs.download_only, url)
sources = SBoQueries(sbo).sources() sources = SBoQueries(sbo).sources()
for source in sources.split(): for source in sources:
wget.download(self.configs.download_only, source) wget.download(self.configs.download_only, source)

View file

@ -14,5 +14,6 @@ class Wget:
self.wget_options: str = Configs.wget_options self.wget_options: str = Configs.wget_options
def download(self, path: str, url: str): def download(self, path: str, url: str):
""" Wget downloader. """
subprocess.call(f'wget {self.wget_options} --directory-prefix={path}' subprocess.call(f'wget {self.wget_options} --directory-prefix={path}'
f' {url}', shell=True) f' {url}', shell=True)

View file

@ -16,9 +16,10 @@ class FindInstalled:
self.color = colors() self.color = colors()
def find(self, packages: list): def find(self, packages: list):
""" Find the packages. """
matching = [] matching = []
print(f'The list below shows the packages ' print(f'The list below shows the installed packages '
f'that contains \'{", ".join([p for p in packages])}\' files:\n') f'that contains \'{", ".join([p for p in packages])}\' files:\n')
for pkg in packages: for pkg in packages:
@ -28,6 +29,7 @@ class FindInstalled:
self.matched(matching) self.matched(matching)
def matched(self, matching: list): def matched(self, matching: list):
""" Print the matched packages. """
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"]}')

View file

@ -7,6 +7,7 @@ import sys
from slpkg.checks import Check from slpkg.checks import Check
from slpkg.upgrade import Upgrade from slpkg.upgrade import Upgrade
from slpkg.configs import Configs from slpkg.configs import Configs
from slpkg.dependees import Dependees
from slpkg.utilities import Utilities from slpkg.utilities import Utilities
from slpkg.search import SearchPackage from slpkg.search import SearchPackage
from slpkg.views.cli_menu import Usage from slpkg.views.cli_menu import Usage
@ -23,7 +24,7 @@ from slpkg.update_repository import UpdateRepository
class Argparse: class Argparse:
def __init__(self, args): def __init__(self, args: list):
self.args = args self.args = args
self.flags = [] self.flags = []
self.configs = Configs self.configs = Configs
@ -41,10 +42,17 @@ class Argparse:
'--reinstall', '--reinstall',
'--skip-installed'] '--skip-installed']
for option in self.options: # Check for correct flag
if option in self.args: for opt in self.args:
self.args.remove(option) if opt.startswith('--'):
self.flags.append(option) if opt not in self.options and opt not in ['--help', '--version']:
raise SystemExit(f"\nError: flag '{opt}' does not exist.\n")
# Remove flags from args
for opt in self.options:
if opt in self.args:
self.args.remove(opt)
self.flags.append(opt)
def help(self): def help(self):
if len(self.args) == 1 and not self.flags: if len(self.args) == 1 and not self.flags:
@ -66,6 +74,9 @@ class Argparse:
self.usage.help(1) self.usage.help(1)
def upgrade(self): def upgrade(self):
if [f for f in self.flags if f not in self.options[:-2]]:
self.usage.help(1)
if len(self.args) == 1: if len(self.args) == 1:
self.check.database() self.check.database()
@ -91,7 +102,10 @@ class Argparse:
self.usage.help(1) self.usage.help(1)
def build(self): def build(self):
if len(self.args) >= 2 and '--reinstall' not in self.flags: if [f for f in self.flags if f not in self.options[:-3]]:
self.usage.help(1)
if len(self.args) >= 2:
packages = list(set(self.args[1:])) packages = list(set(self.args[1:]))
self.check.database() self.check.database()
@ -104,6 +118,9 @@ class Argparse:
self.usage.help(1) self.usage.help(1)
def install(self): def install(self):
if [f for f in self.flags if f not in self.options[:-1]]:
self.usage.help(1)
if len(self.args) >= 2: if len(self.args) >= 2:
packages = list(set(self.args[1:])) packages = list(set(self.args[1:]))
@ -127,7 +144,6 @@ class Argparse:
self.check.exists(packages) self.check.exists(packages)
download = Download(self.flags) download = Download(self.flags)
download.packages(packages) download.packages(packages)
raise SystemExit() raise SystemExit()
self.usage.help(1) self.usage.help(1)
@ -146,6 +162,17 @@ class Argparse:
raise SystemExit() raise SystemExit()
self.usage.help(1) self.usage.help(1)
def find(self):
if len(self.args) >= 2 and not self.flags:
packages = list(set(self.args[1:]))
self.check.database()
find = FindInstalled()
find.find(packages)
raise SystemExit()
self.usage.help(1)
def view(self): def view(self):
if len(self.args) >= 2 and not self.flags: if len(self.args) >= 2 and not self.flags:
packages = list(set(self.args[1:])) packages = list(set(self.args[1:]))
@ -169,14 +196,15 @@ class Argparse:
raise SystemExit() raise SystemExit()
self.usage.help(1) self.usage.help(1)
def find(self): def dependees(self):
if len(self.args) >= 2 and not self.flags: if len(self.args) >= 2 and not self.flags:
packages = list(set(self.args[1:])) packages = list(set(self.args[1:]))
self.check.database() self.check.database()
self.check.exists(packages)
find = FindInstalled() dependees = Dependees(packages)
find.find(packages) dependees.slackbuilds()
raise SystemExit() raise SystemExit()
self.usage.help(1) self.usage.help(1)
@ -234,7 +262,9 @@ def main():
'find': argparse.find, 'find': argparse.find,
'-f': argparse.find, '-f': argparse.find,
'search': argparse.search, 'search': argparse.search,
'-s': argparse.search '-s': argparse.search,
'dependees': argparse.dependees,
'-e': argparse.dependees
} }
try: try:

View file

@ -11,7 +11,7 @@ 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: str):
self.name = name self.name = name
self.session = Session self.session = Session
self.configs = Configs self.configs = Configs
@ -20,10 +20,13 @@ class SBoQueries:
if self.name in self.black.get(): if self.name in self.black.get():
self.name = '' self.name = ''
def names(self): def names(self) -> list:
return list(self._names_grabbing()) """ Returns all the slackbuilds. """
names = self.session.query(SBoTable.name).all()
return [name[0] for name in names]
def slackbuild(self): def slackbuild(self) -> str:
""" Returns a slackbuild. """
sbo = self.session.query( sbo = self.session.query(
SBoTable.name).filter(SBoTable.name == self.name).first() SBoTable.name).filter(SBoTable.name == self.name).first()
@ -31,7 +34,8 @@ class SBoQueries:
return sbo[0] return sbo[0]
return '' return ''
def location(self): def location(self) -> str:
""" Returns the category of a slackbuild. """
location = self.session.query( location = self.session.query(
SBoTable.location).filter(SBoTable.name == self.name).first() SBoTable.location).filter(SBoTable.name == self.name).first()
@ -39,16 +43,19 @@ class SBoQueries:
return location[0] return location[0]
return '' return ''
def sources(self): def sources(self) -> list:
""" Returns the source of a slackbuild. """
source, source64 = self.session.query( source, source64 = self.session.query(
SBoTable.download, SBoTable.download64).filter( SBoTable.download, SBoTable.download64).filter(
SBoTable.name == self.name).first() SBoTable.name == self.name).first()
if source or source64: if self.configs.os_arch == 'x86_64' and source64:
return self._chose_arch(source, source64) return source64.split()
return ''
def requires(self): return source.split()
def requires(self) -> str:
""" Returns the requirements of a slackbuild. """
requires = self.session.query( requires = self.session.query(
SBoTable.requires).filter( SBoTable.requires).filter(
SBoTable.name == self.name).first() SBoTable.name == self.name).first()
@ -61,7 +68,8 @@ class SBoQueries:
return requires return requires
return '' return ''
def version(self): def version(self) -> str:
""" Returns the version of a slackbuild. """
version = self.session.query( version = self.session.query(
SBoTable.version).filter( SBoTable.version).filter(
SBoTable.name == self.name).first() SBoTable.name == self.name).first()
@ -70,22 +78,19 @@ class SBoQueries:
return version[0] return version[0]
return '' return ''
def checksum(self): def checksum(self) -> list:
md5sum, md5sum64, = [], [] """ Returns the source checksum. """
mds5, md5s64 = self.session.query( mds5, md5s64 = self.session.query(
SBoTable.md5sum, SBoTable.md5sum64).filter( SBoTable.md5sum, SBoTable.md5sum64).filter(
SBoTable.name == self.name).first() SBoTable.name == self.name).first()
if mds5: if self.configs.os_arch == 'x86_64' and md5s64:
md5sum.append(mds5) return md5s64.split()
if md5s64:
md5sum64.append(md5s64)
if md5sum or md5sum64: return mds5.split()
return self._chose_arch(md5sum, md5sum64)
return ''
def description(self): def description(self) -> str:
""" Returns the slackbuild description. """
desc = self.session.query( desc = self.session.query(
SBoTable.short_description).filter( SBoTable.short_description).filter(
SBoTable.name == self.name).first() SBoTable.name == self.name).first()
@ -94,7 +99,8 @@ class SBoQueries:
return desc[0] return desc[0]
return '' return ''
def files(self): def files(self) -> str:
""" Returns the files of a slackbuild. """
files = self.session.query( files = self.session.query(
SBoTable.files).filter( SBoTable.files).filter(
SBoTable.name == self.name).first() SBoTable.name == self.name).first()
@ -102,13 +108,3 @@ class SBoQueries:
if files: if files:
return files[0] return files[0]
return '' return ''
def _chose_arch(self, arch, arch64):
if self.configs.os_arch == 'x86_64' and arch64:
return arch64
return arch
def _names_grabbing(self):
names = self.session.query(SBoTable.name).all()
for n in names:
yield n[0]

View file

@ -13,7 +13,7 @@ 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: list, flags: list):
self.packages = packages self.packages = packages
self.flags = flags self.flags = flags
self.session = Session self.session = Session

View file

@ -12,7 +12,8 @@ class SearchPackage:
def __init__(self): def __init__(self):
self.colors = Configs.colour self.colors = Configs.colour
def package(self, packages): def package(self, packages: list):
""" Searching and print the matched slackbuilds. """
color = self.colors() color = self.colors()
cyan = color['cyan'] cyan = color['cyan']
endc = color['endc'] endc = color['endc']
@ -20,8 +21,8 @@ class SearchPackage:
names = SBoQueries('').names() names = SBoQueries('').names()
print(f'The list below shows the packages ' print(f'The list below shows the repo '
f'that contains \'{", ".join([p for p in packages])}\' files:\n') f'packages that contains \'{", ".join([p for p in packages])}\' files:\n')
for name in names: for name in names:
for package in packages: for package in packages:

View file

@ -21,7 +21,7 @@ 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: list, flags: list, install: bool):
self.slackbuilds = slackbuilds self.slackbuilds = slackbuilds
self.flags = flags self.flags = flags
self.install = install self.install = install
@ -200,7 +200,7 @@ class Slackbuilds:
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: list):
""" Download the sources. """ """ Download the sources. """
wget = Wget() wget = Wget()
@ -208,7 +208,7 @@ class Slackbuilds:
checksums = SBoQueries(name).checksum() checksums = SBoQueries(name).checksum()
for source, checksum in zip(sources.split(), checksums[0].split()): for source, checksum in zip(sources, checksums):
wget.download(path, source) wget.download(path, source)
md5sum = Md5sum(self.flags) md5sum = Md5sum(self.flags)
md5sum.check(path, source, checksum, name) md5sum.check(path, source, checksum, name)

View file

@ -10,6 +10,8 @@ from slpkg.downloader import Wget
from slpkg.configs import Configs from slpkg.configs import Configs
from slpkg.create_data import CreateData from slpkg.create_data import CreateData
from slpkg.models.models import SBoTable from slpkg.models.models import SBoTable
from slpkg.views.views import ViewMessage
from slpkg.check_updates import CheckUpdates
from slpkg.models.models import session as Session from slpkg.models.models import session as Session
@ -21,6 +23,17 @@ class UpdateRepository:
self.session = Session self.session = Session
def sbo(self): def sbo(self):
""" Updated the sbo repository. """
view = ViewMessage([])
check_updates = CheckUpdates()
if not check_updates.check():
print('\n\nNo changes in ChangeLog.txt between your last update and now.')
else:
print('\n\nThere are new updates available!')
view.question()
print('Updating the package list...\n') print('Updating the package list...\n')
self.delete_file(self.configs.sbo_repo_path, self.configs.sbo_txt) self.delete_file(self.configs.sbo_repo_path, self.configs.sbo_txt)
self.delete_file(self.configs.sbo_repo_path, self.configs.chglog_txt) self.delete_file(self.configs.sbo_repo_path, self.configs.chglog_txt)
@ -38,10 +51,12 @@ class UpdateRepository:
@staticmethod @staticmethod
def delete_file(folder: str, txt_file: str): def delete_file(folder: str, txt_file: str):
""" Delete the file. """
file = f'{folder}/{txt_file}' file = f'{folder}/{txt_file}'
if path.exists(file): if path.exists(file):
os.remove(file) os.remove(file)
def delete_sbo_data(self): def delete_sbo_data(self):
""" Delete the table from the database. """
self.session.query(SBoTable).delete() self.session.query(SBoTable).delete()
self.session.commit() self.session.commit()

View file

@ -19,8 +19,6 @@ class Upgrade:
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.\n")
repo_packages = SBoQueries('').names() repo_packages = SBoQueries('').names()
black = Blacklist().get() black = Blacklist().get()

View file

@ -16,7 +16,7 @@ class Utilities:
self.configs = Configs self.configs = Configs
self.black = Blacklist() self.black = Blacklist()
def is_installed(self, name: str): def is_installed(self, name: str) -> str:
""" Returns the installed package name. """ """ Returns the installed package name. """
for package in os.listdir(self.configs.log_packages): for package in os.listdir(self.configs.log_packages):
pkg = self.split_installed_pkg(package)[0] pkg = self.split_installed_pkg(package)[0]
@ -52,7 +52,7 @@ class Utilities:
if not os.path.isdir(directory): if not os.path.isdir(directory):
os.makedirs(directory) os.makedirs(directory)
def split_installed_pkg(self, package): def split_installed_pkg(self, package: str) -> list:
""" Split the package by the name, version, arch, build and tag. """ """ Split the package by the name, version, arch, build and tag. """
name = '-'.join(package.split('-')[:-3]) name = '-'.join(package.split('-')[:-3])
version = ''.join(package[len(name):].split('-')[:-2]) version = ''.join(package[len(name):].split('-')[:-2])

View file

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

View file

@ -6,13 +6,14 @@ class Version:
""" Print the version. """ """ Print the version. """
def __init__(self): def __init__(self):
self.version_info: tuple = (4, 3, 8) self.version_info = (4, 3, 9)
self.version: str = '{0}.{1}.{2}'.format(*self.version_info) self.version = '{0}.{1}.{2}'.format(*self.version_info)
self.license: str = 'MIT License' self.license = 'MIT License'
self.author: str = 'Dimitris Zlatanidis (dslackw)' self.author = 'Dimitris Zlatanidis (dslackw)'
self.homepage: str = 'https://dslackw.gitlab.io/slpkg' self.homepage = 'https://dslackw.gitlab.io/slpkg'
def view(self): def view(self):
""" Prints the version. """
print(f'Version: {self.version}\n' print(f'Version: {self.version}\n'
f'Author: {self.author}\n' f'Author: {self.author}\n'
f'License: {self.license}\n' f'License: {self.license}\n'

View file

@ -18,9 +18,8 @@ class ViewPackage:
self.configs = Configs self.configs = Configs
self.colors = self.configs.colour self.colors = self.configs.colour
def package(self, packages): def package(self, packages: list):
""" View the packages from the repository. """ """ View the packages from the repository. """
http = urllib3.PoolManager()
color = self.colors() color = self.colors()
green = color['green'] green = color['green']
blue = color['blue'] blue = color['blue']
@ -30,6 +29,7 @@ class ViewPackage:
endc = color['endc'] endc = color['endc']
for package in packages: for package in packages:
info = self.session.query( info = self.session.query(
SBoTable.name, SBoTable.name,
SBoTable.version, SBoTable.version,
@ -43,11 +43,9 @@ class ViewPackage:
SBoTable.location SBoTable.location
).filter(SBoTable.name == package).first() ).filter(SBoTable.name == package).first()
readme = http.request( readme = self.http_request(f'{self.configs.sbo_repo_url}/{info[9]}/{info[0]}/README')
'GET', f'{self.configs.sbo_repo_url}/{info[9]}/{info[0]}/README')
info_file = http.request( info_file = self.http_request(f'{self.configs.sbo_repo_url}/{info[9]}/{info[0]}/{info[0]}.info')
'GET', f'{self.configs.sbo_repo_url}/{info[9]}/{info[0]}/{info[0]}.info')
maintainer, email, homepage = '', '', '' maintainer, email, homepage = '', '', ''
for line in info_file.data.decode().splitlines(): for line in info_file.data.decode().splitlines():
@ -64,7 +62,8 @@ class ViewPackage:
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]}'
f'{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'
@ -77,3 +76,9 @@ class ViewPackage:
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}')
@staticmethod
def http_request(link: str) -> str:
""" Http get request. """
http = urllib3.PoolManager()
return http.request('GET', link)

View file

@ -14,7 +14,7 @@ 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: list):
self.flags = flags self.flags = flags
self.configs = Configs self.configs = Configs
self.colors = self.configs.colour self.colors = self.configs.colour
@ -170,7 +170,7 @@ class ViewMessage:
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: list):
""" View the logging packages. """ """ 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()
@ -184,7 +184,7 @@ class ViewMessage:
def question(self): def question(self):
""" Manage to proceed. """ """ 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)?: ')
if answer not in ['Y', 'y']: if answer not in ['Y', 'y']:
raise SystemExit() raise SystemExit()
print() print()

View file

@ -6,20 +6,19 @@ class TestPkgInstalled(unittest.TestCase):
def setUp(self): def setUp(self):
self.check = Check() self.check = Check()
self.packages = ['Flask', 'colored', 'slpkg'] self.packages = ['fish', 'ranger', 'pycharm']
def test_check_exists(self): def test_check_exists(self):
self.assertIsNone(self.check.exists(self.packages)) self.assertIsNone(self.check.exists(self.packages))
def tect_check_unsupported(self): def test_check_unsupported(self):
self.assertIsNone(self.check.unsupported(self.packages)) self.assertIsNone(self.check.unsupported(self.packages))
def test_check_installed(self): def test_check_installed(self):
self.assertIsNone(self.check.installed(self.packages)) self.assertListEqual(self.packages, self.check.installed(self.packages))
def test_check_blacklist(self): def test_check_blacklist(self):
self.assertListEqual(self.packages, self.assertIsNone(self.check.blacklist(self.packages))
self.check.blacklist(self.packages))
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -9,12 +9,14 @@ class TestColors(unittest.TestCase):
self.color = colors() self.color = colors()
def test_colors(self): def test_colors(self):
self.assertIn('BOLD', self.color) self.assertIn('bold', self.color)
self.assertIn('RED', self.color) self.assertIn('red', self.color)
self.assertIn('YELLOW', self.color) self.assertIn('yellow', self.color)
self.assertIn('GREEN', self.color) self.assertIn('cyan', self.color)
self.assertIn('BLUE', self.color) self.assertIn('green', self.color)
self.assertIn('GREY', self.color) self.assertIn('blue', self.color)
self.assertIn('grey', self.color)
self.assertIn('endc', self.color)
if __name__ == '__main__': if __name__ == '__main__':

View file

@ -14,17 +14,17 @@ class TestSBoQueries(unittest.TestCase):
self.assertEqual('system', self.query.location()) self.assertEqual('system', self.query.location())
def test_sources(self): def test_sources(self):
self.assertEqual('https://gitlab.com/dslackw/slpkg/-/archive' self.assertEqual(['https://gitlab.com/dslackw/slpkg/-/archive'
'/4.3.0/slpkg-4.3.0.tar.gz', self.query.sources()) '/4.3.7/slpkg-4.3.7.tar.gz'], self.query.sources())
def test_requires(self): def test_requires(self):
self.assertEqual(['SQLAlchemy'], self.query.requires()) self.assertEqual(['SQLAlchemy', 'python-toml'], self.query.requires())
def test_version(self): def test_version(self):
self.assertEqual('4.3.0', self.query.version()) self.assertEqual('4.3.7', self.query.version())
def test_checksum(self): def test_checksum(self):
self.assertListEqual(['ab03d0543b74abfce92287db740394c4'], self.assertListEqual(['5a55fd350004b3e49a060835a7ada3e9'],
self.query.checksum()) self.query.checksum())
def test_files(self): def test_files(self):