X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fchanges.py;h=d6ccaa0095d01cad07780be8d57d1bdda57507d9;hb=391f5ec09a119131dc846b796ca791f4cecc69e4;hp=4d23f9fadac9cf8b5152f8a0319657cb5c8ffb85;hpb=d78cd5b22422f0a9d4660970b2b506c39b6139f8;p=dak.git diff --git a/daklib/changes.py b/daklib/changes.py old mode 100755 new mode 100644 index 4d23f9fa..d6ccaa00 --- a/daklib/changes.py +++ b/daklib/changes.py @@ -34,10 +34,9 @@ import datetime from cPickle import Unpickler, Pickler from errno import EPERM -from apt_inst import debExtractControl -from apt_pkg import ParseSection +from apt_pkg import TagSection -from utils import open_file, fubar, poolify +from utils import open_file, fubar, poolify, deb_extract_control from config import * from dbconn import * @@ -127,7 +126,7 @@ class Changes(object): if entry["type"] == "deb": deb_fh = open_file(name) - summary += ParseSection(debExtractControl(deb_fh))["Description"] + '\n' + summary += TagSection(deb_extract_control(deb_fh))["Description"] + '\n' deb_fh.close() else: @@ -187,8 +186,41 @@ class Changes(object): if (not self.changes.has_key(key)) or (not self.changes[key]): self.changes[key]='missing' + def __get_file_from_pool(self, filename, entry, session, logger): + cnf = Config() + + if cnf.has_key("Dinstall::SuiteSuffix"): + component = cnf["Dinstall::SuiteSuffix"] + entry["component"] + else: + component = entry["component"] + + poolname = poolify(entry["source"], component) + l = get_location(cnf["Dir::Pool"], component, session=session) + + found, poolfile = check_poolfile(os.path.join(poolname, filename), + entry['size'], + entry["md5sum"], + l.location_id, + session=session) + + if found is None: + if logger is not None: + logger.log(["E: Found multiple files for pool (%s) for %s" % (filename, component)]) + return None + elif found is False and poolfile is not None: + if logger is not None: + logger.log(["E: md5sum/size mismatch for %s in pool" % (filename)]) + return None + else: + if poolfile is None: + if logger is not None: + logger.log(["E: Could not find %s in pool" % (filename)]) + return None + else: + return poolfile + @session_wrapper - def add_known_changes(self, dirpath, session=None): + def add_known_changes(self, dirpath, in_queue=None, session=None, logger=None): """add "missing" in fields which we will require for the known_changes table""" cnf = Config() @@ -202,26 +234,72 @@ class Changes(object): if isinstance(self.changes[key], dict): multivalues[key] = " ".join(self.changes[key].keys()) else: - multivalues[key] = self.changes[key].keys() - - session.execute( - """INSERT INTO known_changes - (changesname, seen, source, binaries, architecture, version, - distribution, urgency, maintainer, fingerprint, changedby, date) - VALUES (:changesfile,:filetime,:source,:binary, :architecture, - :version,:distribution,:urgency,:maintainer,:fingerprint,:changedby,:date)""", - { 'changesfile': self.changes_file, - 'filetime': filetime, - 'source': self.changes["source"], - 'binary': multivalues["binary"], - 'architecture': multivalues["architecture"], - 'version': self.changes["version"], - 'distribution': multivalues["distribution"], - 'urgency': self.changes["urgency"], - 'maintainer': self.changes["maintainer"], - 'fingerprint': self.changes["fingerprint"], - 'changedby': self.changes["changed-by"], - 'date': self.changes["date"]} ) + multivalues[key] = self.changes[key] + + chg = DBChange() + chg.changesname = self.changes_file + chg.seen = filetime + chg.in_queue_id = in_queue + chg.source = self.changes["source"] + chg.binaries = multivalues["binary"] + chg.architecture = multivalues["architecture"] + chg.version = self.changes["version"] + chg.distribution = multivalues["distribution"] + chg.urgency = self.changes["urgency"] + chg.maintainer = self.changes["maintainer"] + chg.fingerprint = self.changes["fingerprint"] + chg.changedby = self.changes["changed-by"] + chg.date = self.changes["date"] + + session.add(chg) + + 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 + poolfile = self.__get_file_from_pool(chg_fn, entry, session) + if poolfile: + chg.poolfiles.append(poolfile) + + chg.files = files + + # Add files referenced in .dsc, but not included in .changes + for name, entry in self.dsc_files.items(): + if self.files.has_key(name): + continue + + entry['source'] = self.changes['source'] + poolfile = self.__get_file_from_pool(name, entry, session, logger) + if poolfile: + chg.poolfiles.append(poolfile) + + session.commit() + chg = session.query(DBChange).filter_by(changesname = self.changes_file).one(); + + return chg def unknown_files_fields(self, name): return sorted(list( set(self.files[name].keys()) -