Updated for type hinting

This commit is contained in:
Dimitris Zlatanidis 2023-03-02 23:01:45 +02:00
parent 66c3fe542f
commit b2fdf0d32e
14 changed files with 81 additions and 80 deletions

View file

@ -79,7 +79,7 @@ class Dependees(Configs, Utilities):
def find_requires(self, sbo: str) -> Generator[str, None, None]:
""" Find requires that slackbuild dependees. """
requires: list = self.session.query(SBoTable.name, SBoTable.requires).all()
requires: list = self.session.query(SBoTable.name, SBoTable.requires).all() # type: ignore
for req in requires:
if [r for r in req[1].split() if r == sbo]:
yield req

View file

@ -13,11 +13,10 @@ class Requires:
def resolve(self) -> list:
""" Resolve the dependencies. """
requires = SBoQueries(self.name).requires()
requires: list[str] = SBoQueries(self.name).requires() # type: ignore
for req in requires:
if req:
sub = SBoQueries(req).requires()
sub: list[str] = SBoQueries(req).requires() # type: ignore
for s in sub:
requires.append(s)

View file

@ -25,7 +25,7 @@ class DialogBox(Configs):
list_height: int, choices: list, packages: list):
""" Display a checklist box. """
if self.dialog:
code, tags = self.d.checklist(text, title=title, height=height, width=width,
code, tags = self.d.checklist(text, title=title, height=height, width=width, # type: ignore
list_height=list_height, choices=choices)
else:
code: bool = False
@ -36,7 +36,7 @@ class DialogBox(Configs):
def mixedform(self, text: str, title: str, elements: list, height: int, width: int):
""" Display a mixedform box. """
if self.dialog:
code, tags = self.d.mixedform(text=text, title=title, elements=elements,
code, tags = self.d.mixedform(text=text, title=title, elements=elements, # type: ignore
height=height, width=width, help_button=True)
else:
code: bool = False

View file

@ -19,14 +19,14 @@ 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.path = path
self.url: str = url
self.flags: list = flags
self.color = self.colour()
self.progress = ProgressBar()
self.output: int = 0
self.output = 0
self.stderr = None
self.stdout = None

View file

@ -24,7 +24,7 @@ class FindInstalled(Configs, Utilities):
""" Find the packages. """
matching: list = []
installed: list = self.all_installed(pattern)
installed: list = list(self.all_installed(pattern))
print(f'The list below shows the installed packages '
f'that contains \'{", ".join([p for p in packages])}\' files:\n')

View file

@ -16,7 +16,7 @@ class FormConfigs(Configs):
self.load_configs = LoadConfigs()
self.dialogbox = DialogBox()
self.orig_configs = None
self.orig_configs: list = []
self.config_file = Path(self.etc_path, f'{self.prog_name}.toml')
def edit(self) -> None:

View file

@ -32,7 +32,7 @@ class Argparse(Configs):
def __init__(self, args: list):
self.args: list = args
self.flags: list = []
self.directory = None
self.directory = self.tmp_slpkg
self.file_pattern: str = f'*{self.sbo_repo_tag}'
self.dialogbox = DialogBox()
self.utils = Utilities()
@ -207,23 +207,23 @@ class Argparse(Configs):
]
}
self.commands['-h']: dict = self.commands['--help']
self.commands['-v']: dict = self.commands['--version']
self.commands['-u']: dict = self.commands['update']
self.commands['-U']: dict = self.commands['upgrade']
self.commands['-c']: dict = self.commands['check-updates']
self.commands['-g']: dict = self.commands['configs']
self.commands['-L']: dict = self.commands['clean-logs']
self.commands['-D']: dict = self.commands['clean-tmp']
self.commands['-b']: dict = self.commands['build']
self.commands['-i']: dict = self.commands['install']
self.commands['-d']: dict = self.commands['download']
self.commands['-R']: dict = self.commands['remove']
self.commands['-f']: dict = self.commands['find']
self.commands['-w']: dict = self.commands['view']
self.commands['-s']: dict = self.commands['search']
self.commands['-e']: dict = self.commands['dependees']
self.commands['-t']: dict = self.commands['tracking']
self.commands['-h'] = self.commands['--help']
self.commands['-v'] = self.commands['--version']
self.commands['-u'] = self.commands['update']
self.commands['-U'] = self.commands['upgrade']
self.commands['-c'] = self.commands['check-updates']
self.commands['-g'] = self.commands['configs']
self.commands['-L'] = self.commands['clean-logs']
self.commands['-D'] = self.commands['clean-tmp']
self.commands['-b'] = self.commands['build']
self.commands['-i'] = self.commands['install']
self.commands['-d'] = self.commands['download']
self.commands['-R'] = self.commands['remove']
self.commands['-f'] = self.commands['find']
self.commands['-w'] = self.commands['view']
self.commands['-s'] = self.commands['search']
self.commands['-e'] = self.commands['dependees']
self.commands['-t'] = self.commands['tracking']
self.split_options()
self.split_options_from_args()
@ -258,19 +258,19 @@ class Argparse(Configs):
for arg in self.args:
if arg.startswith(self.flag_directory):
self.directory = arg.split('=')[1]
self.args[self.args.index(arg)]: list = self.flag_directory
self.args[self.args.index(arg)] = self.flag_directory
if arg.startswith(self.flag_short_directory):
self.directory = arg.split('=')[1]
self.args[self.args.index(arg)]: list = self.flag_short_directory
self.args[self.args.index(arg)] = self.flag_short_directory
if arg.startswith(self.flag_file_pattern):
self.file_pattern = arg.split('=')[1]
self.args[self.args.index(arg)]: list = self.flag_file_pattern
self.args[self.args.index(arg)] = self.flag_file_pattern
if arg.startswith(self.flag_short_file_pattern):
self.file_pattern = arg.split('=')[1]
self.args[self.args.index(arg)]: list = self.flag_short_file_pattern
self.args[self.args.index(arg)] = self.flag_short_file_pattern
def move_options(self) -> None:
""" Move options to the flags and removes from the arguments. """
@ -310,7 +310,7 @@ class Argparse(Configs):
if method == 'find' and self.file_pattern:
pattern: str = self.file_pattern
installed: list = self.utils.all_installed(pattern)
installed: list = list(self.utils.all_installed(pattern))
if method in ['remove', 'find']:

