]> git.decadent.org.uk Git - dak.git/commitdiff
don't do the same thing twice, do it once, but correctly
authorMark Hymers <mhy@debian.org>
Sun, 15 Nov 2009 18:52:26 +0000 (18:52 +0000)
committerMark Hymers <mhy@debian.org>
Sun, 15 Nov 2009 18:52:26 +0000 (18:52 +0000)
Signed-off-by: Mark Hymers <mhy@debian.org>
dak/process_upload.py
daklib/changes.py
daklib/dbconn.py

index ab9a3197ddc199ebe34a1eed5d5e24b6897ce9ae..33fff0dc8059af7834b94619b8c402cccc2e31e2 100755 (executable)
@@ -293,14 +293,12 @@ def action(u, session):
         if not chg:
             chg = u.pkg.add_known_changes(holding.holding_dir, session=session)
         package_to_queue(u, summary, short_summary, policyqueue, chg, session)
-        chg.upload_into_db(u, holding.holding_dir)
         session.commit()
         u.remove()
     elif answer == queuekey:
         if not chg:
             chg = u.pkg.add_known_changes(holding.holding_dir, session=session)
         QueueInfo[qu]["process"](u, summary, short_summary, chg, session)
-        chg.upload_into_db(u, holding.holding_dir)
         session.commit()
         u.remove()
     elif answer == 'Q':
index 4fdf0a60995e4f124d659ea64059a4b234736c80..f56ca96c436ed21bac2765b74313b63ec42e2c8c 100644 (file)
@@ -221,17 +221,53 @@ class Changes(object):
         
         session.add(chg)
 
-        chg_files = []
-        for chg_fn in self.files.keys():
-            cpf = ChangePendingFile()
-            cpf.filename = chg_fn
-            cpf.size = self.files[chg_fn]['size']
-            cpf.md5sum = self.files[chg_fn]['md5sum']
-
-            session.add(cpf)
-            chg_files.append(cpf)
-
-        chg.files = chg_files
+        files = []
+        for chg_fn, entry in self.files.items():
+            try:
+                f = open(os.path.join(dirpath, chg_fn))
+                cpf = ChangePendingFile()
+                cpf.filename = chg_fn
+                cpf.size = entry['size']
+                cpf.md5sum = entry['md5sum']
+
+                if entry.has_key('sha1sum'):
+                    cpf.sha1sum = entry['sha1sum']
+                else:
+                    f.seek(0)
+                    cpf.sha1sum = apt_pkg.sha1sum(f)
+
+                if entry.has_key('sha256sum'):
+                    cpf.sha256sum = entry['sha256sum']
+                else:
+                    f.seek(0)
+                    cpf.sha256sum = apt_pkg.sha256sum(f)
+
+                session.add(cpf)
+                files.append(cpf)
+                f.close()
+
+            except IOError:
+                # Can't find the file, try to look it up in the pool
+                poolname = poolify(entry["source"], entry["component"])
+                l = get_location(cnf["Dir::Pool"], entry["component"], session=session)
+
+                found, poolfile = check_poolfile(os.path.join(poolname, chg_fn),
+                                                 entry['size'],
+                                                 entry["md5sum"],
+                                                 l.location_id,
+                                                 session=session)
+
+                if found is None:
+                    Logger.log(["E: Found multiple files for pool (%s) for %s" % (chg_fn, entry["component"])])
+                elif found is False and poolfile is not None:
+                    Logger.log(["E: md5sum/size mismatch for %s in pool" % (chg_fn)])
+                else:
+                    if poolfile is None:
+                        Logger.log(["E: Could not find %s in pool" % (chg_fn)])
+                    else:
+                        chg.poolfiles.append(poolfile)
+
+        chg.files = files
 
         session.commit()
         chg = session.query(DBChange).filter_by(changesname = self.changes_file).one();
index ecb610311bb23ad36cfecb81fa37c65f1a3032c6..7047f59bbc3ea5ad1f39b431c28a10037ed9b0ec 100644 (file)
@@ -1437,60 +1437,6 @@ class DBChange(object):
     def __repr__(self):
         return '<DBChange %s>' % self.changesname
 
-    def upload_into_db(self, u, path):
-        cnf = Config()
-        session = DBConn().session().object_session(self)
-
-        files = []
-        for chg_fn, entry in u.pkg.files.items():
-            try:
-                f = open(os.path.join(path, chg_fn))
-                cpf = ChangePendingFile()
-                cpf.filename = chg_fn
-                cpf.size = entry['size']
-                cpf.md5sum = entry['md5sum']
-
-                if entry.has_key('sha1sum'):
-                    cpf.sha1sum = entry['sha1sum']
-                else:
-                    f.seek(0)
-                    cpf.sha1sum = apt_pkg.sha1sum(f)
-
-                if entry.has_key('sha256sum'):
-                    cpf.sha256sum = entry['sha256sum']
-                else:
-                    f.seek(0)
-                    cpf.sha256sum = apt_pkg.sha256sum(f)
-
-                session.add(cpf)
-                files.append(cpf)
-                f.close()
-
-            except IOError:
-                # Can't find the file, try to look it up in the pool
-                from utils import poolify
-                poolname = poolify(entry["source"], entry["component"])
-                l = get_location(cnf["Dir::Pool"], entry["component"], session=session)
-
-                found, poolfile = check_poolfile(os.path.join(poolname, chg_fn),
-                                                 entry['size'],
-                                                 entry["md5sum"],
-                                                 l.location_id,
-                                                 session=session)
-
-                if found is None:
-                    Logger.log(["E: Found multiple files for pool (%s) for %s" % (chg_fn, entry["component"])])
-                elif found is False and poolfile is not None:
-                    Logger.log(["E: md5sum/size mismatch for %s in pool" % (chg_fn)])
-                else:
-                    if poolfile is None:
-                        Logger.log(["E: Could not find %s in pool" % (chg_fn)])
-                    else:
-                        chg.poolfiles.append(poolfile)
-
-        chg.files = files
-
-
     def clean_from_queue(self):
         session = DBConn().session().object_session(self)