From: Mark Hymers Date: Tue, 3 Nov 2009 17:53:05 +0000 (+0000) Subject: manage_build_queues fixups X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=b5c1801337d0115ceff491e0279f2cbd25c5d49b;p=dak.git manage_build_queues fixups Signed-off-by: Mark Hymers --- diff --git a/dak/manage_build_queues.py b/dak/manage_build_queues.py index 402521f0..ba73d1af 100755 --- a/dak/manage_build_queues.py +++ b/dak/manage_build_queues.py @@ -76,7 +76,7 @@ def main (): queue = get_build_queue(q.lower(), session) if queue: Logger.log(['cleaning queue %s using datetime %s' % (q, starttime)]) - queue.clean_and_update(starttime) + queue.clean_and_update(starttime, dryrun=Options["No-Action"]) else: Logger.log(['cannot find queue %s' % q]) diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 8543ab10..dd5aa2de 100644 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -477,7 +477,7 @@ class BuildQueue(object): def __repr__(self): return '' % self.queue_name - def write_metadata(self, ourtime, force=False): + def write_metadata(self, starttime, force=False): # Do we write out metafiles? if not (force or self.generate_metadata): return @@ -491,8 +491,7 @@ class BuildQueue(object): try: # Grab files we want to include - newer = session.query(BuildQueueFile).filter_by(build_queue_id = 1).filter(BuildQueueFile.lastused > ourtime).all() - + newer = session.query(BuildQueueFile).filter_by(build_queue_id = self.queue_id).filter(BuildQueueFile.lastused + timedelta(seconds=self.stay_of_execution) > starttime).all() # Write file list with newer files (fl_fd, fl_name) = mkstemp() for n in newer: @@ -562,13 +561,11 @@ class BuildQueue(object): """WARNING: This routine commits for you""" session = DBConn().session().object_session(self) - ourtime = starttime + timedelta(seconds=self.stay_of_execution) - if self.generate_metadata: - self.write_metadata(ourtime) + self.write_metadata(starttime) # Grab files older than our execution time - older = session.query(BuildQueueFile).filter_by(build_queue_id = 1).filter(BuildQueueFile.lastused <= ourtime).all() + older = session.query(BuildQueueFile).filter_by(build_queue_id = self.queue_id).filter(BuildQueueFile.lastused + timedelta(seconds=self.stay_of_execution) <= starttime).all() for o in older: killdb = False @@ -576,6 +573,7 @@ class BuildQueue(object): if dryrun: print "I: Would have removed %s from the queue" else: + print "I: Removing %s from the queue" os.unlink(o.fullpath) killdb = True except OSError, e: @@ -591,6 +589,22 @@ class BuildQueue(object): session.commit() + for f in os.listdir(self.path): + if f.startswith('Packages') or f.startswith('Source') or f.startswith('Release'): + continue + + try: + r = session.query(BuildQueueFile).filter_by(build_queue_id = self.queue_id).filter_by(filename = f).one() + except NoResultFound: + fp = os.path.join(self.path, f) + if dryrun: + print "I: Would remove unused link %s" % fp + else: + print "I: Removing unused link %s" % fp + try: + os.unlink(fp) + except OSError: + print "E: Failed to unlink unreferenced file %s" % r.fullpath def add_file_from_pool(self, poolfile): """Copies a file into the pool. Assumes that the PoolFile object is