View file

@ -23,13 +23,13 @@ class SBoQueries(Configs):
def sbos(self) -> list:
""" Returns all the slackbuilds. """
sbos: tuple = self.session.query(SBoTable.name).all()
sbos: tuple = self.session.query(SBoTable.name).all() # type: ignore
return [sbo[0] for sbo in sbos]
def slackbuild(self) -> str:
""" Returns a slackbuild. """
sbo: tuple = self.session.query(
SBoTable.name).filter(SBoTable.name == self.name).first()
SBoTable.name).filter(SBoTable.name == self.name).first() # type: ignore
if sbo:
return sbo[0]
@ -38,7 +38,7 @@ class SBoQueries(Configs):
def location(self) -> str:
""" Returns the category of a slackbuild. """
location: tuple = self.session.query(
SBoTable.location).filter(SBoTable.name == self.name).first()
SBoTable.location).filter(SBoTable.name == self.name).first() # type: ignore
if location:
return location[0]
@ -47,7 +47,7 @@ class SBoQueries(Configs):
def sources(self) -> list:
""" Returns the source of a slackbuild. """
source, source64 = self.session.query(
SBoTable.download, SBoTable.download64).filter(
SBoTable.download, SBoTable.download64).filter( # type: ignore
SBoTable.name == self.name).first()
if self.os_arch == 'x86_64' and source64:
@ -57,8 +57,8 @@ class SBoQueries(Configs):
def requires(self) -> Union[str, list]:
""" Returns the requirements of a slackbuild. """
requires: tuple = self.session.query(
SBoTable.requires).filter(
requires: tuple = self.session.query( # type: ignore
SBoTable.requires).filter( # type: ignore
SBoTable.name == self.name).first()
if requires:
@ -72,7 +72,7 @@ class SBoQueries(Configs):
def version(self) -> str:
""" Returns the version of a slackbuild. """
version: tuple = self.session.query(
SBoTable.version).filter(
SBoTable.version).filter( # type: ignore
SBoTable.name == self.name).first()
if version:
@ -82,7 +82,7 @@ class SBoQueries(Configs):
def checksum(self) -> list:
""" Returns the source checksum. """
mds5, md5s64 = self.session.query(
SBoTable.md5sum, SBoTable.md5sum64).filter(
SBoTable.md5sum, SBoTable.md5sum64).filter( # type: ignore
SBoTable.name == self.name).first()
if self.os_arch == 'x86_64' and md5s64:
@ -93,7 +93,7 @@ class SBoQueries(Configs):
def description(self) -> str:
""" Returns the slackbuild description. """
desc: tuple = self.session.query(
SBoTable.short_description).filter(
SBoTable.short_description).filter( # type: ignore
SBoTable.name == self.name).first()
if desc:
@ -103,7 +103,7 @@ class SBoQueries(Configs):
def files(self) -> str:
""" Returns the files of a slackbuild. """
files: tuple = self.session.query(
SBoTable.files).filter(
SBoTable.files).filter( # type: ignore
SBoTable.name == self.name).first()
if files:

View file

@ -107,8 +107,8 @@ class RemovePackages(Configs):
if not p1.is_alive():
if p1.exitcode != 0:
done = f' {self.bred} Failed{self.endc}'
self.output = p1.exitcode
done: str = f' {self.bred} Failed{self.endc}'
self.output: int = p1.exitcode # type: ignore
print(f'{self.endc}{done}', end='')
p2.terminate()

View file

@ -6,6 +6,7 @@ import time
import subprocess
from pathlib import Path
from typing import Literal
from collections import OrderedDict
from multiprocessing import Process, cpu_count
@ -45,7 +46,7 @@ class Slackbuilds(Configs):
self.output: int = 0
self.stderr = None
self.stdout = None
self.process_message = None
self.process_message: str = ''
self.bold: str = self.color['bold']
self.cyan: str = self.color['cyan']
self.red: str = self.color['red']
@ -122,7 +123,7 @@ class Slackbuilds(Configs):
self.view_message.question()
def is_for_skipped(self, sbo) -> None:
def is_for_skipped(self, sbo) -> Literal[True]:
""" Condition to check if slackbuild is for skipped. """
return (not self.utils.is_installed(sbo, self.file_pattern) or
self.utils.is_package_upgradeable(sbo, self.file_pattern) or
@ -194,7 +195,7 @@ class Slackbuilds(Configs):
def logging_installed_dependencies(self, name: str) -> None:
""" Logging installed dependencies and used for remove. """
exist = self.session.query(LogsDependencies.name).filter(
exist = self.session.query(LogsDependencies.name).filter( # type: ignore
LogsDependencies.name == name).first()
requires: list = Requires(name).resolve()
@ -302,7 +303,7 @@ class Slackbuilds(Configs):
if p1.exitcode != 0:
done: str = f' {self.bred} Failed{self.endc}'
self.output = p1.exitcode
self.output: int = p1.exitcode # type: ignore
print(f'{self.endc}{done}', end='')
p2.terminate()

View file

@ -26,7 +26,7 @@ class Upgrade(Configs, Utilities):
black: list = self.black.packages()
upgrade, requires = [], []
installed: list = self.all_installed(self.file_pattern)
installed: list = list(self.all_installed(self.file_pattern))
for pkg in installed:
inst_pkg_name: str = self.split_installed_pkg(pkg)[0]

View file

@ -5,6 +5,7 @@ import time
import shutil
import tarfile
from pathlib import Path
from typing import Generator, Any
from distutils.version import LooseVersion
from slpkg.configs import Configs
@ -36,7 +37,7 @@ class Utilities:
return ''
def all_installed(self, pattern: str) -> list:
def all_installed(self, pattern: str) -> Generator:
""" Return all installed SBo packages from /val/log/packages folder. """
var_log_packages = Path(self.configs.log_packages)
@ -91,7 +92,7 @@ class Utilities:
time.strftime(f'[{self.cyan}%H:%M:%S{self.endc}]',
time.gmtime(elapsed_time)))
def is_package_upgradeable(self, package: str, file_pattern: str) -> bool:
def is_package_upgradeable(self, package: str, file_pattern: str) -> Any:
""" Checks if the package is installed and if it is upgradeable, returns true. """
installed = self.is_installed(package, file_pattern)
if installed:
@ -101,6 +102,6 @@ class Utilities:
return LooseVersion(repository_version) > LooseVersion(installed_version)
@staticmethod
def is_option(flag: list, flags: list) -> True:
def is_option(flag: list, flags: list) -> Any:
""" Checking for flags. """
return [f for f in flag if f in flags]

View file

@ -44,21 +44,21 @@ class Help(Configs):
'tracking': "Tracking the packages dependencies."
}
help_commands['-u']: dict = help_commands['update']
help_commands['-U']: dict = help_commands['upgrade']
help_commands['-c']: dict = help_commands['check-updates']
help_commands['-g']: dict = help_commands['configs']
help_commands['-L']: dict = help_commands['clean-logs']
help_commands['-D']: dict = help_commands['clean-tmp']
help_commands['-b']: dict = help_commands['build']
help_commands['-i']: dict = help_commands['install']
help_commands['-d']: dict = help_commands['download']
help_commands['-r']: dict = help_commands['remove']
help_commands['-f']: dict = help_commands['find']
help_commands['-w']: dict = help_commands['view']
help_commands['-s']: dict = help_commands['search']
help_commands['-e']: dict = help_commands['dependees']
help_commands['-t']: dict = help_commands['tracking']
help_commands['-u'] = help_commands['update']
help_commands['-U'] = help_commands['upgrade']
help_commands['-c'] = help_commands['check-updates']
help_commands['-g'] = help_commands['configs']
help_commands['-L'] = help_commands['clean-logs']
help_commands['-D'] = help_commands['clean-tmp']
help_commands['-b'] = help_commands['build']
help_commands['-i'] = help_commands['install']
help_commands['-d'] = help_commands['download']
help_commands['-r'] = help_commands['remove']
help_commands['-f'] = help_commands['find']
help_commands['-w'] = help_commands['view']
help_commands['-s'] = help_commands['search']
help_commands['-e'] = help_commands['dependees']
help_commands['-t'] = help_commands['tracking']
print(f'\n{self.bold}{self.green}Help: {self.endc}{help_commands[self.command]}\n')
print(f"{self.bold}COMMAND{self.endc}: {self.cyan}{self.command}{self.endc}")

View file

@ -34,16 +34,16 @@ class ViewPackage(Configs, Utilities):
for package in packages:
info: list = self.session.query(
SBoTable.name,
SBoTable.version,
SBoTable.requires,
SBoTable.download,
SBoTable.download64,
SBoTable.md5sum,
SBoTable.md5sum64,
SBoTable.files,
SBoTable.short_description,
SBoTable.location
SBoTable.name, # type: ignore
SBoTable.version, # type: ignore
SBoTable.requires, # type: ignore
SBoTable.download, # type: ignore
SBoTable.download64, # type: ignore
SBoTable.md5sum, # type: ignore
SBoTable.md5sum64, # type: ignore
SBoTable.files, # type: ignore
SBoTable.short_description, # type: ignore
SBoTable.location # type: ignore
).filter(SBoTable.name == package).first()
readme = self.http_request(f'{self.sbo_repo_url}{info[9]}/{info[0]}/README')
@ -51,7 +51,7 @@ class ViewPackage(Configs, Utilities):
info_file = self.http_request(f'{self.sbo_repo_url}{info[9]}/{info[0]}/{info[0]}.info')
maintainer, email, homepage = '', '', ''
for line in info_file.data.decode().splitlines():
for line in info_file.data.decode().splitlines(): # type: ignore
if line.startswith('HOMEPAGE'):
homepage: str = line[10:-1].strip()
if line.startswith('MAINTAINER'):
@ -82,7 +82,7 @@ class ViewPackage(Configs, Utilities):
f'SBo url: {blue}{self.sbo_repo_url}{info[9]}/{info[0]}{endc}\n'
f'Maintainer: {yellow}{maintainer}{endc}\n'
f'Email: {yellow}{email}{endc}\n'
f'\nREADME: {cyan}{readme.data.decode()}{endc}')
f'\nREADME: {cyan}{readme.data.decode()}{endc}') # type: ignore
@staticmethod
def http_request(link: str) -> str: