]> git.decadent.org.uk Git - dak.git/blobdiff - daklib/dbconn.py
Fix up hand off to policy and buildd queues
[dak.git] / daklib / dbconn.py
index 0f4d4ede271627e21d8536e2296d9741eb1255d8..8d8e6af8ea4e43dc24845983bb5099eb8ef0f194 100755 (executable)
@@ -458,7 +458,7 @@ class BuildQueue(object):
         qf = QueueFile()
         qf.queue_id = self.queue_id
         qf.lastused = datetime.now()
-        qf.filename = dest
+        qf.filename = poolfile_basename
 
         targetpath = qf.fullpath
         queuepath = os.path.join(self.path, poolfile_basename)
@@ -1248,19 +1248,19 @@ __all__.append('KeyringACLMap')
 
 ################################################################################
 
-class KnownChange(object):
+class DBChange(object):
     def __init__(self, *args, **kwargs):
         pass
 
     def __repr__(self):
-        return '<KnownChange %s>' % self.changesname
+        return '<DBChange %s>' % self.changesname
 
-__all__.append('KnownChange')
+__all__.append('DBChange')
 
 @session_wrapper
-def get_knownchange(filename, session=None):
+def get_dbchange(filename, session=None):
     """
-    returns knownchange object for given C{filename}.
+    returns DBChange object for given C{filename}.
 
     @type archive: string
     @param archive: the name of the arhive
@@ -1273,14 +1273,14 @@ def get_knownchange(filename, session=None):
     @return: Archive object for the given name (None if not present)
 
     """
-    q = session.query(KnownChange).filter_by(changesname=filename)
+    q = session.query(DBChange).filter_by(changesname=filename)
 
     try:
         return q.one()
     except NoResultFound:
         return None
 
-__all__.append('get_knownchange')
+__all__.append('get_dbchange')
 
 ################################################################################
 
@@ -1965,6 +1965,7 @@ __all__.append('get_source_in_suite')
 def add_dsc_to_db(u, filename, session=None):
     entry = u.pkg.files[filename]
     source = DBSource()
+    pfs = []
 
     source.source = u.pkg.dsc["source"]
     source.version = u.pkg.dsc["version"] # NB: not files[file]["version"], that has no epoch
@@ -1983,6 +1984,7 @@ def add_dsc_to_db(u, filename, session=None):
         filename = entry["pool name"] + filename
         poolfile = add_poolfile(filename, entry, dsc_location_id, session)
         session.flush()
+        pfs.append(poolfile)
         entry["files id"] = poolfile.file_id
 
     source.poolfile_id = entry["files id"]
@@ -2026,6 +2028,7 @@ def add_dsc_to_db(u, filename, session=None):
             # FIXME: needs to check for -1/-2 and or handle exception
             if found and obj is not None:
                 files_id = obj.file_id
+                pfs.append(obj)
 
             # If still not found, add it
             if files_id is None:
@@ -2033,6 +2036,7 @@ def add_dsc_to_db(u, filename, session=None):
                 dentry["sha1sum"] = dfentry["sha1sum"]
                 dentry["sha256sum"] = dfentry["sha256sum"]
                 poolfile = add_poolfile(filename, dentry, dsc_location_id, session)
+                pfs.append(poolfile)
                 files_id = poolfile.file_id
 
         df.poolfile_id = files_id
@@ -2062,7 +2066,7 @@ def add_dsc_to_db(u, filename, session=None):
 
     session.flush()
 
-    return dsc_component, dsc_location_id
+    return dsc_component, dsc_location_id, pfs
 
 __all__.append('add_dsc_to_db')
 
@@ -2088,13 +2092,14 @@ def add_deb_to_db(u, filename, session=None):
     filename = entry["pool name"] + filename
     fullpath = os.path.join(cnf["Dir::Pool"], filename)
     if not entry.get("location id", None):
-        entry["location id"] = get_location(cnf["Dir::Pool"], entry["component"], utils.where_am_i(), session).location_id
+        entry["location id"] = get_location(cnf["Dir::Pool"], entry["component"], session=session).location_id
 
-    if not entry.get("files id", None):
+    if entry.get("files id", None):
+        poolfile = get_poolfile_by_id(bin.poolfile_id)
+        bin.poolfile_id = entry["files id"]
+    else:
         poolfile = add_poolfile(filename, entry, entry["location id"], session)
