From: Mark Hymers Date: Thu, 23 Jul 2009 21:12:08 +0000 (+0100) Subject: make decode_dot_dak use Changes class X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=3b1a95b1ac0b05ca86ac1fde96ca51fdae429ccd;p=dak.git make decode_dot_dak use Changes class Signed-off-by: Mark Hymers --- diff --git a/dak/decode_dot_dak.py b/dak/decode_dot_dak.py index e6bc45b6..54b4ca12 100755 --- a/dak/decode_dot_dak.py +++ b/dak/decode_dot_dak.py @@ -28,7 +28,7 @@ import sys import apt_pkg -from daklib import queue +from daklib.changes import Changes from daklib import utils ################################################################################ @@ -55,77 +55,13 @@ def main(): if Options["Help"]: usage() - k = queue.Upload(Cnf) + for arg in sys.argv[1:]: arg = utils.validate_changes_file_arg(arg,require_changes=-1) - k.pkg.changes_file = arg - print "%s:" % (arg) - k.init_vars() - k.update_vars() - - changes = k.pkg.changes - print " Changes:" - # Mandatory changes fields - for i in [ "source", "version", "maintainer", "urgency", "changedby822", - "changedby2047", "changedbyname", "maintainer822", - "maintainer2047", "maintainername", "maintaineremail", - "fingerprint", "changes" ]: - print " %s: %s" % (i.capitalize(), changes[i]) - del changes[i] - # Mandatory changes lists - for i in [ "distribution", "architecture", "closes" ]: - print " %s: %s" % (i.capitalize(), " ".join(changes[i].keys())) - del changes[i] - # Optional changes fields - for i in [ "changed-by", "filecontents", "format", "adv id" ]: - if changes.has_key(i): - print " %s: %s" % (i.capitalize(), changes[i]) - del changes[i] - print - if changes: - utils.warn("changes still has following unrecognised keys: %s" % (changes.keys())) - - dsc = k.pkg.dsc - print " Dsc:" - for i in [ "source", "version", "maintainer", "fingerprint", "uploaders", - "bts changelog" ]: - if dsc.has_key(i): - print " %s: %s" % (i.capitalize(), dsc[i]) - del dsc[i] - print - if dsc: - utils.warn("dsc still has following unrecognised keys: %s" % (dsc.keys())) - - files = k.pkg.files - print " Files:" - for f in files.keys(): - print " %s:" % (f) - for i in [ "package", "version", "architecture", "type", "size", - "md5sum", "sha1sum", "sha256sum", "component", "location id", - "source package", "source version", "maintainer", "dbtype", - "files id", "new", "section", "priority", "pool name" ]: - if files[f].has_key(i): - print " %s: %s" % (i.capitalize(), files[f][i]) - del files[f][i] - if files[f]: - utils.warn("files[%s] still has following unrecognised keys: %s" % (f, files[f].keys())) - print - - dsc_files = k.pkg.dsc_files - print " Dsc Files:" - for f in dsc_files.keys(): - print " %s:" % (f) - # Mandatory fields - for i in [ "size", "md5sum" ]: - print " %s: %s" % (i.capitalize(), dsc_files[f][i]) - del dsc_files[f][i] - # Optional fields - for i in [ "files id" ]: - if dsc_files[f].has_key(i): - print " %s: %s" % (i.capitalize(), dsc_files[f][i]) - del dsc_files[f][i] - if dsc_files[f]: - utils.warn("dsc_files[%s] still has following unrecognised keys: %s" % (f, dsc_files[f].keys())) + k = Changes() + k.load_dot_dak(arg) + print arg + print k ################################################################################ diff --git a/daklib/changes.py b/daklib/changes.py index 150e7c53..5cd26e2a 100755 --- a/daklib/changes.py +++ b/daklib/changes.py @@ -287,4 +287,103 @@ class Changes(object): dump_file.close() + def unknown_files_fields(self, name): + return sorted(list( set(self.files[name].keys()) - + set(CHANGESFIELDS_FILES))) + + def unknown_changes_fields(self): + return sorted(list( set(self.changes.keys()) - + set(CHANGESFIELDS_MANDATORY + CHANGESFIELDS_OPTIONAL))) + + def unknown_dsc_fields(self): + return sorted(list( set(self.dsc.keys()) - + set(CHANGESFIELDS_DSC))) + + def unknown_dsc_files_fields(self, name): + return sorted(list( set(self.dsc_files[name].keys()) - + set(CHANGESFIELDS_DSCFILES_MANDATORY + CHANGESFIELDS_DSCFILES_OPTIONAL))) + + def str_files(self): + r = [] + for name, entry in self.files.items(): + r.append(" %s:" % (name)) + for i in CHANGESFIELDS_FILES: + if entry.has_key(i): + r.append(" %s: %s" % (i.capitalize(), entry[i])) + xfields = self.unknown_files_fields(name) + if len(xfields) > 0: + r.append("files[%s] still has following unrecognised keys: %s" % (name, ", ".join(xfields))) + + return r + + def str_changes(self): + r = [] + for i in CHANGESFIELDS_MANDATORY: + val = self.changes[i] + if isinstance(val, list): + val = " ".join(val) + elif isinstance(val, dict): + val = " ".join(val.keys()) + r.append(' %s: %s' % (i.capitalize(), val)) + + for i in CHANGESFIELDS_OPTIONAL: + if self.changes.has_key(i): + r.append(' %s: %s' % (i.capitalize(), self.changes[i])) + + xfields = self.unknown_changes_fields() + if len(xfields) > 0: + r.append("Warning: changes still has the following unrecognised fields: %s" % ", ".join(xfields)) + + return r + + def str_dsc(self): + r = [] + for i in CHANGESFIELDS_DSC: + if self.dsc.has_key(i): + r.append(' %s: %s' % (i.capitalize(), self.dsc[i])) + + xfields = self.unknown_dsc_fields() + if len(xfields) > 0: + r.append("Warning: dsc still has the following unrecognised fields: %s" % ", ".join(xfields)) + + return r + + def str_dsc_files(self): + r = [] + for name, entry in self.dsc_files.items(): + r.append(" %s:" % (name)) + for i in CHANGESFIELDS_DSCFILES_MANDATORY: + r.append(" %s: %s" % (i.capitalize(), entry[i])) + for i in CHANGESFIELDS_DSCFILES_OPTIONAL: + if entry.has_key(i): + r.append(" %s: %s" % (i.capitalize(), entry[i])) + xfields = self.unknown_dsc_files_fields(name) + if len(xfields) > 0: + r.append("dsc_files[%s] still has following unrecognised keys: %s" % (name, ", ".join(xfields))) + + return r + + def __str__(self): + r = [] + + r.append(" Changes:") + r += self.str_changes() + + r.append("") + + r.append(" Dsc:") + r += self.str_dsc() + + r.append("") + + r.append(" Files:") + r += self.str_files() + + r.append("") + + r.append(" Dsc Files:") + r += self.str_dsc_files() + + return "\n".join(r) + __all__.append('Changes')