]> git.decadent.org.uk Git - dak.git/blobdiff - dak/import_known_changes.py
Convert exception handling to Python3 syntax.
[dak.git] / dak / import_known_changes.py
index 3702411d3cbe9908ad034c8fbae3493177241099..7b182d6f199123908f02b5406ea9ae580ea14c3c 100755 (executable)
@@ -32,7 +32,7 @@ import sys
 import os
 import logging
 import threading
-from daklib.dbconn import DBConn,get_knownchange
+from daklib.dbconn import DBConn, get_dbchange, get_policy_queue
 from daklib.config import Config
 import apt_pkg
 from daklib.dak_exceptions import DBUpdateError, InvalidDscError, ChangesUnicodeError
@@ -70,7 +70,6 @@ def check_signature (sig_filename, data_filename=""):
 
     keyrings = [
         "/home/joerg/keyring/keyrings/debian-keyring.gpg",
-        "/home/joerg/keyring/keyrings/debian-keyring.pgp",
         "/home/joerg/keyring/keyrings/debian-maintainers.gpg",
         "/home/joerg/keyring/keyrings/debian-role-keys.gpg",
         "/home/joerg/keyring/keyrings/emeritus-keyring.pgp",
@@ -128,37 +127,48 @@ class OneAtATime(object):
     """
     def __init__(self):
         self.next_in_line = None
-        self.next_lock = threading.Condition()
+        self.read_lock = threading.Condition()
+        self.write_lock = threading.Condition()
         self.die = False
 
     def plsDie(self):
         self.die = True
-        self.next_lock.notify()
+        self.write_lock.acquire()
+        self.write_lock.notifyAll()
+        self.write_lock.release()
+
+        self.read_lock.acquire()
+        self.read_lock.notifyAll()
+        self.read_lock.release()
 
     def enqueue(self, next):
-        self.next_lock.acquire()
+        self.write_lock.acquire()
         while self.next_in_line:
             if self.die:
                 return
-            self.next_lock.wait()
+            self.write_lock.wait()
 
         assert( not self.next_in_line )
         self.next_in_line = next
-        self.next_lock.notify()
-        self.next_lock.release()
+        self.write_lock.release()
+        self.read_lock.acquire()
+        self.read_lock.notify()
+        self.read_lock.release()
 
     def dequeue(self):
-        self.next_lock.acquire()
+        self.read_lock.acquire()
         while not self.next_in_line:
             if self.die:
                 return
-            self.next_lock.wait()
+            self.read_lock.wait()
 
         result = self.next_in_line
 
         self.next_in_line = None
-        self.next_lock.notify()
-        self.next_lock.release()
+        self.read_lock.release()
+        self.write_lock.acquire()
+        self.write_lock.notify()
+        self.write_lock.release()
 
         if isinstance(result, EndOfChanges):
             return None
@@ -190,12 +200,22 @@ class ChangesGenerator(threading.Thread):
     def run(self):
         cnf = Config()
         count = 1
-        for directory in [ "Accepted", "Byhand", "Done", "New", "ProposedUpdates", "OldProposedUpdates" ]:
-            checkdir = cnf["Dir::Queue::%s" % (directory) ]
+
+        dirs = []
+        dirs.append(cnf['Dir::Done'])
+
+        for queue_name in [ "byhand", "new", "proposedupdates", "oldproposedupdates" ]:
+            queue = get_policy_queue(queue_name)
+            if queue:
+                dirs.append(os.path.abspath(queue.path))
+            else:
+                warn("Could not find queue %s in database" % queue_name)
+
+        for checkdir in dirs:
             if os.path.exists(checkdir):
                 print "Looking into %s" % (checkdir)
 
-                for dirpath, dirnames, filenames in os.walk(checkdir, topdown=False):
+                for dirpath, dirnames, filenames in os.walk(checkdir, topdown=True):
                     if not filenames:
                         # Empty directory (or only subdirectories), next
                         continue
@@ -207,7 +227,7 @@ class ChangesGenerator(threading.Thread):
                                 continue
                             count += 1
 
-                            if not get_knownchange(changesfile, self.session):
+                            if not get_dbchange(changesfile, self.session):
                                 to_import = ChangesToImport(dirpath, changesfile, count)
                                 if self.die:
                                     return
@@ -246,22 +266,21 @@ class ImportThread(threading.Thread):
                 changesfile = os.path.join(to_import.dirpath, to_import.changesfile)
                 changes.changes = parse_changes(changesfile, signing_rules=-1)
                 changes.changes["fingerprint"] = check_signature(changesfile)
-                changes.add_known_changes(to_import.dirpath, self.session)
+                changes.add_known_changes(to_import.dirpath, session=self.session)
                 self.session.commit()
 
-            except InvalidDscError, line:
+            except InvalidDscError as line:
                 warn("syntax error in .dsc file '%s', line %s." % (f, line))
 
             except ChangesUnicodeError:
                 warn("found invalid changes file, not properly utf-8 encoded")
 
-
             except KeyboardInterrupt:
                 print("Caught C-c; on ImportThread. terminating.")
                 self.parent.plsDie()
                 sys.exit(1)
+
             except:
-                traceback.print_exc()
                 self.parent.plsDie()
                 sys.exit(1)
 
@@ -279,7 +298,7 @@ class ImportKnownChanges(object):
 
         except KeyboardInterrupt:
             print("Caught C-c; terminating.")
-            utils.warn("Caught C-c; terminating.")
+            warn("Caught C-c; terminating.")
             self.plsDie()
 
     def plsDie(self):