From 764b87d2692c7bb3480a127c728985aac3a59800 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Mon, 9 Oct 2017 23:22:34 +0100 Subject: [PATCH] Add command to list packages in a repository Signed-off-by: Michael Tremer --- src/buildservice/builds.py | 18 ++++++++++++++++++ src/scripts/pakfire-build-service | 28 ++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/buildservice/builds.py b/src/buildservice/builds.py index df57fec..f2e9ef7 100644 --- a/src/buildservice/builds.py +++ b/src/buildservice/builds.py @@ -59,6 +59,18 @@ def import_from_package(_pakfire, filename, distro=None, commit=None, type="rele class Builds(base.Object): + def _get_build(self, query, *args): + res = self.db.get(query, *args) + + if res: + return Build(self.backend, res.id, data=res) + + def _get_builds(self, query, *args): + res = self.db.query(query, *args) + + for row in res: + yield Build(self.backend, row.id, data=row) + def get_by_id(self, id, data=None): return Build(self.pakfire, id, data=data) @@ -418,6 +430,12 @@ class Build(base.Object): return cmp(self.pkg, other.pkg) + def __iter__(self): + jobs = self.backend.jobs._get_jobs("SELECT * FROM jobs \ + WHERE build_id = %s", self.id) + + return iter(sorted(jobs)) + @classmethod def create(cls, pakfire, pkg, type="release", owner=None, distro=None, public=True): assert type in ("release", "scratch", "test") diff --git a/src/scripts/pakfire-build-service b/src/scripts/pakfire-build-service index b4ee9db..17883b2 100644 --- a/src/scripts/pakfire-build-service +++ b/src/scripts/pakfire-build-service @@ -26,6 +26,9 @@ class Cli(object): # Cleanup uploads "cleanup-uploads" : self.backend.uploads.cleanup, + # List repository + "list-repository" : self._list_repository, + # Sends all queued messages "process-message-queue" : self.backend.messages.process_queue, @@ -58,6 +61,31 @@ class Cli(object): # Exit with error code sys.exit(r or 0) + def _list_repository(self, distro_name, repo_name, arch): + # Get distribution + distro = self.backend.distros.get_by_name(distro_name) + if not distro: + print >>sys.stderr, "Could not find distribution: %s" % distro_name + return 2 + + # Get repository + repo = distro.get_repo(repo_name) + if not repo: + print >>sys.stderr, "Could not find repository: %s" % repo_name + return 2 + + # Iterate through all of it + for build in repo: + for job in build: + if not job.type == "build": + continue + + if not job.arch in (arch, "noarch"): + continue + + for pkg in job: + print pkg + # main cli = Cli() -- 2.47.3