From 38cc9dbff9aed66d79a8d86b6013bab082d48951 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Thu, 22 Dec 2022 22:26:59 +0200 Subject: [PATCH] Added type hints --- slpkg/blacklist.py | 2 +- slpkg/check_updates.py | 2 +- slpkg/checks.py | 2 +- slpkg/checksum.py | 2 +- slpkg/clean_logs.py | 2 +- slpkg/create_data.py | 2 +- slpkg/dependees.py | 2 +- slpkg/dependencies.py | 2 +- slpkg/download_only.py | 2 +- slpkg/main.py | 2 +- slpkg/queries.py | 22 +++++++++++----------- slpkg/remove_packages.py | 2 +- slpkg/search.py | 2 +- slpkg/slackbuild.py | 2 +- slpkg/utilities.py | 4 ++-- slpkg/views/version.py | 10 +++++----- slpkg/views/view_package.py | 4 ++-- slpkg/views/views.py | 4 ++-- 18 files changed, 35 insertions(+), 35 deletions(-) diff --git a/slpkg/blacklist.py b/slpkg/blacklist.py index 3bb5f1e5..f9e480b0 100644 --- a/slpkg/blacklist.py +++ b/slpkg/blacklist.py @@ -11,7 +11,7 @@ from slpkg.configs import Configs class Blacklist: """ Reads and returns the blacklist. """ - def __init__(self): + def __init__(self) -> list: self.configs = Configs def get(self): diff --git a/slpkg/check_updates.py b/slpkg/check_updates.py index 8dd62b46..837c1ea1 100644 --- a/slpkg/check_updates.py +++ b/slpkg/check_updates.py @@ -14,7 +14,7 @@ class CheckUpdates: def __init__(self): self.configs = Configs - def check(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 diff --git a/slpkg/checks.py b/slpkg/checks.py index dd9cf918..5a12ede8 100644 --- a/slpkg/checks.py +++ b/slpkg/checks.py @@ -38,7 +38,7 @@ class Check: if 'UNSUPPORTED' in sources: raise SystemExit(f"\nPackage '{sbo}' unsupported by arch.\n") - def installed(self, slackbuilds: list): + def installed(self, slackbuilds: list) -> list: """ Checking for installed packages. """ found, not_found = [], [] diff --git a/slpkg/checksum.py b/slpkg/checksum.py index f89919bb..8bf953bf 100644 --- a/slpkg/checksum.py +++ b/slpkg/checksum.py @@ -10,7 +10,7 @@ from slpkg.views.views import ViewMessage class Md5sum: """ Checksum the sources. """ - def __init__(self, flags): + def __init__(self, flags: list): self.flags = flags def check(self, path: str, source: str, checksum: str, name: str): diff --git a/slpkg/clean_logs.py b/slpkg/clean_logs.py index ee2eec8d..5d617602 100644 --- a/slpkg/clean_logs.py +++ b/slpkg/clean_logs.py @@ -10,7 +10,7 @@ from slpkg.models.models import session as Session class CleanLogsDependencies: """ Cleans the logs from packages. """ - def __init__(self, flags): + def __init__(self, flags: list): self.flags = flags self.session = Session diff --git a/slpkg/create_data.py b/slpkg/create_data.py index 0bdeb9f9..46e914fe 100644 --- a/slpkg/create_data.py +++ b/slpkg/create_data.py @@ -58,6 +58,6 @@ class CreateData: @staticmethod def read_file(file: str): - """ Reades the text file. """ + """ Reads the text file. """ with open(file, 'r', encoding='utf-8') as f: return f.readlines() diff --git a/slpkg/dependees.py b/slpkg/dependees.py index 0111d5c4..1156f52f 100644 --- a/slpkg/dependees.py +++ b/slpkg/dependees.py @@ -9,7 +9,7 @@ from slpkg.queries import SBoQueries class Dependees: """ Show which packages depend. """ - def __init__(self, packages): + def __init__(self, packages: list): self.packages = packages self.configs = Configs self.colors = self.configs.colour diff --git a/slpkg/dependencies.py b/slpkg/dependencies.py index 8f57cd22..c16c5b1b 100644 --- a/slpkg/dependencies.py +++ b/slpkg/dependencies.py @@ -9,7 +9,7 @@ class Requires: """ Creates a list of dependencies with the right order to install. """ - def __init__(self, name): + def __init__(self, name: str): self.name = name def resolve(self) -> list: diff --git a/slpkg/download_only.py b/slpkg/download_only.py index 77295bfb..333ee0e3 100644 --- a/slpkg/download_only.py +++ b/slpkg/download_only.py @@ -12,7 +12,7 @@ from slpkg.models.models import session as Session class Download: """ Download the slackbuilds with the sources only. """ - def __init__(self, flags): + def __init__(self, flags: list): self.flags: list = flags self.configs = Configs self.session = Session diff --git a/slpkg/main.py b/slpkg/main.py index 7b85cc79..413ccb87 100644 --- a/slpkg/main.py +++ b/slpkg/main.py @@ -24,7 +24,7 @@ from slpkg.update_repository import UpdateRepository class Argparse: - def __init__(self, args): + def __init__(self, args: list): self.args = args self.flags = [] self.configs = Configs diff --git a/slpkg/queries.py b/slpkg/queries.py index 7b57110e..1778f250 100644 --- a/slpkg/queries.py +++ b/slpkg/queries.py @@ -11,7 +11,7 @@ from slpkg.models.models import session as Session class SBoQueries: """ Queries class for the sbo repository. """ - def __init__(self, name): + def __init__(self, name: str): self.name = name self.session = Session self.configs = Configs @@ -20,12 +20,12 @@ class SBoQueries: if self.name in self.black.get(): self.name = '' - def names(self): + def names(self) -> list: """ 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( SBoTable.name).filter(SBoTable.name == self.name).first() @@ -34,7 +34,7 @@ class SBoQueries: return sbo[0] return '' - def location(self): + def location(self) -> str: """ Returns the category of a slackbuild. """ location = self.session.query( SBoTable.location).filter(SBoTable.name == self.name).first() @@ -43,7 +43,7 @@ class SBoQueries: return location[0] return '' - def sources(self): + def sources(self) -> str: """ Returns the source of a slackbuild. """ source, source64 = self.session.query( SBoTable.download, SBoTable.download64).filter( @@ -53,7 +53,7 @@ class SBoQueries: return self._chose_arch(source, source64) return '' - def requires(self): + def requires(self) -> str: """ Returns the requirements of a slackbuild. """ requires = self.session.query( SBoTable.requires).filter( @@ -67,7 +67,7 @@ class SBoQueries: return requires return '' - def version(self): + def version(self) -> str: """ Returns the version of a slackbuild. """ version = self.session.query( SBoTable.version).filter( @@ -77,7 +77,7 @@ class SBoQueries: return version[0] return '' - def checksum(self): + def checksum(self) -> str: """ Returns the source checkcum. """ md5sum, md5sum64, = [], [] mds5, md5s64 = self.session.query( @@ -93,7 +93,7 @@ class SBoQueries: return self._chose_arch(md5sum, md5sum64) return '' - def description(self): + def description(self) -> str: """ Returns the slackbuild description. """ desc = self.session.query( SBoTable.short_description).filter( @@ -103,7 +103,7 @@ class SBoQueries: return desc[0] return '' - def files(self): + def files(self) -> str: """ Returns the files of a slackbuild. """ files = self.session.query( SBoTable.files).filter( @@ -113,7 +113,7 @@ class SBoQueries: return files[0] return '' - def _chose_arch(self, arch, arch64): + def _chose_arch(self, arch: str, arch64: str) -> str: """ Choosing the right arch. """ if self.configs.os_arch == 'x86_64' and arch64: return arch64 diff --git a/slpkg/remove_packages.py b/slpkg/remove_packages.py index 311f81b0..6556e4f2 100644 --- a/slpkg/remove_packages.py +++ b/slpkg/remove_packages.py @@ -13,7 +13,7 @@ from slpkg.models.models import session as Session class RemovePackages: """ Removes installed packages. """ - def __init__(self, packages, flags): + def __init__(self, packages: list, flags: list): self.packages = packages self.flags = flags self.session = Session diff --git a/slpkg/search.py b/slpkg/search.py index f3767dcc..4effad2d 100644 --- a/slpkg/search.py +++ b/slpkg/search.py @@ -12,7 +12,7 @@ class SearchPackage: def __init__(self): self.colors = Configs.colour - def package(self, packages): + def package(self, packages: list): """ Searching and print the matched slackbuilds. """ color = self.colors() cyan = color['cyan'] diff --git a/slpkg/slackbuild.py b/slpkg/slackbuild.py index f9cb42a3..b0e44766 100644 --- a/slpkg/slackbuild.py +++ b/slpkg/slackbuild.py @@ -21,7 +21,7 @@ from slpkg.models.models import session as Session class 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.flags = flags self.install = install diff --git a/slpkg/utilities.py b/slpkg/utilities.py index 5fb5dc4f..eb6db319 100644 --- a/slpkg/utilities.py +++ b/slpkg/utilities.py @@ -16,7 +16,7 @@ class Utilities: self.configs = Configs self.black = Blacklist() - def is_installed(self, name: str): + def is_installed(self, name: str) -> str: """ Returns the installed package name. """ for package in os.listdir(self.configs.log_packages): pkg = self.split_installed_pkg(package)[0] @@ -52,7 +52,7 @@ class Utilities: if not os.path.isdir(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. """ name = '-'.join(package.split('-')[:-3]) version = ''.join(package[len(name):].split('-')[:-2]) diff --git a/slpkg/views/version.py b/slpkg/views/version.py index 5610a0eb..aa9c19cc 100644 --- a/slpkg/views/version.py +++ b/slpkg/views/version.py @@ -6,11 +6,11 @@ class Version: """ Print the version. """ def __init__(self): - self.version_info: tuple = (4, 3, 9) - 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' + self.version_info = (4, 3, 9) + 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' def view(self): """ Prints the version. """ diff --git a/slpkg/views/view_package.py b/slpkg/views/view_package.py index 60e43104..238ba2cf 100644 --- a/slpkg/views/view_package.py +++ b/slpkg/views/view_package.py @@ -18,7 +18,7 @@ class ViewPackage: self.configs = Configs self.colors = self.configs.colour - def package(self, packages): + def package(self, packages: list): """ View the packages from the repository. """ color = self.colors() green = color['green'] @@ -78,7 +78,7 @@ class ViewPackage: f'\nREADME: {cyan}{readme.data.decode()}{endc}') @staticmethod - def http_request(link): + def http_request(link: str) -> str: """ Http get request. """ http = urllib3.PoolManager() return http.request('GET', link) diff --git a/slpkg/views/views.py b/slpkg/views/views.py index ae8ef184..4d774691 100644 --- a/slpkg/views/views.py +++ b/slpkg/views/views.py @@ -14,7 +14,7 @@ from slpkg.models.models import session as Session class ViewMessage: """ Print some messages before. """ - def __init__(self, flags): + def __init__(self, flags: list): self.flags = flags self.configs = Configs self.colors = self.configs.colour @@ -170,7 +170,7 @@ class ViewMessage: print(f'\n{color["grey"]}Total {installed + upgraded} packages ' f'will be removed.{color["endc"]}') - def logs_packages(self, dependencies): + def logs_packages(self, dependencies: list): """ View the logging packages. """ print('The following logs will be removed:\n') color = self.colors()