Updated for type hinting

This commit is contained in:
Dimitris Zlatanidis 2023-03-01 19:40:43 +02:00
parent 33dc69d149
commit 7ce7c6a417
19 changed files with 112 additions and 106 deletions

View file

@ -22,7 +22,7 @@ class Blacklist(Configs):
file_toml = Path(self.etc_path, 'blacklist.toml')
if self.ponce_repo:
sbos = self.session.query(PonceTable.name).all()
sbos: list = self.session.query(PonceTable.name).all()
ponce_blacks: list = [sbo[0] for sbo in sbos]
if file_toml.is_file():

View file

@ -15,15 +15,16 @@ class CheckUpdates(Configs):
def __init__(self):
super(Configs, self).__init__()
self.color = self.colour()
self.green = self.color['green']
self.yellow = self.color['yellow']
self.endc = self.color['endc']
self.progress = ProgressBar()
self.color = self.colour()
self.green: str = self.color['green']
self.yellow: str = self.color['yellow']
self.endc: str = self.color['endc']
def check(self) -> bool:
""" Checks the ChangeLogs and returns True or False. """
local_date = 0
local_date: int = 0
local_chg_txt = Path(self.sbo_repo_path, self.sbo_chglog_txt)
@ -33,19 +34,19 @@ class CheckUpdates(Configs):
if local_chg_txt.is_file():
local_date = int(os.stat(local_chg_txt).st_size)
repo_date = int(repo.headers['Content-Length'])
repo_date: int = int(repo.headers['Content-Length'])
return repo_date != local_date
def view_message(self):
def view_message(self) -> None:
if self.check():
print(f'\n\n{self.endc}There are new updates available!')
else:
print(f'\n\n{self.endc}No updated packages since the last check.')
def updates(self):
def updates(self) -> None:
""" Starting multiprocessing download process. """
message = f'Checking for news in the Changelog.txt file...'
message: str = f'Checking for news in the {self.sbo_chglog_txt} file...'
# Starting multiprocessing
p1 = Process(target=self.view_message)

View file

@ -17,9 +17,9 @@ class Check(Configs, Utilities):
super(Utilities, self).__init__()
@staticmethod
def exists(slackbuilds: list):
def exists(slackbuilds: list) -> None:
""" Checking if the slackbuild exists in the repository. """
not_packages = []
not_packages: list = []
for sbo in slackbuilds:
if not SBoQueries(sbo).slackbuild():
@ -30,7 +30,7 @@ class Check(Configs, Utilities):
'does not exists.\n')
@staticmethod
def unsupported(slackbuilds: list):
def unsupported(slackbuilds: list) -> None:
""" Checking for unsupported slackbuilds. """
for sbo in slackbuilds:
sources = SBoQueries(sbo).sources()
@ -43,9 +43,9 @@ class Check(Configs, Utilities):
found, not_found = [], []
for sbo in slackbuilds:
package = self.is_installed(sbo, file_pattern)
package: str = self.is_installed(sbo, file_pattern)
if package:
pkg = self.split_installed_pkg(package)[0]
pkg: str = self.split_installed_pkg(package)[0]
found.append(pkg)
else:
not_found.append(sbo)
@ -56,9 +56,9 @@ class Check(Configs, Utilities):
return found
def blacklist(self, slackbuilds: list):
def blacklist(self, slackbuilds: list) -> None:
""" Checking if the packages are blacklisted. """
packages = []
packages: list = []
black = Blacklist()
for package in black.packages():
@ -71,7 +71,7 @@ class Check(Configs, Utilities):
f'Please edit the blacklist.toml file in '
f'{self.configs.etc_path} folder.\n')
def database(self):
def database(self) -> None:
""" Checking for empty table """
db = Path(self.db_path, self.database_name)
if not SBoQueries('').sbos() or not db.is_file():

View file

@ -14,10 +14,10 @@ class Md5sum:
""" Checksum the sources. """
def __init__(self, flags: list):
self.flags = flags
self.flags: list = flags
self.ascii = Ascii()
def check(self, path: Union[str, Path], source: str, checksum: str, name: str):
def check(self, path: Union[str, Path], source: str, checksum: str, name: str) -> None:
""" Checksum the source. """
filename = unquote(source)
source_file = Path(path, filename.split('/')[-1])

View file

