From: Michael Tremer Date: Tue, 21 Jun 2022 16:28:19 +0000 (+0000) Subject: builds: Automatically create any build jobs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b7bc6039fb6601d280c81d56cc9e94db76eb57c;p=pbs.git builds: Automatically create any build jobs Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/builds.py b/src/buildservice/builds.py index aa07332e..d79ba6d5 100644 --- a/src/buildservice/builds.py +++ b/src/buildservice/builds.py @@ -187,7 +187,9 @@ class Builds(base.Object): owner, ) - # XXX create jobs + # Create all jobs + build._create_jobs() + # XXX generate update ID? # XXX obsolete other builds @@ -666,33 +668,33 @@ class Build(base.DataObject): return ret - def create_autojobs(self, arches=None, **kwargs): - jobs = [] - - # Arches may be passed to this function. If not we use all arches - # this package supports. - if arches is None: - arches = self.supported_arches + def _create_jobs(self): + """ + Called after a build has been created and creates all jobs + """ + arches = [] - # Create a new job for every given archirecture. - #for arch in self.backend.arches.expand(arches): - # # Don't create jobs for src - # if arch == "src": - # continue - # - # job = self.add_job(arch, **kwargs) - # jobs.append(job) + # Collect all supported arches + for arch in self.distro.arches: + # Skip any unsupported arches + #if self.pkg.supported_arches and not arch in self.pkg.supported_arches: + # log.debug("Build %s does not support %s" % (self.pkg, arch)) + # continue - # Return all newly created jobs. - return jobs + arches.append(arch) - def add_job(self, arch, **kwargs): - job = self.backend.jobs.create(self, arch, **kwargs) + # Check for noarch + if not arches: + if "noarch" in self.pkg.supported_arches: + arches.append("noarch") - # Add new job to cache. - self.jobs.append(job) + # Raise an error if nothing is supported at all + if not arches: + raise RuntimeError("Build %s does not support any architectures" % self) - return job + # Create the jobs + for arch in arches: + self.backend.jobs.create(self, arch) ## Update stuff diff --git a/src/buildservice/jobs.py b/src/buildservice/jobs.py index 3c92ac64..63235e63 100644 --- a/src/buildservice/jobs.py +++ b/src/buildservice/jobs.py @@ -33,11 +33,27 @@ class Jobs(base.Object): yield Job(self.backend, row.id, data=row) def create(self, build, arch, test=False, superseeds=None): - job = self._get_job("INSERT INTO jobs(build_id, arch, test) \ - VALUES(%s, %s, %s) RETURNING *", build.id, arch, test) - job.log("created") + job = self._get_job(""" + INSERT INTO + jobs + ( + build_id, + arch, + test + ) + VALUES + ( + %s, + %s, + %s + ) + RETURNING *""", + build, + arch, + test, + ) - # Set cache for Build object. + # Set cache for Build object job.build = build # Mark if the new job superseeds some other job diff --git a/src/buildservice/packages.py b/src/buildservice/packages.py index 3520cb0c..d265e4db 100644 --- a/src/buildservice/packages.py +++ b/src/buildservice/packages.py @@ -123,6 +123,8 @@ class Packages(base.Object): print(pkg) + return pkg + def search(self, pattern, limit=None): """ Searches for packages that do match the query.