[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

ftpmaster-dak r1083: Merge from cleanup branch



------------------------------------------------------------
revno: 1083
committer: Joerg Jaspert <joerg@debian.org>
branch nick: upstream
timestamp: Mon 2008-05-05 16:02:55 +0200
message:
  Merge from cleanup branch
added:
  daklib/dak_exceptions.py
modified:
  ChangeLog
  dak/check_archive.py
  dak/cruft_report.py
  dak/generate_releases.py
  dak/import_archive.py
  dak/process_unchecked.py
  dak/queue_report.py*
  dak/rm.py
  daklib/queue.py*
  daklib/utils.py*
    ------------------------------------------------------------
    revno: 1082.1.1
    committer: Joerg Jaspert <joerg@debian.org>
    branch nick: cleanup
    timestamp: Sun 2008-05-04 23:54:54 +0200
    message:
      Split a little function of of main()
    modified:
      ChangeLog
      dak/cruft_report.py
      dak/process_unchecked.py*
    ------------------------------------------------------------
    revno: 1082.1.2
    committer: Joerg Jaspert <joerg@debian.org>
    branch nick: cleanup
    timestamp: Mon 2008-05-05 00:10:29 +0200
    message:
      Various pychecker cleanups
    modified:
      ChangeLog
      daklib/queue.py
    ------------------------------------------------------------
    revno: 1082.1.3
    committer: Joerg Jaspert <joerg@debian.org>
    branch nick: cleanup
    timestamp: Mon 2008-05-05 14:08:51 +0200
    message:
      Add an exception class and adjust the scripts using ParseMaintError to use the new class
    added:
      daklib/dak_exceptions.py
    modified:
      ChangeLog
      dak/process_unchecked.py*
      dak/queue_report.py*
      daklib/utils.py*
    ------------------------------------------------------------
    revno: 1082.1.4
    committer: Joerg Jaspert <joerg@debian.org>
    branch nick: cleanup
    timestamp: Mon 2008-05-05 14:44:31 +0200
    message:
      Exception handling
    modified:
      ChangeLog
      dak/check_archive.py
      dak/generate_releases.py
      dak/import_archive.py
      dak/process_unchecked.py
      dak/rm.py
      daklib/queue.py*
      daklib/utils.py
    ------------------------------------------------------------
    revno: 1082.1.5
    committer: Joerg Jaspert <joerg@debian.org>
    branch nick: cleanup
    timestamp: Mon 2008-05-05 14:47:34 +0200
    message:
      Using the real name of the stuff to import might help
    modified:
      dak/generate_releases.py
      dak/import_archive.py
      dak/rm.py
    ------------------------------------------------------------
    revno: 1082.1.6
    committer: Joerg Jaspert <joerg@debian.org>
    branch nick: cleanup
    timestamp: Mon 2008-05-05 16:01:38 +0200
    message:
      Merge from mhy
    modified:
      ChangeLog
      daklib/dak_exceptions.py
        ------------------------------------------------------------
        revno: 1082.2.1
        committer: Mark Hymers <mhy@debian.org>
        branch nick: cleanup-exceptions
        timestamp: Mon 2008-05-05 14:54:03 +0100
        message:
            * daklib/dak_exceptions.py: Add a default message and tidy up our string
            representation
        modified:
          ChangeLog
          daklib/dak_exceptions.py
    ------------------------------------------------------------
    revno: 1076.2.1
    committer: Joerg Jaspert <joerg@debian.org>
    branch nick: mainline
    timestamp: Sun 2008-05-04 10:49:52 +0200
    message:
      Merge from Thomas
    modified:
      ChangeLog
      dak/process_unchecked.py
    ------------------------------------------------------------
    revno: 1076.2.2
    committer: Joerg Jaspert <joerg@debian.org>
    branch nick: security
    timestamp: Sun 2008-05-04 11:15:49 +0200
    message:
      Merge with mainline
    modified:
      ChangeLog
      config/debian/cron.dinstall
      dak/check_archive.py*
      dak/check_overrides.py
      dak/check_proposed_updates.py*
      dak/clean_proposed_updates.py*
      dak/clean_queues.py*
      dak/clean_suites.py*
      dak/compare_suites.py*
      dak/control_overrides.py
      dak/control_suite.py
      dak/cruft_report.py*
      dak/dak.py*
      dak/decode_dot_dak.py
      dak/examine_package.py*
      dak/find_null_maintainers.py*
      dak/generate_index_diffs.py*
      dak/generate_releases.py*
      dak/import_archive.py*
      dak/import_keyring.py*
      dak/import_ldap_fingerprints.py*
      dak/import_users_from_passwd.py*
      dak/init_db.py*
      dak/init_dirs.py*
      dak/ls.py*
      dak/make_maintainers.py*
      dak/make_overrides.py*
      dak/make_suite_file_list.py*
      dak/new_security_install.py*
      dak/override.py*
      dak/process_accepted.py*
      dak/process_new.py*
      dak/process_unchecked.py*
      dak/queue_report.py
      dak/reject_proposed_updates.py
      dak/rm.py*
      dak/security_install.py
      dak/show_new.py*
      dak/split_done.py*
      dak/stats.py*
      dak/symlink_dists.py
      dak/transitions.py*
=== modified file 'ChangeLog'
--- a/ChangeLog	2008-05-04 09:13:30 +0000
+++ b/ChangeLog	2008-05-05 13:54:03 +0000
@@ -1,5 +1,27 @@
+2008-05-05  Mark Hymers  <mhy@debian.org>
+
+	* daklib/dak_exceptions.py: Add a default message and tidy up our string
+	representation
+
+2008-05-05  Joerg Jaspert  <joerg@debian.org>
+
+	* 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  <joerg@debian.org>
 
+	* 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

=== modified file 'dak/check_archive.py'
--- a/dak/check_archive.py	2008-05-03 23:18:23 +0000
+++ b/dak/check_archive.py	2008-05-05 12:44:31 +0000
@@ -132,7 +132,7 @@
             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
 

=== modified file 'dak/cruft_report.py'
--- a/dak/cruft_report.py	2008-05-03 23:44:24 +0000
+++ b/dak/cruft_report.py	2008-05-04 21:54:54 +0000
@@ -242,6 +242,20 @@
         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 @@
     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))

