提交 f86fb53a 编写于 作者: J Joerg Jaspert

Add an exception class and adjust the scripts using ParseMaintError to use the new class

上级 cc94fbc1
2008-05-05 Joerg Jaspert <joerg@debian.org>
* 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 <joerg@debian.org>
* daklib/queue.py: Various pychecker cleanups
......
......@@ -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))
......
......@@ -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"
......
# 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 = 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]
################################################################################
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册