]> git.decadent.org.uk Git - dak.git/blob - daklib/dak_exceptions.py
Add an exception class and adjust the scripts using ParseMaintError to use the new...
[dak.git] / daklib / dak_exceptions.py
1 # Exception classes used in dak
2
3 # Copyright (C) 2008  Mark Hymers <mhy@debian.org>
4
5 ################################################################################
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21 ################################################################################
22
23 class DakError(Exception):
24     """Base class for all simple errors in this module.
25
26     Attributes:
27
28        message -- explanation of the error
29     """
30
31     def __init__(self, message):
32         self.args = message
33         self.message = message
34
35 __all__ = ['DakError']
36
37 dakerrors = {
38     "ParseMaintError":     """Exception raised for errors in parsing a maintainer field.""",
39     "ParseChangesError":   """Exception raised for errors in parsing a changes file.""",
40     "InvalidDscError":     """Exception raised for invalid dsc files.""",
41     "UnknownFormatError":  """Exception raised for unknown Format: lines in changes files.""",
42     "NoFilesFieldError":   """Exception raised for missing files field in dsc/changes.""",
43     "CantOpenError":       """Exception raised when files can't be opened.""",
44     "CantOverwriteError":  """Exception raised when files cant be overwritten.""",
45     "FileExistsError":     """Exception raised when destination file exists.""",
46     "SendmailFailedError": """Exception raised when Sendmail invocation failed.""",
47     "NoFreeFilenameError": """Exception raised when no alternate filename was found."""
48 }
49
50
51 def construct_dak_exception(name, description):
52     class Er(DakError):
53         __doc__ = description
54     setattr(Er, "__name__", name)
55     return Er
56
57 for e in dakerrors.keys():
58     globals()[e] = construct_dak_exception(e, dakerrors[e])
59     __all__ += [e]
60
61
62
63 ################################################################################