mirror of
https://gitlab.com/dslackw/slpkg.git
synced 2025-01-30 20:34:38 +01:00
Updated for typing
This commit is contained in:
parent
b6b9a80d64
commit
c6c222bd4f
1 changed files with 2 additions and 9 deletions
|
@ -41,7 +41,7 @@ class Utilities(Configs):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
def all_installed(self) -> dict:
|
def all_installed(self) -> tuple:
|
||||||
""" Return all installed packages from /val/log/packages folder. """
|
""" Return all installed packages from /val/log/packages folder. """
|
||||||
for file in self.log_packages.glob(self.file_pattern):
|
for file in self.log_packages.glob(self.file_pattern):
|
||||||
name: str = self.split_package(file.name)['name']
|
name: str = self.split_package(file.name)['name']
|
||||||
|
@ -78,7 +78,7 @@ class Utilities(Configs):
|
||||||
build: str = ''.join(re.findall(r'\d+', build_tag[:2]))
|
build: str = ''.join(re.findall(r'\d+', build_tag[:2]))
|
||||||
pkg_tag: str = build_tag[len(build):]
|
pkg_tag: str = build_tag[len(build):]
|
||||||
|
|
||||||
split: dict = {
|
split: dict[str] = {
|
||||||
'name': name,
|
'name': name,
|
||||||
'version': version,
|
'version': version,
|
||||||
'arch': arch,
|
'arch': arch,
|
||||||
|
@ -104,7 +104,6 @@ class Utilities(Configs):
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.startswith('BUILD=$'):
|
if line.startswith('BUILD=$'):
|
||||||
build = ''.join(re.findall(r'\d+', line))
|
build = ''.join(re.findall(r'\d+', line))
|
||||||
|
|
||||||
return build
|
return build
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -117,7 +116,6 @@ class Utilities(Configs):
|
||||||
def read_packages_from_file(self, file: Path) -> Generator:
|
def read_packages_from_file(self, file: Path) -> Generator:
|
||||||
""" Reads packages from file and split these to list. """
|
""" Reads packages from file and split these to list. """
|
||||||
try:
|
try:
|
||||||
|
|
||||||
with open(file, 'r', encoding='utf-8') as pkgs:
|
with open(file, 'r', encoding='utf-8') as pkgs:
|
||||||
packages: list = pkgs.read().splitlines()
|
packages: list = pkgs.read().splitlines()
|
||||||
|
|
||||||
|
@ -125,9 +123,7 @@ class Utilities(Configs):
|
||||||
if package and not package.startswith('#'):
|
if package and not package.startswith('#'):
|
||||||
if '#' in package:
|
if '#' in package:
|
||||||
package = package.split('#')[0].strip()
|
package = package.split('#')[0].strip()
|
||||||
|
|
||||||
yield package
|
yield package
|
||||||
|
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
logger = logging.getLogger(LoggingConfig.date)
|
logger = logging.getLogger(LoggingConfig.date)
|
||||||
logger.exception(f'{self.__class__.__name__}: '
|
logger.exception(f'{self.__class__.__name__}: '
|
||||||
|
@ -166,7 +162,6 @@ class Utilities(Configs):
|
||||||
def convert_file_sizes(size: int) -> str:
|
def convert_file_sizes(size: int) -> str:
|
||||||
""" Convert file sizes. """
|
""" Convert file sizes. """
|
||||||
units: tuple = ('KB', 'MB', 'GB')
|
units: tuple = ('KB', 'MB', 'GB')
|
||||||
|
|
||||||
for unit in units:
|
for unit in units:
|
||||||
if size < 1000:
|
if size < 1000:
|
||||||
return f'{size:.0f} {unit}'
|
return f'{size:.0f} {unit}'
|
||||||
|
@ -176,11 +171,9 @@ class Utilities(Configs):
|
||||||
def apply_package_pattern(data: dict, packages: list) -> list:
|
def apply_package_pattern(data: dict, packages: list) -> list:
|
||||||
""" If the '*' applied returns all the package names. """
|
""" If the '*' applied returns all the package names. """
|
||||||
for pkg in packages:
|
for pkg in packages:
|
||||||
|
|
||||||
if pkg == '*':
|
if pkg == '*':
|
||||||
packages.remove(pkg)
|
packages.remove(pkg)
|
||||||
packages.extend(list(data.keys()))
|
packages.extend(list(data.keys()))
|
||||||
|
|
||||||
return packages
|
return packages
|
||||||
|
|
||||||
def blacklist_pattern(self, name: str) -> bool:
|
def blacklist_pattern(self, name: str) -> bool:
|
||||||
|
|
Loading…
Add table
Reference in a new issue