From: Joerg Jaspert Date: Mon, 5 May 2008 12:08:51 +0000 (+0200) Subject: Add an exception class and adjust the scripts using ParseMaintError to use the new... X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=f86fb53a967d9fa0e92f3534b9a44a5ba0e6adb0;p=dak.git Add an exception class and adjust the scripts using ParseMaintError to use the new class --- diff --git a/ChangeLog b/ChangeLog index 9533845d..909eb961 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2008-05-05 Joerg Jaspert + + * dak/queue_report.py: Use the exception class + * dak/process_unchecked.py: dito + + * 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. + 2008-05-04 Joerg Jaspert * daklib/queue.py: Various pychecker cleanups diff --git a/dak/process_unchecked.py b/dak/process_unchecked.py old mode 100644 new mode 100755 index fbd7d74d..1382b113 --- 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 * @@ -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"]) = \ ("", "", "", "") @@ -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)) 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/daklib/dak_exceptions.py b/daklib/dak_exceptions.py new file mode 100644 index 00000000..e9ab2c72 --- /dev/null +++ b/daklib/dak_exceptions.py @@ -0,0 +1,63 @@ +# 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 = message + self.message = 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/utils.py b/daklib/utils.py old mode 100644 new mode 100755 index a094788f..d05719fb --- 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 * ################################################################################ @@ -67,23 +68,6 @@ 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)