def get_jobs(self, name, version=None, dist=None, arch=None): """Dump a job status""" if version: pkgs = Package.selectBy(name=name, version=version) else: pkgs = Package.selectBy(name=name) if not pkgs.count(): return [] retjobs = [] if dist and arch: for pkg in pkgs: retjobs.extend(Job.selectBy(package=pkg, dist=dist, arch=arch)) elif dist: for pkg in pkgs: retjobs.extend(Job.selectBy(package=pkg, dist=dist)) elif arch: for pkg in pkgs: retjobs.extend(Job.selectBy(package=pkg, arch=arch)) else: for pkg in pkgs: retjobs.extend(Job.selectBy(package=pkg)) return retjobs
def add_job(self, name, version, priority, dist, mailto=None, arch=None): """Add a job""" if not arch: arch = self.cfg.arch[0] if not Dists().get_dist(dist, arch): RebuilddLog.error("Couldn't find dist/arch in the config file for %s_%s on %s/%s, don't adding it" \ % (name, version, dist, arch)) return False pkgs = Package.selectBy(name=name, version=version) if pkgs.count(): # If several packages exists, just take the first pkg = pkgs[0] else: # Maybe we found no packages, so create a brand new one! pkg = Package(name=name, version=version, priority=priority) jobs_count = Job.selectBy(package=pkg, dist=dist, arch=arch, mailto=mailto, status=JobStatus.WAIT).count() if jobs_count: RebuilddLog.error("Job already existing for %s_%s on %s/%s, don't adding it" \ % (pkg.name, pkg.version, dist, arch)) return False job = Job(package=pkg, dist=dist, arch=arch) job.status = JobStatus.WAIT job.arch = arch job.mailto = mailto log = Log(job=job) RebuilddLog.info("Added job for %s_%s on %s/%s for %s" \ % (name, version, dist, arch, mailto)) return True
def get_new_jobs(self): """Feed jobs list with waiting jobs and lock them""" max_new = self.cfg.getint('build', 'max_jobs') count_current = len(self.jobs) with self.jobs_locker: if count_current >= max_new: return 0 jobs = [] for dist in Dists().dists: jobs.extend(Job.selectBy(status=JobStatus.WAIT, dist=dist.name, arch=dist.arch)[:max_new]) count_new = 0 for job in jobs: # Look for higher versions ? if self.cfg.getboolean('build', 'build_more_recent'): packages = Package.selectBy(name=job.package.name) candidate_packages = [] candidate_packages.extend(packages) candidate_packages.sort(cmp=Package.version_compare) candidate_packages.reverse() newjob = None # so there are packages with higher version number # try to see if there's a job for us for cpackage in candidate_packages: candidate_jobs = [] candidate_jobs.extend(Job.selectBy(package=cpackage, dist=job.dist, arch=job.arch)) for cjob in candidate_jobs: if newjob and newjob != cjob and cjob.status == JobStatus.WAIT: cjob.status = JobStatus.GIVEUP elif cjob.status == JobStatus.WAIT: newjob = cjob job = newjob # We have to check because it might have changed # between our first select and the build_more_recent stuffs if not job or job.status != JobStatus.WAIT: continue # Check dependencies if not job.is_allowed_to_build(): continue job.status = JobStatus.WAIT_LOCKED job.host = socket.gethostname() self.jobs.append(job) count_new += 1 count_current += 1 if count_current >= max_new: break return count_new
def GET(self, name=None, version=None): jobs = [] if version: pkg = Package.selectBy(name=name, version=version)[0] title = "%s %s" % (name, version) package = "%s/%s" % (name, version) else: pkg = Package.selectBy(name=name)[0] title = package = name jobs.extend(Job.selectBy(package=pkg)) return render.base(page=render.tab(jobs=jobs), \ hostname=socket.gethostname(), \ title=title, \ package=package, \ archs=RebuilddConfig().arch, \ dists=RebuilddConfig().get('build', 'dists').split(' '))
def GET_package(self, package=None): graph = self.graph_init() if package == "/": graph.title = "Build status" jobs = Job.selectBy() else: dindex = package.rindex("/") graph.title = "Build status for %s" % package[1:] pkg = Package.selectBy(version=package[dindex+1:], name=package[1:dindex])[0] jobs = Job.selectBy(package=pkg) graph.setData(self.compute_stats(jobs)) tmp = tempfile.TemporaryFile() graph.draw(tmp) tmp.seek(0) return tmp.read()
def GET_package(self, package=None): graph = self.graph_init() if package == "/": graph.title = "Build status" jobs = Job.selectBy() else: dindex = package.rindex("/") graph.title = "Build status for %s" % package[1:] pkg = Package.selectBy(version=package[dindex + 1:], name=package[1:dindex])[0] jobs = Job.selectBy(package=pkg) graph.setData(self.compute_stats(jobs)) tmp = tempfile.TemporaryFile() graph.draw(tmp) tmp.seek(0) return tmp.read()
def add_job(self, name, version, priority, dist, mailto=None, arch=None): """Add a job""" if not arch: arch = self.cfg.arch[0] if not Dists().get_dist(dist, arch): RebuilddLog.error("Couldn't find dist/arch in the config file for %s_%s on %s/%s, not adding it" \ % (name, version, dist, arch)) return False pkgs = Package.selectBy(name=name, version=version) if pkgs.count(): # If several packages exists, just take the first pkg = pkgs[0] else: # Maybe we found no packages, so create a brand new one! pkg = Package(name=name, version=version, priority=priority) jobs_count = Job.selectBy(package=pkg, dist=dist, arch=arch, mailto=mailto, status=JobStatus.WAIT).count() if jobs_count: RebuilddLog.error("Job already existing for %s_%s on %s/%s, not adding it" \ % (pkg.name, pkg.version, dist, arch)) return False job = Job(package=pkg, dist=dist, arch=arch) job.status = JobStatus.WAIT job.arch = arch job.mailto = mailto log = Log(job=job) RebuilddLog.info("Added job for %s_%s on %s/%s for %s" \ % (name, version, dist, arch, mailto)) return True
def get_new_jobs(self): """Feed jobs list with waiting jobs and lock them""" max_new = self.cfg.getint('build', 'max_jobs') count_current = len(self.jobs) with self.jobs_locker: if count_current >= max_new: return 0 jobs = [] for dist in Dists().dists: jobs.extend( Job.selectBy(status=JobStatus.WAIT, dist=dist.name, arch=dist.arch)[:max_new]) count_new = 0 for job in jobs: # Look for higher versions ? if self.cfg.getboolean('build', 'build_more_recent'): packages = Package.selectBy(name=job.package.name) candidate_packages = [] candidate_packages.extend(packages) candidate_packages.sort(cmp=Package.version_compare) candidate_packages.reverse() newjob = None # so there are packages with higher version number # try to see if there's a job for us for cpackage in candidate_packages: candidate_jobs = [] candidate_jobs.extend( Job.selectBy(package=cpackage, dist=job.dist, arch=job.arch)) for cjob in candidate_jobs: if newjob and newjob != cjob and cjob.status == JobStatus.WAIT: cjob.status = JobStatus.GIVEUP elif cjob.status == JobStatus.WAIT: newjob = cjob job = newjob # We have to check because it might have changed # between our first select and the build_more_recent stuffs if not job or job.status != JobStatus.WAIT: continue # Check dependencies if not job.is_allowed_to_build(): continue job.status = JobStatus.WAIT_LOCKED job.host = socket.gethostname() self.jobs.append(job) count_new += 1 count_current += 1 if count_current >= max_new: break return count_new