Updated for generators

This commit is contained in:
Dimitris Zlatanidis 2023-04-04 12:55:37 +03:00
parent 96a43b4d3e
commit 8a34ce52a7
5 changed files with 31 additions and 21 deletions

View file

@ -1,7 +1,7 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from typing import Union
from typing import Union, Generator
from slpkg.configs import Configs
from slpkg.blacklist import Blacklist
@ -32,21 +32,25 @@ class BinQueries(Configs):
return count
def all_package_names_by_repo(self) -> list:
def all_package_names_by_repo(self) -> Generator:
""" Returns all the names of the binaries packages. """
pkgs: tuple = self.session.query(
BinariesTable.name).where(
BinariesTable.repo == self.repo).all()
return [pkg[0] for pkg in pkgs]
for pkg in pkgs:
if pkg[0] not in self.black.packages():
yield pkg[0]
def all_binaries_packages_by_repo(self) -> list:
def all_binaries_packages_by_repo(self) -> Generator:
""" Returns all the binaries packages. """
pkgs: tuple = self.session.query(
BinariesTable.package).where(
BinariesTable.repo == self.repo).all()
return [pkg[0] for pkg in pkgs]
for pkg in pkgs:
if pkg[0] not in self.black.packages():
yield pkg[0]
def all_package_names_from_repositories(self) -> tuple:
""" Returns the package name with the repo. """

View file

@ -4,6 +4,7 @@
import os
import sys
from pathlib import Path
from typing import Generator
from slpkg.checks import Check
from slpkg.upgrade import Upgrade
@ -417,9 +418,9 @@ class Argparse(Configs):
choices: list = []
title: str = f' Choose packages you want to {method} '
repo_packages: list = SBoQueries('').sbos()
repo_packages: Generator = SBoQueries('').sbos()
if self.utils.is_option(self.flag_binaries, self.flags):
repo_packages: list = BinQueries('', self.binary_repo).all_package_names_by_repo()
repo_packages: Generator = BinQueries('', self.binary_repo).all_package_names_by_repo()
installed: list = self.utils.installed_packages

View file

@ -1,7 +1,7 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from typing import Union
from typing import Union, Generator
from sqlalchemy import inspect
from slpkg.configs import Configs
@ -45,15 +45,18 @@ class SBoQueries(Configs):
return repo
def sbos(self) -> list:
def sbos(self) -> Generator:
""" Returns all the slackbuilds. """
sbos: tuple = self.session.query(self.sbo_table.name).all() # type: ignore
return [sbo[0] for sbo in sbos]
sbos: tuple = self.session.query(self.sbo_table.name).all()
for sbo in sbos:
if sbo[0] not in self.black.packages():
yield sbo[0]
def slackbuild(self) -> str:
""" Returns a slackbuild. """
sbo: tuple = self.session.query(
self.sbo_table.name).filter(self.sbo_table.name == self.name).first() # type: ignore
self.sbo_table.name).filter(self.sbo_table.name == self.name).first()
if sbo:
return sbo[0]
@ -62,7 +65,7 @@ class SBoQueries(Configs):
def location(self) -> str:
""" Returns the category of a slackbuild. """
location: tuple = self.session.query(
self.sbo_table.location).filter(self.sbo_table.name == self.name).first() # type: ignore
self.sbo_table.location).filter(self.sbo_table.name == self.name).first()
if location:
return location[0]
@ -71,7 +74,7 @@ class SBoQueries(Configs):
def sources(self) -> list:
""" Returns the source of a slackbuild. """
source, source64 = self.session.query(
self.sbo_table.download, self.sbo_table.download64).filter( # type: ignore
self.sbo_table.download, self.sbo_table.download64).filter(
self.sbo_table.name == self.name).first()
if self.os_arch == 'x86_64' and source64:
@ -106,7 +109,7 @@ class SBoQueries(Configs):
def checksum(self) -> list:
""" Returns the source checksum. """
mds5, md5s64 = self.session.query(
self.sbo_table.md5sum, self.sbo_table.md5sum64).filter( # type: ignore
self.sbo_table.md5sum, self.sbo_table.md5sum64).filter(
self.sbo_table.name == self.name).first()
if self.os_arch == 'x86_64' and md5s64:
@ -117,7 +120,7 @@ class SBoQueries(Configs):
def description(self) -> str:
""" Returns the slackbuild description. """
desc: tuple = self.session.query(
self.sbo_table.short_description).filter( # type: ignore
self.sbo_table.short_description).filter(
self.sbo_table.name == self.name).first()
if desc:
@ -127,7 +130,7 @@ class SBoQueries(Configs):
def files(self) -> str:
""" Returns the files of a slackbuild. """
files: tuple = self.session.query(
self.sbo_table.files).filter( # type: ignore
self.sbo_table.files).filter(
self.sbo_table.name == self.name).first()
if files:

View file

@ -1,6 +1,8 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from typing import Generator
from slpkg.configs import Configs
from slpkg.utilities import Utilities
from slpkg.sbos.queries import SBoQueries
@ -55,7 +57,7 @@ class SearchPackage(Configs):
print(f'{repository}{self.cyan}{pr[0]}{self.endc} {self.yellow}{version}{self.endc}'
f'{self.green}{desc}{self.endc}')
else:
pkg_repo: list = BinQueries('', repo).all_package_names_by_repo()
pkg_repo: Generator = BinQueries('', repo).all_package_names_by_repo()
for pkg in packages:
for pr in pkg_repo:
@ -71,7 +73,7 @@ class SearchPackage(Configs):
else:
# Searching for slackbuilds.
names: list = SBoQueries('').sbos()
names: Generator = SBoQueries('').sbos()
for name in names:
for package in packages:

View file

@ -27,9 +27,9 @@ class Upgrade(Configs):
def packages(self) -> Generator[str, None, None]:
""" Compares version of packages and returns the maximum. """
if self.utils.is_option(self.flag_bin_repository, self.flags):
repo_packages: list = BinQueries('', self.repo).all_package_names_by_repo()
repo_packages: Generator = BinQueries('', self.repo).all_package_names_by_repo()
else:
repo_packages: list = SBoQueries('').sbos()
repo_packages: Generator = SBoQueries('').sbos()
for pkg in self.all_installed:
inst_package: str = self.utils.split_binary_pkg(pkg)[0]