=== modified file 'dak/generate_releases.py'
--- a/dak/generate_releases.py	2008-05-03 23:51:40 +0000
+++ b/dak/generate_releases.py	2008-05-05 12:47:34 +0000
@@ -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 @@
             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)

=== modified file 'dak/import_archive.py'
--- a/dak/import_archive.py	2008-05-03 23:54:14 +0000
+++ b/dak/import_archive.py	2008-05-05 12:47:34 +0000
@@ -40,6 +40,7 @@
 import apt_pkg
 import daklib.database as database
 import daklib.utils as utils
+from daklib.dak_exceptions import *
 
 ###############################################################################
 
@@ -323,7 +324,7 @@
     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 @@
     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)

=== modified file 'dak/process_unchecked.py'
--- a/dak/process_unchecked.py	2008-05-04 09:13:30 +0000
+++ b/dak/process_unchecked.py	2008-05-05 12:44:31 +0000
@@ -34,6 +34,7 @@
 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 @@
     # 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 @@
         (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 @@
         (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 @@
     # 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 @@
     # 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 @@
         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 @@
         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 @@
 
         try:
             file_handle = utils.open_file(f)
-        except utils.cant_open_exc:
+        except CantOpenError:
             continue
 
         # Check hash

=== modified file 'dak/queue_report.py' (properties changed)
--- a/dak/queue_report.py	2008-05-03 12:43:58 +0000
+++ b/dak/queue_report.py	2008-05-05 12:08:51 +0000
@@ -38,6 +38,7 @@
 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 @@
                     (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"

=== modified file 'dak/rm.py'
--- a/dak/rm.py	2008-05-04 00:31:41 +0000
+++ b/dak/rm.py	2008-05-05 12:47:34 +0000
@@ -43,6 +43,7 @@
 import apt_pkg, apt_inst
 import daklib.database as database
 import daklib.utils as utils
+from daklib.dak_exceptions import *
 
 ################################################################################
 
@@ -364,7 +365,7 @@
                 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(','):

=== added file 'daklib/dak_exceptions.py'
--- a/daklib/dak_exceptions.py	1970-01-01 00:00:00 +0000
+++ b/daklib/dak_exceptions.py	2008-05-05 13:54:03 +0000
@@ -0,0 +1,66 @@
+# Exception classes used in dak
+
+# Copyright (C) 2008  Mark Hymers <mhy@debian.org>
+
+################################################################################
+
+# 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]
+
+
+
+################################################################################

=== modified file 'daklib/queue.py' (properties changed)
--- a/daklib/queue.py	2008-05-02 15:21:35 +0000
+++ b/daklib/queue.py	2008-05-05 12:44:31 +0000
@@ -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 @@
     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 @@
             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 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 @@
     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 @@
         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 @@
             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 @@
         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 @@
         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 @@
         # 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 @@
             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 @@
             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 @@
         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 @@
 
         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 @@
         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 @@
         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 @@
                     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)

=== modified file 'daklib/utils.py' (properties changed)
--- a/daklib/utils.py	2008-05-02 15:21:35 +0000
+++ b/daklib/utils.py	2008-05-05 12:44:31 +0000
@@ -25,6 +25,7 @@
        sys, tempfile, traceback
 import apt_pkg
 import database
+from dak_exceptions import *
 
 ################################################################################
 
@@ -48,17 +49,6 @@
 
 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 @@
 
 ################################################################################
 
-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 @@
     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 @@
             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 @@
         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 @@
         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 @@
             changes["source-version"] = srcver.group(2)
 
     if error:
-        raise changes_parse_error_exc, error
+        raise ParseChangesError, error
 
     return changes
 
@@ -241,12 +214,12 @@
 
     # 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 @@
 
     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 @@
             else:
                 (md5, size, name) = s
         except ValueError:
-            raise changes_parse_error_exc, i
+            raise ParseChangesError, i
 
         if section == "":
             section = "-"
@@ -387,7 +360,7 @@
     # 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 @@
     # 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 @@
         dest = orig_dest + '.' + repr(extra)
         extra += 1
     if extra >= too_many:
-        raise tried_too_hard_exc
+        raise NoFreeFilenameError
     return dest
 
 ################################################################################


Reply to: