X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fchanges.py;h=90ce2311c17b8e8cea778b38820862fe0b1527e5;hb=df610ec6b921b869c4e4a25629a0aff3f13a03ae;hp=5cd26e2a69e071689e5adba343f0590a1973b3f1;hpb=3b1a95b1ac0b05ca86ac1fde96ca51fdae429ccd;p=dak.git diff --git a/daklib/changes.py b/daklib/changes.py index 5cd26e2a..90ce2311 100755 --- a/daklib/changes.py +++ b/daklib/changes.py @@ -29,6 +29,9 @@ Changes class for dak import os import stat +import time + +import datetime from cPickle import Unpickler, Pickler from errno import EPERM @@ -36,6 +39,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 +81,10 @@ CHANGESFIELDS_DSCFILES_OPTIONAL = [ "files id" ] __all__.append('CHANGESFIELDS_DSCFILES_OPTIONAL') +CHANGESFIELDS_ORIGFILES = [ "id", "location" ] + +__all__.append('CHANGESFIELDS_ORIGFILES') + ############################################################################### class Changes(object): @@ -91,10 +100,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 @@ -150,7 +156,6 @@ class Changes(object): or the text of a warning if there are """ - conf = Config() summary = "" # Abandon the check if it's a non-sourceful upload @@ -166,13 +171,66 @@ class Changes(object): entry["override section"]) if entry["priority"] != "-": - if entry["priority"] != entry["override_priority"]: + if entry["priority"] != entry["override priority"]: summary += "%s: package says priority is %s, override says %s.\n" % (name, entry["priority"], entry["override priority"]) 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', 'changedby' ]: + 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): """ @@ -190,8 +248,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() @@ -241,6 +315,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. @@ -282,8 +367,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()