From: Joerg Jaspert Date: Mon, 5 May 2008 14:02:55 +0000 (+0200) Subject: Merge from cleanup branch X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=05e649f2cfaa94ac361cb2df2e9a810adeb9c943;p=dak Merge from cleanup branch --- diff --git a/ChangeLog b/ChangeLog index eead3da3..869ff621 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,27 @@ +2008-05-05 Mark Hymers + + * daklib/dak_exceptions.py: Add a default message and tidy up our string + representation + +2008-05-05 Joerg Jaspert + + * daklib/dak_exceptions.py: New file, central place for all those + own exceptions dak may raise. + + * daklib/utils.py: Use dak_exceptions and delete all those string + exception raising stuff, which is depcreated. + During that delete the unknown_hostname_exc, as it wasnt used. + + * dak/import_archive.py: use the new Exception class + * dak/rm.py: dito + * dak/generate_releases.py: dito + * dak/queue_report.py: dito + * daklib/queue.py: dito + 2008-05-04 Joerg Jaspert + * daklib/queue.py: Various pychecker cleanups + * dak/import_keyring.py: Remove unused daklib.logging and Logger and add the actually used daklib/utils @@ -12,6 +34,10 @@ * dak/clean_suites.py: likewise * dak/compare_suites.py: likewise * dak/cruft_report.py: likewise + (get_suite_binaries): Seperated in own function, out of main. More + of main should be splitted. (Or well, cruft_report redesigned a + little, so its easier to run on multiple suites with differing tests) + * dak/examine_package.py: likewise * dak/find_null_maintainers.py: likewise * dak/generate_index_diffs.py: likewise diff --git a/dak/check_archive.py b/dak/check_archive.py index c00aa08b..7a2c779c 100755 --- a/dak/check_archive.py +++ b/dak/check_archive.py @@ -132,7 +132,7 @@ def check_dscs(): f = line[:-1] try: utils.parse_changes(f, signing_rules=1) - except utils.invalid_dsc_format_exc, line: + except InvalidDscError, line: utils.warn("syntax error in .dsc file '%s', line %s." % (f, line)) count += 1 diff --git a/dak/cruft_report.py b/dak/cruft_report.py index 238cdd49..cc5aa4b8 100755 --- a/dak/cruft_report.py +++ b/dak/cruft_report.py @@ -242,6 +242,20 @@ def do_obsolete_source(duplicate_bins, bin2source): print " dak rm -S -p -m \"[auto-cruft] obsolete source package\" %s" % (" ".join(to_remove)) print +def get_suite_binaries(): + # Initalize a large hash table of all binary packages + binaries = {} + before = time.time() + + sys.stderr.write("[Getting a list of binary packages in %s..." % (suite)) + q = projectB.query("SELECT distinct b.package FROM binaries b, bin_associations ba WHERE ba.suite = %s AND ba.bin = b.id" % (suite_id)) + ql = q.getresult() + sys.stderr.write("done. (%d seconds)]\n" % (int(time.time()-before))) + for i in ql: + binaries[i[0]] = "" + + return binaries + ################################################################################ def main (): @@ -294,14 +308,7 @@ def main (): bin_not_built = {} if "bnb" in checks: - # Initalize a large hash table of all binary packages - before = time.time() - sys.stderr.write("[Getting a list of binary packages in %s..." % (suite)) - q = projectB.query("SELECT distinct b.package FROM binaries b, bin_associations ba WHERE ba.suite = %s AND ba.bin = b.id" % (suite_id)) - ql = q.getresult() - sys.stderr.write("done. (%d seconds)]\n" % (int(time.time()-before))) - for i in ql: - bins_in_suite[i[0]] = "" + bins_in_suite = get_suite_binaries() # Checks based on the Sources files components = Cnf.ValueList("Suite::%s::Components" % (suite)) diff --git a/dak/generate_releases.py b/dak/generate_releases.py index cb82a947..afd4a02b 100755 --- a/dak/generate_releases.py +++ b/dak/generate_releases.py @@ -25,6 +25,7 @@ import sys, os, popen2, tempfile, stat, time, pg import apt_pkg import daklib.utils as utils +from daklib.dak_exceptions import * ################################################################################ @@ -107,7 +108,7 @@ def print_md5sha_files (tree, files, hashop): else: size = os.stat(path + name)[stat.ST_SIZE] file_handle = utils.open_file(path + name) - except utils.cant_open_exc: + except CantOpenError: print "ALERT: Couldn't open " + path + name else: hash = hashop(file_handle) diff --git a/dak/import_archive.py b/dak/import_archive.py index b8884ab2..b1e11fce 100755 --- a/dak/import_archive.py +++ b/dak/import_archive.py @@ -40,6 +40,7 @@ import commands, os, pg, re, sys, time import apt_pkg import daklib.database as database import daklib.utils as utils +from daklib.dak_exceptions import * ############################################################################### @@ -323,7 +324,7 @@ def process_sources (filename, suite, component, archive): suite_id = database.get_suite_id(suite) try: file = utils.open_file (filename) - except utils.cant_open_exc: + except CantOpenError: utils.warn("can't open '%s'" % (filename)) return Scanner = apt_pkg.ParseTagFile(file) @@ -406,7 +407,7 @@ def process_packages (filename, suite, component, archive): suite_id = database.get_suite_id(suite) try: file = utils.open_file (filename) - except utils.cant_open_exc: + except CantOpenError: utils.warn("can't open '%s'" % (filename)) return Scanner = apt_pkg.ParseTagFile(file) diff --git a/dak/process_unchecked.py b/dak/process_unchecked.py index fbd7d74d..11b480a0 100755 --- a/dak/process_unchecked.py +++ b/dak/process_unchecked.py @@ -34,6 +34,7 @@ import daklib.database as database import daklib.logging as logging import daklib.queue as queue import daklib.utils as utils +from daklib.dak_exceptions import * from types import * @@ -181,19 +182,19 @@ def check_changes(): # Parse the .changes field into a dictionary try: changes.update(utils.parse_changes(filename)) - except utils.cant_open_exc: + except CantOpenError: reject("%s: can't read file." % (filename)) return 0 - except utils.changes_parse_error_exc, line: + except ParseChangesError, line: reject("%s: parse error, can't grok: %s." % (filename, line)) return 0 # Parse the Files field from the .changes into another dictionary try: files.update(utils.build_file_list(changes)) - except utils.changes_parse_error_exc, line: + except ParseChangesError, line: reject("%s: parse error, can't grok: %s." % (filename, line)) - except utils.nk_format_exc, format: + except UnknownFormatError, format: reject("%s: unknown format '%s'." % (filename, format)) return 0 @@ -226,7 +227,7 @@ def check_changes(): (changes["maintainer822"], changes["maintainer2047"], changes["maintainername"], changes["maintaineremail"]) = \ utils.fix_maintainer (changes["maintainer"]) - except utils.ParseMaintError, msg: + except ParseMaintError, msg: reject("%s: Maintainer field ('%s') failed to parse: %s" \ % (filename, changes["maintainer"], msg)) @@ -235,7 +236,7 @@ def check_changes(): (changes["changedby822"], changes["changedby2047"], changes["changedbyname"], changes["changedbyemail"]) = \ utils.fix_maintainer (changes.get("changed-by", "")) - except utils.ParseMaintError, msg: + except ParseMaintError, msg: (changes["changedby822"], changes["changedby2047"], changes["changedbyname"], changes["changedbyemail"]) = \ ("", "", "", "") @@ -685,21 +686,21 @@ def check_dsc(): # Parse the .dsc file try: dsc.update(utils.parse_changes(dsc_filename, signing_rules=1)) - except utils.cant_open_exc: + except CantOpenError: # if not -n copy_to_holding() will have done this for us... if Options["No-Action"]: reject("%s: can't read file." % (dsc_filename)) - except utils.changes_parse_error_exc, line: + except ParseChangesError, line: reject("%s: parse error, can't grok: %s." % (dsc_filename, line)) - except utils.invalid_dsc_format_exc, line: + except InvalidDscError, line: reject("%s: syntax error on line %s." % (dsc_filename, line)) # Build up the file list of files mentioned by the .dsc try: dsc_files.update(utils.build_file_list(dsc, is_a_dsc=1)) - except utils.no_files_exc: + except NoFilesFieldError: reject("%s: no Files: field." % (dsc_filename)) return 0 - except utils.changes_parse_error_exc, line: + except ParseChangesError, line: reject("%s: parse error, can't grok: %s." % (dsc_filename, line)) return 0 @@ -723,7 +724,7 @@ def check_dsc(): # Validate the Maintainer field try: utils.fix_maintainer (dsc["maintainer"]) - except utils.ParseMaintError, msg: + except ParseMaintError, msg: reject("%s: Maintainer field ('%s') failed to parse: %s" \ % (dsc_filename, dsc["maintainer"], msg)) @@ -945,9 +946,9 @@ def check_hashes (): try: fs = utils.build_file_list(changes, 0, "checksums-%s" % h, h) check_hash(".changes %s" % (h), fs, h, f, files) - except utils.no_files_exc: + except NoFilesFieldError: reject("No Checksums-%s: field in .changes" % (h)) - except utils.changes_parse_error_exc, line: + except ParseChangesError, line: reject("parse error for Checksums-%s in .changes, can't grok: %s." % (h, line)) if "source" not in changes["architecture"]: continue @@ -955,9 +956,9 @@ def check_hashes (): try: fs = utils.build_file_list(dsc, 1, "checksums-%s" % h, h) check_hash(".dsc %s" % (h), fs, h, f, dsc_files) - except utils.no_files_exc: + except NoFilesFieldError: reject("No Checksums-%s: field in .dsc" % (h)) - except utils.changes_parse_error_exc, line: + except ParseChangesError, line: reject("parse error for Checksums-%s in .dsc, can't grok: %s." % (h, line)) ################################################################################ @@ -974,7 +975,7 @@ def check_hash (where, lfiles, key, testfn, basedict = None): try: file_handle = utils.open_file(f) - except utils.cant_open_exc: + except CantOpenError: continue # Check hash diff --git a/dak/queue_report.py b/dak/queue_report.py old mode 100644 new mode 100755 index f1e5287f..7f20ce58 --- a/dak/queue_report.py +++ b/dak/queue_report.py @@ -38,6 +38,7 @@ import copy, glob, os, stat, sys, time import apt_pkg import daklib.queue as queue import daklib.utils as utils +from daklib.dak_exceptions import * Cnf = None Upload = None @@ -322,7 +323,7 @@ def process_changes_files(changes_files, type): (maintainer["maintainer822"], maintainer["maintainer2047"], maintainer["maintainername"], maintainer["maintaineremail"]) = \ utils.fix_maintainer (j["maintainer"]) - except utils.ParseMaintError, msg: + except ParseMaintError, msg: print "Problems while parsing maintainer address\n" maintainer["maintainername"] = "Unknown" maintainer["maintaineremail"] = "Unknown" diff --git a/dak/rm.py b/dak/rm.py index d5663e34..df11a53b 100755 --- a/dak/rm.py +++ b/dak/rm.py @@ -43,6 +43,7 @@ import commands, os, pg, re, sys import apt_pkg, apt_inst import daklib.database as database import daklib.utils as utils +from daklib.dak_exceptions import * ################################################################################ @@ -364,7 +365,7 @@ def main (): filename = "/".join(source_packages[i]) try: dsc = utils.parse_changes(filename) - except utils.cant_open_exc: + except CantOpenError: utils.warn("couldn't open '%s'." % (filename)) continue for package in dsc.get("binary").split(','): diff --git a/daklib/dak_exceptions.py b/daklib/dak_exceptions.py new file mode 100644 index 00000000..e488ac9d --- /dev/null +++ b/daklib/dak_exceptions.py @@ -0,0 +1,66 @@ +# Exception classes used in dak + +# Copyright (C) 2008 Mark Hymers + +################################################################################ + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +################################################################################ + +class DakError(Exception): + """Base class for all simple errors in this module. + + Attributes: + + message -- explanation of the error + """ + + def __init__(self, message=""): + self.args = str(message) + self.message = str(message) + + def __str__(self): + return self.message + +__all__ = ['DakError'] + +dakerrors = { + "ParseMaintError": """Exception raised for errors in parsing a maintainer field.""", + "ParseChangesError": """Exception raised for errors in parsing a changes file.""", + "InvalidDscError": """Exception raised for invalid dsc files.""", + "UnknownFormatError": """Exception raised for unknown Format: lines in changes files.""", + "NoFilesFieldError": """Exception raised for missing files field in dsc/changes.""", + "CantOpenError": """Exception raised when files can't be opened.""", + "CantOverwriteError": """Exception raised when files cant be overwritten.""", + "FileExistsError": """Exception raised when destination file exists.""", + "SendmailFailedError": """Exception raised when Sendmail invocation failed.""", + "NoFreeFilenameError": """Exception raised when no alternate filename was found.""" +} + + +def construct_dak_exception(name, description): + class Er(DakError): + __doc__ = description + setattr(Er, "__name__", name) + return Er + +for e in dakerrors.keys(): + globals()[e] = construct_dak_exception(e, dakerrors[e]) + __all__ += [e] + + + +################################################################################ diff --git a/daklib/queue.py b/daklib/queue.py old mode 100644 new mode 100755 index 9f8223a6..f35ee18c --- a/daklib/queue.py +++ b/daklib/queue.py @@ -22,6 +22,7 @@ import cPickle, errno, os, pg, re, stat, sys, time import apt_inst, apt_pkg import utils, database +from dak_exceptions import * from types import * @@ -40,36 +41,36 @@ def determine_new(changes, files, projectB, warn=1): new = {} # Build up a list of potentially new things - for file in files.keys(): - f = files[file] + for file_entry in files.keys(): + f = files[file_entry] # Skip byhand elements if f["type"] == "byhand": continue pkg = f["package"] priority = f["priority"] section = f["section"] - type = get_type(f) + file_type = get_type(f) component = f["component"] - if type == "dsc": + if file_type == "dsc": priority = "source" if not new.has_key(pkg): new[pkg] = {} new[pkg]["priority"] = priority new[pkg]["section"] = section - new[pkg]["type"] = type + new[pkg]["type"] = file_type new[pkg]["component"] = component new[pkg]["files"] = [] else: old_type = new[pkg]["type"] - if old_type != type: + if old_type != file_type: # source gets trumped by deb or udeb if old_type == "dsc": new[pkg]["priority"] = priority new[pkg]["section"] = section - new[pkg]["type"] = type + new[pkg]["type"] = file_type new[pkg]["component"] = component - new[pkg]["files"].append(file) + new[pkg]["files"].append(file_entry) if f.has_key("othercomponents"): new[pkg]["othercomponents"] = f["othercomponents"] @@ -81,9 +82,9 @@ def determine_new(changes, files, projectB, warn=1): q = projectB.query("SELECT package FROM override WHERE package = '%s' AND suite = %s AND component = %s AND type = %s" % (pkg, suite_id, component_id, type_id)) ql = q.getresult() if ql: - for file in new[pkg]["files"]: - if files[file].has_key("new"): - del files[file]["new"] + for file_entry in new[pkg]["files"]: + if files[file_entry].has_key("new"): + del files[file_entry]["new"] del new[pkg] if warn: @@ -102,18 +103,18 @@ def determine_new(changes, files, projectB, warn=1): def get_type(f): # Determine the type if f.has_key("dbtype"): - type = f["dbtype"] + file_type = f["dbtype"] elif f["type"] in [ "orig.tar.gz", "orig.tar.bz2", "tar.gz", "tar.bz2", "diff.gz", "diff.bz2", "dsc" ]: - type = "dsc" + file_type = "dsc" else: - utils.fubar("invalid type (%s) for new. Dazed, confused and sure as heck not continuing." % (type)) + utils.fubar("invalid type (%s) for new. Dazed, confused and sure as heck not continuing." % (file_type)) # Validate the override type - type_id = database.get_override_type_id(type) + type_id = database.get_override_type_id(file_type) if type_id == -1: - utils.fubar("invalid type (%s) for new. Say wha?" % (type)) + utils.fubar("invalid type (%s) for new. Say wha?" % (file_type)) - return type + return file_type ################################################################################ @@ -123,15 +124,15 @@ def check_valid(new): for pkg in new.keys(): section = new[pkg]["section"] priority = new[pkg]["priority"] - type = new[pkg]["type"] + file_type = new[pkg]["type"] new[pkg]["section id"] = database.get_section_id(section) new[pkg]["priority id"] = database.get_priority_id(new[pkg]["priority"]) # Sanity checks di = section.find("debian-installer") != -1 - if (di and type != "udeb") or (not di and type == "udeb"): + if (di and file_type != "udeb") or (not di and file_type == "udeb"): new[pkg]["section id"] = -1 - if (priority == "source" and type != "dsc") or \ - (priority != "source" and type == "dsc"): + if (priority == "source" and file_type != "dsc") or \ + (priority != "source" and file_type == "dsc"): new[pkg]["priority id"] = -1 @@ -214,15 +215,15 @@ class Upload: for i in [ "d_changes", "d_dsc", "d_files", "d_dsc_files" ]: exec "%s = {}" % i ## files - for file in files.keys(): - d_files[file] = {} + for file_entry in files.keys(): + d_files[file_entry] = {} for i in [ "package", "version", "architecture", "type", "size", "md5sum", "component", "location id", "source package", "source version", "maintainer", "dbtype", "files id", "new", "section", "priority", "othercomponents", "pool name", "original component" ]: - if files[file].has_key(i): - d_files[file][i] = files[file][i] + if files[file_entry].has_key(i): + d_files[file_entry][i] = files[file_entry][i] ## changes # Mandatory changes fields for i in [ "distribution", "source", "architecture", "version", @@ -242,15 +243,15 @@ class Upload: if dsc.has_key(i): d_dsc[i] = dsc[i] ## dsc_files - for file in dsc_files.keys(): - d_dsc_files[file] = {} + for file_entry in dsc_files.keys(): + d_dsc_files[file_entry] = {} # Mandatory dsc_files fields for i in [ "size", "md5sum" ]: - d_dsc_files[file][i] = dsc_files[file][i] + d_dsc_files[file_entry][i] = dsc_files[file_entry][i] # Optional dsc_files fields for i in [ "files id" ]: - if dsc_files[file].has_key(i): - d_dsc_files[file][i] = dsc_files[file][i] + if dsc_files[file_entry].has_key(i): + d_dsc_files[file_entry][i] = dsc_files[file_entry][i] for i in [ d_changes, d_dsc, d_files, d_dsc_files, legacy_source_untouchable, orig_tar_id, orig_tar_location ]: @@ -317,31 +318,31 @@ class Upload: override_summary =""; file_keys = files.keys() file_keys.sort() - for file in file_keys: - if files[file].has_key("byhand"): + for file_entry in file_keys: + if files[file_entry].has_key("byhand"): byhand = 1 - summary += file + " byhand\n" - elif files[file].has_key("new"): + summary += file_entry + " byhand\n" + elif files[file_entry].has_key("new"): new = 1 - summary += "(new) %s %s %s\n" % (file, files[file]["priority"], files[file]["section"]) - if files[file].has_key("othercomponents"): - summary += "WARNING: Already present in %s distribution.\n" % (files[file]["othercomponents"]) - if files[file]["type"] == "deb": - deb_fh = utils.open_file(file) + summary += "(new) %s %s %s\n" % (file_entry, files[file_entry]["priority"], files[file_entry]["section"]) + if files[file_entry].has_key("othercomponents"): + summary += "WARNING: Already present in %s distribution.\n" % (files[file_entry]["othercomponents"]) + if files[file_entry]["type"] == "deb": + deb_fh = utils.open_file(file_entry) summary += apt_pkg.ParseSection(apt_inst.debExtractControl(deb_fh))["Description"] + '\n' deb_fh.close() else: - files[file]["pool name"] = utils.poolify (changes.get("source",""), files[file]["component"]) - destination = self.Cnf["Dir::PoolRoot"] + files[file]["pool name"] + file - summary += file + "\n to " + destination + "\n" - if not files[file].has_key("type"): - files[file]["type"] = "unknown" - if files[file]["type"] in ["deb", "udeb", "dsc"]: + files[file_entry]["pool name"] = utils.poolify (changes.get("source",""), files[file_entry]["component"]) + destination = self.Cnf["Dir::PoolRoot"] + files[file_entry]["pool name"] + file_entry + summary += file_entry + "\n to " + destination + "\n" + if not files[file_entry].has_key("type"): + files[file_entry]["type"] = "unknown" + if files[file_entry]["type"] in ["deb", "udeb", "dsc"]: # (queue/unchecked), there we have override entries already, use them # (process-new), there we dont have override entries, use the newly generated ones. - override_prio = files[file].get("override priority", files[file]["priority"]) - override_sect = files[file].get("override section", files[file]["section"]) - override_summary += "%s - %s %s\n" % (file, override_prio, override_sect) + override_prio = files[file_entry].get("override priority", files[file_entry]["priority"]) + override_sect = files[file_entry].get("override section", files[file_entry]["section"]) + override_summary += "%s - %s %s\n" % (file_entry, override_prio, override_sect) short_summary = summary @@ -408,14 +409,14 @@ distribution.""" Subst["__SHORT_SUMMARY__"] = short_summary for dist in changes["distribution"].keys(): - list = Cnf.Find("Suite::%s::Announce" % (dist)) - if list == "" or lists_done.has_key(list): + announce_list = Cnf.Find("Suite::%s::Announce" % (dist)) + if announce_list == "" or lists_done.has_key(announce_list): continue - lists_done[list] = 1 - summary += "Announcing to %s\n" % (list) + lists_done[announce_list] = 1 + summary += "Announcing to %s\n" % (announce_list) if action: - Subst["__ANNOUNCE_LIST_ADDRESS__"] = list + Subst["__ANNOUNCE_LIST_ADDRESS__"] = announce_list if Cnf.get("Dinstall::TrackingServer") and changes["architecture"].has_key("source"): Subst["__ANNOUNCE_LIST_ADDRESS__"] = Subst["__ANNOUNCE_LIST_ADDRESS__"] + "\nBcc: %s@%s" % (changes["source"], Cnf["Dinstall::TrackingServer"]) mail_message = utils.TemplateSubst(Subst,Cnf["Dir::Templates"]+"/process-unchecked.announce") @@ -444,9 +445,9 @@ distribution.""" # Move all the files into the accepted directory utils.move(changes_file, Cnf["Dir::Queue::Accepted"]) file_keys = files.keys() - for file in file_keys: - utils.move(file, Cnf["Dir::Queue::Accepted"]) - self.accept_bytes += float(files[file]["size"]) + for file_entry in file_keys: + utils.move(file_entry, Cnf["Dir::Queue::Accepted"]) + self.accept_bytes += float(files[file_entry]["size"]) self.accept_count += 1 # Send accept mail, announce to lists, close bugs and check for @@ -482,8 +483,8 @@ distribution.""" temp_filename = utils.temp_filename(Cnf["Dir::Queue::BTSVersionTrack"], dotprefix=1, perms=0644) debinfo = utils.open_file(temp_filename, 'w') - for file in file_keys: - f = files[file] + for file_entry in file_keys: + f = files[file_entry] if f["type"] == "deb": line = " ".join([f["package"], f["version"], f["architecture"], f["source package"], @@ -518,9 +519,9 @@ distribution.""" dest_dir = Cnf["Dir::QueueBuild"] if Cnf.FindB("Dinstall::SecurityQueueBuild"): dest_dir = os.path.join(dest_dir, suite) - for file in file_keys: - src = os.path.join(path, file) - dest = os.path.join(dest_dir, file) + for file_entry in file_keys: + src = os.path.join(path, file_entry) + dest = os.path.join(dest_dir, file_entry) if Cnf.FindB("Dinstall::SecurityQueueBuild"): # Copy it since the original won't be readable by www-data utils.copy(src, dest) @@ -574,16 +575,16 @@ distribution.""" summary = "" file_keys = files.keys() file_keys.sort() - for file in file_keys: - if not files[file].has_key("new") and files[file]["type"] == "deb": - section = files[file]["section"] - override_section = files[file]["override section"] + for file_entry in file_keys: + if not files[file_entry].has_key("new") and files[file_entry]["type"] == "deb": + section = files[file_entry]["section"] + override_section = files[file_entry]["override section"] if section.lower() != override_section.lower() and section != "-": - summary += "%s: package says section is %s, override says %s.\n" % (file, section, override_section) - priority = files[file]["priority"] - override_priority = files[file]["override priority"] + summary += "%s: package says section is %s, override says %s.\n" % (file_entry, section, override_section) + priority = files[file_entry]["priority"] + override_priority = files[file_entry]["override priority"] if priority != override_priority and priority != "-": - summary += "%s: package says priority is %s, override says %s.\n" % (file, priority, override_priority) + summary += "%s: package says priority is %s, override says %s.\n" % (file_entry, priority, override_priority) if summary == "": return @@ -602,36 +603,36 @@ distribution.""" Cnf = self.Cnf - for file in files: + for file_entry in files: # Skip any files which don't exist or which we don't have permission to copy. - if os.access(file,os.R_OK) == 0: + if os.access(file_entry,os.R_OK) == 0: continue - dest_file = os.path.join(Cnf["Dir::Queue::Reject"], file) + dest_file = os.path.join(Cnf["Dir::Queue::Reject"], file_entry) try: dest_fd = os.open(dest_file, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0644) except OSError, e: # File exists? Let's try and move it to the morgue if errno.errorcode[e.errno] == 'EEXIST': - morgue_file = os.path.join(Cnf["Dir::Morgue"],Cnf["Dir::MorgueReject"],file) + morgue_file = os.path.join(Cnf["Dir::Morgue"],Cnf["Dir::MorgueReject"],file_entry) try: morgue_file = utils.find_next_free(morgue_file) - except utils.tried_too_hard_exc: + except NoFreeFilenameError: # Something's either gone badly Pete Tong, or # someone is trying to exploit us. - utils.warn("**WARNING** failed to move %s from the reject directory to the morgue." % (file)) + utils.warn("**WARNING** failed to move %s from the reject directory to the morgue." % (file_entry)) return utils.move(dest_file, morgue_file, perms=0660) try: dest_fd = os.open(dest_file, os.O_RDWR|os.O_CREAT|os.O_EXCL, 0644) except OSError, e: # Likewise - utils.warn("**WARNING** failed to claim %s in the reject directory." % (file)) + utils.warn("**WARNING** failed to claim %s in the reject directory." % (file_entry)) return else: raise # If we got here, we own the destination file, so we can # safely overwrite it. - utils.move(file, dest_file, 1, perms=0660) + utils.move(file_entry, dest_file, 1, perms=0660) os.close(dest_fd) ########################################################################### @@ -763,9 +764,9 @@ distribution.""" files = self.pkg.files if binary_type == "": # must be source - type = "dsc" + file_type = "dsc" else: - type = binary_type + file_type = binary_type # Override suite name; used for example with proposed-updates if self.Cnf.Find("Suite::%s::OverrideSuite" % (suite)) != "": @@ -776,13 +777,13 @@ distribution.""" if suite_id == -1: return None component_id = database.get_component_id(component) - type_id = database.get_override_type_id(type) + type_id = database.get_override_type_id(file_type) q = self.projectB.query("SELECT s.section, p.priority FROM override o, section s, priority p WHERE package = '%s' AND suite = %s AND component = %s AND type = %s AND o.section = s.id AND o.priority = p.id" % (package, suite_id, component_id, type_id)) result = q.getresult() # If checking for a source package fall back on the binary override type - if type == "dsc" and not result: + if file_type == "dsc" and not result: deb_type_id = database.get_override_type_id("deb") udeb_type_id = database.get_override_type_id("udeb") q = self.projectB.query("SELECT s.section, p.priority FROM override o, section s, priority p WHERE package = '%s' AND suite = %s AND component = %s AND (type = %s OR type = %s) AND o.section = s.id AND o.priority = p.id" @@ -1038,8 +1039,8 @@ SELECT s.version, su.suite_name FROM source s, src_associations sa, suite su if os.path.exists(in_unchecked) and False: return (self.reject_message, in_unchecked) else: - for dir in [ "Accepted", "New", "Byhand", "ProposedUpdates", "OldProposedUpdates" ]: - in_otherdir = os.path.join(self.Cnf["Dir::Queue::%s" % (dir)],dsc_file) + for directory in [ "Accepted", "New", "Byhand", "ProposedUpdates", "OldProposedUpdates" ]: + in_otherdir = os.path.join(self.Cnf["Dir::Queue::%s" % (directory)],dsc_file) if os.path.exists(in_otherdir): in_otherdir_fh = utils.open_file(in_otherdir) actual_md5 = apt_pkg.md5sum(in_otherdir_fh) diff --git a/daklib/utils.py b/daklib/utils.py old mode 100644 new mode 100755 index a094788f..ec82782f --- a/daklib/utils.py +++ b/daklib/utils.py @@ -25,6 +25,7 @@ import codecs, commands, email.Header, os, pwd, re, select, socket, shutil, \ sys, tempfile, traceback import apt_pkg import database +from dak_exceptions import * ################################################################################ @@ -48,17 +49,6 @@ re_verwithext = re.compile(r"^(\d+)(?:\.(\d+))(?:\s+\((\S+)\))?$") re_srchasver = re.compile(r"^(\S+)\s+\((\S+)\)$") -changes_parse_error_exc = "Can't parse line in .changes file" -invalid_dsc_format_exc = "Invalid .dsc file" -nk_format_exc = "Unknown Format: in .changes file" -no_files_exc = "No Files: field in .dsc or .changes file." -cant_open_exc = "Can't open file" -unknown_hostname_exc = "Unknown hostname" -cant_overwrite_exc = "Permission denied; can't overwrite existent file." -file_exists_exc = "Destination file exists" -sendmail_failed_exc = "Sendmail invocation failed" -tried_too_hard_exc = "Tried too hard to find a free filename." - default_config = "/etc/dak/dak.conf" default_apt_config = "/etc/dak/apt.conf" @@ -67,28 +57,11 @@ key_uid_email_cache = {} ################################################################################ -class Error(Exception): - """Base class for exceptions in this module.""" - pass - -class ParseMaintError(Error): - """Exception raised for errors in parsing a maintainer field. - - Attributes: - message -- explanation of the error - """ - - def __init__(self, message): - self.args = message, - self.message = message - -################################################################################ - def open_file(filename, mode='r'): try: f = open(filename, mode) except IOError: - raise cant_open_exc, filename + raise CantOpenError, filename return f ################################################################################ @@ -151,7 +124,7 @@ The rules for (signing_rules == 1)-mode are: lines = changes_in.readlines() if not lines: - raise changes_parse_error_exc, "[Empty changes file]" + raise ParseChangesError, "[Empty changes file]" # Reindex by line number so we can easily verify the format of # .dsc files... @@ -173,10 +146,10 @@ The rules for (signing_rules == 1)-mode are: if signing_rules == 1: index += 1 if index > num_of_lines: - raise invalid_dsc_format_exc, index + raise InvalidDscError, index line = indexed_lines[index] if not line.startswith("-----BEGIN PGP SIGNATURE"): - raise invalid_dsc_format_exc, index + raise InvalidDscError, index inside_signature = 0 break else: @@ -205,7 +178,7 @@ The rules for (signing_rules == 1)-mode are: mlf = re_multi_line_field.match(line) if mlf: if first == -1: - raise changes_parse_error_exc, "'%s'\n [Multi-line field continuing on from nothing?]" % (line) + raise ParseChangesError, "'%s'\n [Multi-line field continuing on from nothing?]" % (line) if first == 1 and changes[field] != "": changes[field] += '\n' first = 0 @@ -214,7 +187,7 @@ The rules for (signing_rules == 1)-mode are: error += line if signing_rules == 1 and inside_signature: - raise invalid_dsc_format_exc, index + raise InvalidDscError, index changes_in.close() changes["filecontents"] = "".join(lines) @@ -228,7 +201,7 @@ The rules for (signing_rules == 1)-mode are: changes["source-version"] = srcver.group(2) if error: - raise changes_parse_error_exc, error + raise ParseChangesError, error return changes @@ -241,12 +214,12 @@ def build_file_list(changes, is_a_dsc=0, field="files", hashname="md5sum"): # Make sure we have a Files: field to parse... if not changes.has_key(field): - raise no_files_exc + raise NoFilesFieldError # Make sure we recognise the format of the Files: field format = re_verwithext.search(changes.get("format", "0.0")) if not format: - raise nk_format_exc, "%s" % (changes.get("format","0.0")) + raise UnknownFormatError, "%s" % (changes.get("format","0.0")) format = format.groups() if format[1] == None: @@ -258,12 +231,12 @@ def build_file_list(changes, is_a_dsc=0, field="files", hashname="md5sum"): if is_a_dsc: if format != (1,0): - raise nk_format_exc, "%s" % (changes.get("format","0.0")) + raise UnknownFormatError, "%s" % (changes.get("format","0.0")) else: if (format < (1,5) or format > (1,8)): - raise nk_format_exc, "%s" % (changes.get("format","0.0")) + raise UnknownFormatError, "%s" % (changes.get("format","0.0")) if field != "files" and format < (1,8): - raise nk_format_exc, "%s" % (changes.get("format","0.0")) + raise UnknownFormatError, "%s" % (changes.get("format","0.0")) includes_section = (not is_a_dsc) and field == "files" @@ -279,7 +252,7 @@ def build_file_list(changes, is_a_dsc=0, field="files", hashname="md5sum"): else: (md5, size, name) = s except ValueError: - raise changes_parse_error_exc, i + raise ParseChangesError, i if section == "": section = "-" @@ -387,7 +360,7 @@ def send_mail (message, filename=""): # Invoke sendmail (result, output) = commands.getstatusoutput("%s < %s" % (Cnf["Dinstall::SendmailCommand"], filename)) if (result != 0): - raise sendmail_failed_exc, output + raise SendmailFailedError, output # Clean up any temporary files if message: @@ -443,10 +416,10 @@ def copy (src, dest, overwrite = 0, perms = 0664): # Don't overwrite unless forced to if os.path.exists(dest): if not overwrite: - raise file_exists_exc + raise FileExistsError else: if not os.access(dest, os.W_OK): - raise cant_overwrite_exc + raise CantOverwriteError shutil.copy2(src, dest) os.chmod(dest, perms) @@ -590,7 +563,7 @@ def find_next_free (dest, too_many=100): dest = orig_dest + '.' + repr(extra) extra += 1 if extra >= too_many: - raise tried_too_hard_exc + raise NoFreeFilenameError return dest ################################################################################