X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fchanges.py;h=fd09cb7f2086b4c96ebaeffd21da5a047ef6a31a;hb=eeae103589a343674d93a674e77efc2c724fa2a9;hp=1bb90753601bd9f3b0e220363b39e7aeac6932a9;hpb=0dada7c5846e0ae676bbe0b81c1065fe75ca9b86;p=dak.git diff --git a/daklib/changes.py b/daklib/changes.py index 1bb90753..fd09cb7f 100755 --- a/daklib/changes.py +++ b/daklib/changes.py @@ -29,6 +29,8 @@ Changes class for dak import os import stat + +import datetime from cPickle import Unpickler, Pickler from errno import EPERM @@ -36,6 +38,8 @@ from apt_inst import debExtractControl from apt_pkg import ParseSection from utils import open_file, fubar, poolify +from config import * +from dbconn import * ############################################################################### @@ -76,6 +80,10 @@ CHANGESFIELDS_DSCFILES_OPTIONAL = [ "files id" ] __all__.append('CHANGESFIELDS_DSCFILES_OPTIONAL') +CHANGESFIELDS_ORIGFILES = [ "id", "location" ] + +__all__.append('CHANGESFIELDS_ORIGFILES') + ############################################################################### class Changes(object): @@ -91,10 +99,7 @@ class Changes(object): self.dsc = {} self.files = {} self.dsc_files = {} - - self.orig_tar_id = None - self.orig_tar_location = "" - self.orig_tar_gz = None + self.orig_files = {} def file_summary(self): # changes["distribution"] may not exist in corner cases @@ -172,6 +177,59 @@ class Changes(object): return summary + def remove_known_changes(self, session=None): + if session is None: + session = DBConn().session() + privatetrans = True + + session.delete(get_knownchange(self.changes_file, session)) + + if privatetrans: + session.commit() + session.close() + + + def mark_missing_fields(self): + """add "missing" in fields which we will require for the known_changes table""" + for key in ['urgency', 'maintainer', 'fingerprint', 'changed-by' ]: + if (not self.changes.has_key(key)) or (not self.changes[key]): + self.changes[key]='missing' + + def add_known_changes(self, dirpath, session=None): + """add "missing" in fields which we will require for the known_changes table""" + cnf = Config() + privatetrans = False + if session is None: + session = DBConn().session() + privatetrans = True + + changesfile = os.path.join(dirpath, self.changes_file) + filetime = datetime.datetime.fromtimestamp(os.path.getctime(changesfile)) + + self.mark_missing_fields() + + 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':self.changes["binary"], + 'architecture':self.changes["architecture"], + 'version':self.changes["version"], + 'distribution':self.changes["distribution"], + 'urgency':self.changes["urgency"], + 'maintainer':self.changes["maintainer"], + 'fingerprint':self.changes["fingerprint"], + 'changedby':self.changes["changed-by"], + 'date':self.changes["date"]} ) + + if privatetrans: + session.commit() + session.close() def load_dot_dak(self, changesfile): """ @@ -189,8 +247,24 @@ class Changes(object): self.files.update(p.load()) self.dsc_files.update(p.load()) - self.orig_tar_id = p.load() - self.orig_tar_location = p.load() + next_obj = p.load() + if isinstance(next_obj, dict): + self.orig_files.update(next_obj) + else: + # Auto-convert old dak files to new format supporting + # multiple tarballs + orig_tar_gz = None + for dsc_file in self.dsc_files.keys(): + if dsc_file.endswith(".orig.tar.gz"): + orig_tar_gz = dsc_file + self.orig_files[orig_tar_gz] = {} + if next_obj != None: + self.orig_files[orig_tar_gz]["id"] = next_obj + next_obj = p.load() + if next_obj != None and next_obj != "": + self.orig_files[orig_tar_gz]["location"] = next_obj + if len(self.orig_files[orig_tar_gz]) == 0: + del self.orig_files[orig_tar_gz] dump_file.close() @@ -240,6 +314,17 @@ class Changes(object): return ret + def sanitised_orig_files(self): + ret = {} + for name, entry in self.orig_files.items(): + ret[name] = {} + # Optional orig_files fields + for i in CHANGESFIELDS_ORIGFILES: + if entry.has_key(i): + ret[name][i] = entry[i] + + return ret + def write_dot_dak(self, dest_dir): """ Dump ourself into a cPickle file. @@ -281,8 +366,7 @@ class Changes(object): p.dump(self.sanitised_dsc()) p.dump(self.sanitised_files()) p.dump(self.sanitised_dsc_files()) - p.dump(self.orig_tar_id) - p.dump(self.orig_tar_location) + p.dump(self.sanitised_orig_files()) dump_file.close()