-        entry["files id"] = poolfile.file_id
-
-    bin.poolfile_id = entry["files id"]
+        bin.poolfile_id = entry["files id"] = poolfile.file_id
 
     # Find source id
     bin_sources = get_sources_from_name(entry["source package"], entry["source version"], session=session)
@@ -2125,6 +2130,8 @@ def add_deb_to_db(u, filename, session=None):
     #    session.rollback()
     #    raise MissingContents, "No contents stored for package %s, and couldn't determine contents of %s" % (bin.package, filename)
 
+    return poolfile
+
 __all__.append('add_deb_to_db')
 
 ################################################################################
@@ -2499,6 +2506,7 @@ class DBConn(Singleton):
         self.tbl_content_file_paths = Table('content_file_paths', self.db_meta, autoload=True)
         self.tbl_changes_pending_binary = Table('changes_pending_binaries', self.db_meta, autoload=True)
         self.tbl_changes_pending_files = Table('changes_pending_files', self.db_meta, autoload=True)
+        self.tbl_changes_pending_files_map = Table('changes_pending_files_map', self.db_meta, autoload=True)
         self.tbl_changes_pending_source = Table('changes_pending_source', self.db_meta, autoload=True)
         self.tbl_changes_pending_source_files = Table('changes_pending_source_files', self.db_meta, autoload=True)
         self.tbl_changes_pool_files = Table('changes_pool_files', self.db_meta, autoload=True)
@@ -2506,7 +2514,7 @@ class DBConn(Singleton):
         self.tbl_files = Table('files', self.db_meta, autoload=True)
         self.tbl_fingerprint = Table('fingerprint', self.db_meta, autoload=True)
         self.tbl_keyrings = Table('keyrings', self.db_meta, autoload=True)
-        self.tbl_known_changes = Table('known_changes', self.db_meta, autoload=True)
+        self.tbl_changes = Table('changes', self.db_meta, autoload=True)
         self.tbl_keyring_acl_map = Table('keyring_acl_map', self.db_meta, autoload=True)
         self.tbl_location = Table('location', self.db_meta, autoload=True)
         self.tbl_maintainer = Table('maintainer', self.db_meta, autoload=True)
@@ -2611,12 +2619,18 @@ class DBConn(Singleton):
                properties = dict(keyring_name = self.tbl_keyrings.c.name,
                                  keyring_id = self.tbl_keyrings.c.id))
 
-        mapper(KnownChange, self.tbl_known_changes,
-               properties = dict(known_change_id = self.tbl_known_changes.c.id,
+        mapper(DBChange, self.tbl_changes,
+               properties = dict(change_id = self.tbl_changes.c.id,
                                  poolfiles = relation(PoolFile,
                                                       secondary=self.tbl_changes_pool_files,
                                                       backref="changeslinks"),
-                                 files = relation(ChangePendingFile, backref="changesfile")))
+                                 files = relation(ChangePendingFile,
+                                                  secondary=self.tbl_changes_pending_files_map,
+                                                  backref="changesfile"),
+                                 in_queue_id = self.tbl_changes.c.in_queue,
+                                 in_queue = relation(PolicyQueue,
+                                                     primaryjoin=(self.tbl_changes.c.in_queue==self.tbl_policy_queue.c.id)),
+                                 approved_for_id = self.tbl_changes.c.approved_for))
 
         mapper(ChangePendingBinary, self.tbl_changes_pending_binary,
                properties = dict(change_pending_binary_id = self.tbl_changes_pending_binary.c.id))
@@ -2626,7 +2640,7 @@ class DBConn(Singleton):
 
         mapper(ChangePendingSource, self.tbl_changes_pending_source,
                properties = dict(change_pending_source_id = self.tbl_changes_pending_source.c.id,
-                                 change = relation(KnownChange),
+                                 change = relation(DBChange),
                                  maintainer = relation(Maintainer,
                                                        primaryjoin=(self.tbl_changes_pending_source.c.maintainer_id==self.tbl_maintainer.c.id)),
                                  changedby = relation(Maintainer,
@@ -2635,7 +2649,6 @@ class DBConn(Singleton):
                                  source_files = relation(ChangePendingFile,
                                                          secondary=self.tbl_changes_pending_source_files,
                                                          backref="pending_sources")))
-
         mapper(KeyringACLMap, self.tbl_keyring_acl_map,
                properties = dict(keyring_acl_map_id = self.tbl_keyring_acl_map.c.id,
                                  keyring = relation(Keyring, backref="keyring_acl_map"),