]> err.no Git - dak/commitdiff
manage_build_queues fixups
authorMark Hymers <mhy@debian.org>
Tue, 3 Nov 2009 17:53:05 +0000 (17:53 +0000)
committerMark Hymers <mhy@debian.org>
Tue, 3 Nov 2009 17:53:05 +0000 (17:53 +0000)
Signed-off-by: Mark Hymers <mhy@debian.org>
dak/manage_build_queues.py
daklib/dbconn.py

index 402521f0f4105afd2cac2d4175b42be26d151706..ba73d1af4617f030c355a1f166842a0cab79cab1 100755 (executable)
@@ -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])
 
index 8543ab101642dca14056a4d77fba72bc6091f24e..dd5aa2decf3dc2e4ab10ca0f6c293326cfa41a21 100644 (file)
@@ -477,7 +477,7 @@ class BuildQueue(object):
     def __repr__(self):
         return '<BuildQueue %s>' % 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