From 0c6ff54129764cd90e06fd1f32707b718790b2d8 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Sat, 25 Mar 2023 12:33:49 +0200 Subject: [PATCH] Updated for repo --- slpkg/binaries/queries.py | 65 +++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/slpkg/binaries/queries.py b/slpkg/binaries/queries.py index df46a8da..4f14f36f 100644 --- a/slpkg/binaries/queries.py +++ b/slpkg/binaries/queries.py @@ -11,27 +11,38 @@ from slpkg.models.models import BinariesTable class BinsQueries(Configs): """ Queries class for the sbo repository. """ - def __init__(self, name: str): + def __init__(self, name: str, repo=None): super(Configs, self).__init__() self.name: str = name + self.repo: str = repo self.session = Session self.repos = Repositories() + self.bin_repo: list = self.repos.enabled_repositories + if self.repo: + self.bin_repo: list = [self.repo] + self.black = Blacklist() if self.name in self.black.packages(): self.name: str = '' def all_name_packages(self) -> list: """ Returns all the name of the binaries packages. """ - pkgs: tuple = self.session.query(BinariesTable.name).all() + pkgs: tuple = self.session.query( + BinariesTable.name, + BinariesTable.repo.in_(self.bin_repo)).all() + return [pkg[0] for pkg in pkgs] - def all_name_packages_by_repo(self, repo) -> list: + def all_name_binaries_packages(self) -> list: """ Returns all the binaries packages by repo. """ - pkgs: tuple = self.session.query(BinariesTable.name).filter(BinariesTable.repo == repo).all() + pkgs: tuple = self.session.query( + BinariesTable.package, + BinariesTable.repo.in_(self.bin_repo)).all() + return [pkg[0] for pkg in pkgs] - def repo(self) -> str: + def repository(self) -> str: repository: tuple = self.session.query( BinariesTable.repo).filter(BinariesTable.name == self.name).first() @@ -41,7 +52,9 @@ class BinsQueries(Configs): def package_name(self) -> str: pkg: tuple = self.session.query( - BinariesTable.name).filter(BinariesTable.name == self.name).first() + BinariesTable.name).filter( + BinariesTable.name == self.name, + BinariesTable.repo.in_(self.bin_repo)).first() if pkg: return pkg[0] @@ -49,7 +62,9 @@ class BinsQueries(Configs): def package_bin(self) -> str: pkg: tuple = self.session.query( - BinariesTable.package).filter(BinariesTable.name == self.name).first() + BinariesTable.package).filter( + BinariesTable.name == self.name, + BinariesTable.repo.in_(self.bin_repo)).first() if pkg: return pkg[0] @@ -57,7 +72,9 @@ class BinsQueries(Configs): def version(self) -> str: pkg: tuple = self.session.query( - BinariesTable.version).filter(BinariesTable.name == self.name).first() + BinariesTable.version).filter( + BinariesTable.name == self.name, + BinariesTable.repo.in_(self.bin_repo)).first() if pkg: return pkg[0] @@ -65,7 +82,9 @@ class BinsQueries(Configs): def mirror(self) -> str: mir: tuple = self.session.query( - BinariesTable.mirror).filter(BinariesTable.name == self.name).first() + BinariesTable.mirror).filter( + BinariesTable.name == self.name, + BinariesTable.repo.in_(self.bin_repo)).first() if mir: return mir[0] @@ -73,7 +92,9 @@ class BinsQueries(Configs): def location(self) -> str: loc: tuple = self.session.query( - BinariesTable.location).filter(BinariesTable.name == self.name).first() + BinariesTable.location).filter( + BinariesTable.name == self.name, + BinariesTable.repo.in_(self.bin_repo)).first() if loc: return loc[0] @@ -81,7 +102,9 @@ class BinsQueries(Configs): def size_comp(self) -> str: size: tuple = self.session.query( - BinariesTable.size_comp).filter(BinariesTable.name == self.name).first() + BinariesTable.size_comp).filter( + BinariesTable.name == self.name, + BinariesTable.repo.in_(self.bin_repo)).first() if size: return size[0] @@ -89,7 +112,9 @@ class BinsQueries(Configs): def unsize_comp(self) -> str: size: tuple = self.session.query( - BinariesTable.unsize_comp).filter(BinariesTable.name == self.name).first() + BinariesTable.unsize_comp).filter( + BinariesTable.name == self.name, + BinariesTable.repo.in_(self.bin_repo)).first() if size: return size[0] @@ -97,7 +122,9 @@ class BinsQueries(Configs): def required(self) -> str: req: tuple = self.session.query( - BinariesTable.required).filter(BinariesTable.name == self.name).first() + BinariesTable.required).filter( + BinariesTable.name == self.name, + BinariesTable.repo.in_(self.bin_repo)).first() if req: return req[0] @@ -105,7 +132,9 @@ class BinsQueries(Configs): def conflicts(self) -> str: con: tuple = self.session.query( - BinariesTable.conflicts).filter(BinariesTable.name == self.name).first() + BinariesTable.conflicts).filter( + BinariesTable.name == self.name, + BinariesTable.repo.in_(self.bin_repo)).first() if con: return con[0] @@ -113,7 +142,9 @@ class BinsQueries(Configs): def suggests(self) -> str: sug: tuple = self.session.query( - BinariesTable.suggests).filter(BinariesTable.name == self.name).first() + BinariesTable.suggests).filter( + BinariesTable.name == self.name, + BinariesTable.repo.in_(self.bin_repo)).first() if sug: return sug[0] @@ -121,7 +152,9 @@ class BinsQueries(Configs): def description(self) -> str: desc: tuple = self.session.query( - BinariesTable.description).filter(BinariesTable.name == self.name).first() + BinariesTable.description).filter( + BinariesTable.name == self.name, + BinariesTable.repo.in_(self.bin_repo)).first() if desc: return desc[0]