@ -10,12 +10,12 @@ class CleanLogsDependencies:
""" Cleans the logs from packages. """
def __init__(self, flags: list):
self.flags = flags
self.flags: list = flags
self.session = Session
def clean(self) -> None:
""" Deletes the log table from the database. """
dependencies = self.session.query(
dependencies: list = self.session.query(
LogsDependencies.name, LogsDependencies.requires).all()
if dependencies:

View file

@ -94,7 +94,7 @@ class Configs:
if configs:
try:
config: dict = configs['CONFIGS']
config = configs['CONFIGS']
# OS architecture by default.
os_arch: str = config['OS_ARCH']

View file

@ -15,7 +15,6 @@ class Dependees(Configs, Utilities):
def __init__(self, packages: list, flags: list):
super(Configs, self).__init__()
super(Utilities, self).__init__()
self.packages: list = packages
self.flags: list = flags

View file

@ -19,7 +19,6 @@ class Downloader(Configs, Utilities):
def __init__(self, path: Union[str, Path], url: str, flags: list):
super(Configs, self).__init__()
super(Utilities, self).__init__()
self.path: str = path
self.url: str = url
self.flags: list = flags

View file

@ -11,7 +11,6 @@ class FindInstalled(Configs, Utilities):
def __init__(self):
super(Configs, self).__init__()
super(Utilities, self).__init__()
self.color = self.colour()
self.yellow: str = self.color['yellow']

View file

@ -13,7 +13,6 @@ class FormConfigs(Configs):
def __init__(self):
super(Configs).__init__()
self.load_configs = LoadConfigs()
self.dialogbox = DialogBox()

View file

@ -11,7 +11,7 @@ from sqlalchemy import create_engine, Column, Integer, Text
from slpkg.configs import Configs
DATABASE_URI = os.path.join(f'sqlite:///{Configs.db_path}', Configs.database_name)
DATABASE_URI: str = os.path.join(f'sqlite:///{Configs.db_path}', Configs.database_name)
engine = create_engine(DATABASE_URI)

View file

@ -10,7 +10,9 @@ from slpkg.configs import Configs
class ProgressBar(Configs):
def __init__(self):
super(Configs, self).__init__()
self.color = self.colour()
self.bold: str = self.color['bold']
self.violet: str = self.color['violet']
self.bviolet: str = f'{self.bold}{self.violet}'

View file

@ -17,11 +17,14 @@ class RemovePackages(Configs):
""" Removes installed packages. """
def __init__(self, packages: list, flags: list, file_pattern: str):
super(Configs, self).__init__()
self.packages: list = packages
self.flags: list = flags
self.file_pattern: str = file_pattern
self.session = Session
self.color = self.colour()
self.bold: str = self.color['bold']
self.yellow: str = self.color['yellow']
self.red: str = self.color['red']

View file

@ -9,6 +9,7 @@ class SearchPackage(Configs):
""" Search slackbuilds from the repository. """
def __init__(self):
super(Configs, self).__init__()
self.color = self.colour()
self.yellow: str = self.color['yellow']

View file

@ -10,48 +10,48 @@ class Ascii(Configs):
""" ascii characters. """
def __init__(self):
super(Configs, self).__init__()
self.vertical_line = '|'
self.horizontal_line = '='
self.horizontal_vertical = '+'
self.upper_right_corner = '+'
self.lower_left_corner = '+'
self.lower_right_corner = '+'
self.upper_left_corner = '+'
self.horizontal_and_up = '+'
self.horizontal_and_down = '+'
self.vertical_and_right = '+'
self.vertical_and_left = '+'
if self.ascii_characters:
self.vertical_line = ''
self.horizontal_line = ''
self.horizontal_vertical = ''
self.upper_right_corner = ''
self.lower_left_corner = ''
self.lower_right_corner = ''
self.upper_left_corner = ''
self.horizontal_and_up = ''
self.horizontal_and_down = ''
self.vertical_and_right = ''
self.vertical_and_left = ''
self.color = self.colour()
self.bold = self.color['bold']
self.blue = self.color['blue']
self.green = self.color['green']
self.cyan = self.color['cyan']
self.red = self.color['red']
self.yellow = self.color['yellow']
self.violet = self.color['violet']
self.endc = self.color['endc']
self.bgreen = f'{self.bold}{self.green}'
self.bred = f'{self.bold}{self.red}'
self.columns, self.rows = shutil.get_terminal_size()
def draw_package_title_box(self, message, title):
self.vertical_line: str = '|'
self.horizontal_line: str = '='
self.horizontal_vertical: str = '+'
self.upper_right_corner: str = '+'
self.lower_left_corner: str = '+'
self.lower_right_corner: str = '+'
self.upper_left_corner: str = '+'
self.horizontal_and_up: str = '+'
self.horizontal_and_down: str = '+'
self.vertical_and_right: str = '+'
self.vertical_and_left: str = '+'
if self.ascii_characters:
self.vertical_line: str = ''
self.horizontal_line: str = ''
self.horizontal_vertical: str = ''
self.upper_right_corner: str = ''
self.lower_left_corner: str = ''
self.lower_right_corner: str = ''
self.upper_left_corner: str = ''
self.horizontal_and_up: str = ''
self.horizontal_and_down: str = ''
self.vertical_and_right: str = ''
self.vertical_and_left: str = ''
self.bold: str = self.color['bold']
self.blue: str = self.color['blue']
self.green: str = self.color['green']
self.cyan: str = self.color['cyan']
self.red: str = self.color['red']
self.yellow: str = self.color['yellow']
self.violet: str = self.color['violet']
self.endc: str = self.color['endc']
self.bgreen: str = f'{self.bold}{self.green}'
self.bred: str = f'{self.bold}{self.red}'
def draw_package_title_box(self, message: str, title: str) -> None:
""" Drawing package title box. """
middle_title = int((self.columns / 2) - len(title) + 6)
middle_title: int = int((self.columns / 2) - len(title) + 6)
print(f'{self.bgreen}{self.upper_left_corner}' + f'{self.horizontal_line}' * (self.columns - 2) +
f'{self.upper_right_corner}')
@ -69,32 +69,32 @@ class Ascii(Configs):
print(f'{self.bgreen}{self.vertical_line}{self.endc} Package:' + ' ' * 27 + 'Version:' +
' ' * (self.columns - 51) + f'Size{self.bgreen} {self.vertical_line}{self.endc}')
def draw_view_package(self, package, version, color):
def draw_view_package(self, package: str, version: str, color: str) -> None:
""" Draw nad print the packages. """
print(f'{self.bgreen}{self.vertical_line} {self.bold}{color}{package}{self.endc}' + ' ' * (35 - len(package)) +
f'{self.blue}{version}' + ' ' * ((self.columns - 37) - len(version) - 1) +
f'{self.bgreen}{self.vertical_line}{self.endc}')
def draw_log_package(self, package):
def draw_log_package(self, package: str) -> None:
""" Drawing and print logs packages. """
print(f' {self.lower_left_corner}{self.horizontal_line}{self.cyan} {package}{self.endc}\n')
def draw_middle_line(self):
def draw_middle_line(self) -> None:
""" Drawing a middle line. """
print(f'{self.bgreen}{self.vertical_and_right}' + f'{self.horizontal_line}' *
(self.columns - 2) + f'{self.vertical_and_left}')
def draw_dependency_line(self):
def draw_dependency_line(self) -> None:
""" Drawing the dependencies line. """
print(f'{self.bgreen}{self.vertical_line}{self.endc} Dependencies:' + ' ' * (self.columns - 16) +
f'{self.bgreen}{self.vertical_line}{self.endc}')
def draw_bottom_line(self):
def draw_bottom_line(self) -> None:
""" Drawing the bottom line. """
print(f'{self.bold}{self.green}{self.lower_left_corner}' + f'{self.horizontal_line}' *
(self.columns - 2) + f'{self.lower_right_corner}{self.endc}')
def draw_checksum_error_box(self, name, checksum, file_check):
def draw_checksum_error_box(self, name: str, checksum: str, file_check: str) -> None:
""" Drawing checksum error box. """
print('\n' + self.bred + self.upper_left_corner + self.horizontal_line * (self.columns - 2) +
self.upper_right_corner)

View file

@ -16,7 +16,7 @@ class Usage(Configs):
self.yellow: str = color['yellow']
self.endc: str = color['endc']
def help_short(self):
def help_short(self) -> None:
""" Prints the short menu. """
args = (
f'Usage: {self.prog_name} [{self.yellow}OPTIONS{self.endc}] [{self.cyan}COMMAND{self.endc}] [PACKAGES...]\n'
@ -34,9 +34,9 @@ class Usage(Configs):
print(args)
raise SystemExit()
def help(self, status: int):
def help(self, status: int) -> None:
""" Prints the main menu. """
args = (
args: str = (
f'{self.bold}USAGE:{self.endc} {self.prog_name} [{self.yellow}OPTIONS{self.endc}] '
f'[{self.cyan}COMMAND{self.endc}] [PACKAGES...]\n'
f'\n{self.bold}DESCRIPTION:{self.endc} Package manager utility for Slackware.\n'
@ -77,7 +77,7 @@ class Usage(Configs):
print(args)
raise SystemExit(status)
def error_for_options(self, command: str, flags: list):
def error_for_options(self, command: str, flags: list) -> None:
""" Error messages for flags. """
flags.reverse() # Put first the short options.
print(f'Usage: {self.prog_name} [{self.yellow}OPTIONS{self.endc}] '

View file

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

View file

@ -13,26 +13,27 @@ from slpkg.models.models import session as Session
class ViewPackage(Configs, Utilities):
""" View the repository packages. """
def __init__(self, flags):
def __init__(self, flags: list):
super(Configs, self).__init__()
super(Utilities, self).__init__()
self.flags = flags
self.flag_pkg_version = ['-p', '--pkg-version']
self.session = Session
self.flags: list = flags
def package(self, packages: list):
self.session = Session
self.flag_pkg_version: list = ['-p', '--pkg-version']
def package(self, packages: list) -> None:
""" View the packages from the repository. """
color = self.colour()
green = color['green']
blue = color['blue']
yellow = color['yellow']
cyan = color['cyan']
red = color['red']
endc = color['endc']
green: str = color['green']
blue: str = color['blue']
yellow: str = color['yellow']
cyan: str = color['cyan']
red: str = color['red']
endc: str = color['endc']
for package in packages:
info = self.session.query(
info: list = self.session.query(
SBoTable.name,
SBoTable.version,
SBoTable.requires,
@ -52,17 +53,17 @@ class ViewPackage(Configs, Utilities):
maintainer, email, homepage = '', '', ''
for line in info_file.data.decode().splitlines():
if line.startswith('HOMEPAGE'):
homepage = line[10:-1].strip()
homepage: str = line[10:-1].strip()
if line.startswith('MAINTAINER'):
maintainer = line[12:-1].strip()
maintainer: str = line[12:-1].strip()
if line.startswith('EMAIL'):
email = line[7:-1].strip()
email: str = line[7:-1].strip()
deps = (', '.join([f'{cyan}{pkg}' for pkg in info[2].split()]))
deps: str = (', '.join([f'{cyan}{pkg}' for pkg in info[2].split()]))
if self.is_option(self.flag_pkg_version, self.flags):
deps = (', '.join([f'{cyan}{pkg}{endc}-{yellow}{SBoQueries(pkg).version()}'
f'{green}' for pkg in info[2].split()]))
deps: str = (', '.join([f'{cyan}{pkg}{endc}-{yellow}{SBoQueries(pkg).version()}'
f'{green}' for pkg in info[2].split()]))
print(f'Name: {green}{info[0]}{endc}\n'
f'Version: {green}{info[1]}{endc}\n'

View file

@ -19,16 +19,15 @@ class ViewMessage(Configs):
def __init__(self, flags: list):
super(Configs, self).__init__()
self.flags = flags
self.flag_resolve_off: list = ['-o', '--resolve-off']
self.flag_reinstall: list = ['-R', '--reinstall']
self.flag_yes: list = ['-y', '--yes']
self.file_pattern: str = f'*{self.sbo_repo_tag}'
self.flags: list = flags
self.session = Session
self.utils = Utilities()
self.black = Blacklist()
self.dialogbox = DialogBox()
self.ascii = Ascii()
self.color = self.colour()
self.yellow: str = self.color['yellow']
self.cyan: str = self.color['cyan']
self.red: str = self.color['red']
@ -37,7 +36,10 @@ class ViewMessage(Configs):
self.endc: str = self.color['endc']
self.download_only = None
self.installed_packages: list = []
self.ascii = Ascii()
self.flag_resolve_off: list = ['-o', '--resolve-off']
self.flag_reinstall: list = ['-r', '--reinstall']
self.flag_yes: list = ['-y', '--yes']
self.file_pattern: str = f'*{self.sbo_repo_tag}'
def view_packages(self, package, version, mode):
""" Printing the main packages. """