X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fdbconn.py;h=4e54a3272ea75a4ba1f7c71b85ad0f7affb3b0eb;hb=b7f4f39d244e3282303015c9ff4a116252a64613;hp=2a9618348f474de30f34e01ef6b690f70eddfed2;hpb=1f586de5bee300db6f4b49d2643924b7a7e7776b;p=dak.git diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 2a961834..4e54a327 100644 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -1437,6 +1437,75 @@ class DBChange(object): def __repr__(self): return '' % 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) + + # Remove changes_pool_files entries + for pf in self.poolfiles: + self.poolfiles.remove(pf) + + # Remove change + for cf in self.files: + self.files.remove(cf) + + # Clear out of queue + self.in_queue = None + self.approved_for_id = None + __all__.append('DBChange') @session_wrapper @@ -2843,7 +2912,7 @@ class DBConn(object): poolfiles = relation(PoolFile, secondary=self.tbl_changes_pool_files, backref="changeslinks"), - filetime = self.tbl_changes.c.filetime, + seen = self.tbl_changes.c.seen, source = self.tbl_changes.c.source, binaries = self.tbl_changes.c.binaries, architecture = self.tbl_changes.c.architecture, @@ -2852,7 +2921,7 @@ class DBConn(object): maintainer = self.tbl_changes.c.maintainer, changedby = self.tbl_changes.c.changedby, date = self.tbl_changes.c.date, - version = self.tbl_changes.c.version + version = self.tbl_changes.c.version, files = relation(ChangePendingFile, secondary=self.tbl_changes_pending_files_map, backref="changesfile"),