Have objects in one version subclass objects in a previous version. Not
[pykickstart.git] / pykickstart / errors.py
blobcdd1fe49656a6c966058b3248696cf6a1fda32ad
2 # errors.py: Kickstart error handling.
4 # Chris Lumens <clumens@redhat.com>
6 # Copyright 2005, 2006 Red Hat, Inc.
8 # This software may be freely redistributed under the terms of the GNU
9 # general public license.
11 # You should have received a copy of the GNU General Public License
12 # along with this program; if not, write to the Free Software
13 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 """
16 Error handling classes and functions.
18 This module exports a single function:
20 formatErrorMsg - Properly formats an error message.
22 It also exports several exception classes:
24 KickstartError - A generic exception class.
26 KickstartParseError - An exception for errors relating to parsing.
28 KickstartValueError - An exception for errors relating to option
29 processing.
31 KickstartVersionError - An exception for errors relating to unsupported
32 syntax versions.
33 """
34 from rhpl.translate import _
35 import rhpl.translate as translate
37 translate.textdomain("pykickstart")
39 def formatErrorMsg(lineno, msg=""):
40 """Properly format the error message msg for inclusion in an exception."""
41 if msg != "":
42 mapping = {"lineno": lineno, "msg": msg}
43 return _("The following problem occurred on line %(lineno)s of the kickstart file:\n\n%(msg)s\n") % mapping
44 else:
45 return _("There was a problem reading from line %s of the kickstart file") % lineno
47 class KickstartError(Exception):
48 """A generic exception class for unspecific error conditions."""
49 def __init__(self, val = ""):
50 """Create a new KickstartError exception instance with the descriptive
51 message val. val should be the return value of formatErrorMsg.
52 """
53 Exception.__init__(self)
54 self.value = val
56 def __str__ (self):
57 return self.value
59 class KickstartParseError(KickstartError):
60 """An exception class for errors when processing the input file, such as
61 unknown options, commands, or sections.
62 """
63 def __init__(self, msg):
64 """Create a new KickstartParseError exception instance with the
65 descriptive message val. val should be the return value of
66 formatErrorMsg.
67 """
68 KickstartError.__init__(self, msg)
70 def __str__(self):
71 return self.value
73 class KickstartValueError(KickstartError):
74 """An exception class for errors when processing arguments to commands,
75 such as too many arguments, too few arguments, or missing required
76 arguments.
77 """
78 def __init__(self, msg):
79 """Create a new KickstartValueError exception instance with the
80 descriptive message val. val should be the return value of
81 formatErrorMsg.
82 """
83 KickstartError.__init__(self, msg)
85 def __str__ (self):
86 return self.value
88 class KickstartVersionError(KickstartError):
89 """An exception class for errors related to using an incorrect version of
90 kickstart syntax.
91 """
92 def __init__(self, version):
93 """Create a new KickstartVersionError exception instance with the
94 descriptive message val. val should be the return value of
95 formatErrorMsg.
96 """
97 KickstartError.__init__(self, _("Unsupported version specified."))
99 def __str__ (self):
100 return self.value