Take Makefile improvements from anaconda.
[pykickstart.git] / pykickstart / errors.py
blob9420bc3b6cca2678b4cc13e0cd612253a9e1684f
2 # errors.py: Kickstart error handling.
4 # Chris Lumens <clumens@redhat.com>
6 # This copyrighted material is made available to anyone wishing to use, modify,
7 # copy, or redistribute it subject to the terms and conditions of the GNU
8 # General Public License v.2. This program is distributed in the hope that it
9 # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
10 # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 # See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # this program; if not, write to the Free Software Foundation, Inc., 51
15 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat
16 # trademarks that are incorporated in the source code or documentation are not
17 # subject to the GNU General Public License and may only be used or replicated
18 # with the express permission of Red Hat, Inc.
20 """
21 Error handling classes and functions.
23 This module exports a single function:
25 formatErrorMsg - Properly formats an error message.
27 It also exports several exception classes:
29 KickstartError - A generic exception class.
31 KickstartParseError - An exception for errors relating to parsing.
33 KickstartValueError - An exception for errors relating to option
34 processing.
36 KickstartVersionError - An exception for errors relating to unsupported
37 syntax versions.
38 """
39 from rhpl.translate import _
40 import rhpl.translate as translate
42 translate.textdomain("pykickstart")
44 def formatErrorMsg(lineno, msg=""):
45 """Properly format the error message msg for inclusion in an exception."""
46 if msg != "":
47 mapping = {"lineno": lineno, "msg": msg}
48 return _("The following problem occurred on line %(lineno)s of the kickstart file:\n\n%(msg)s\n") % mapping
49 else:
50 return _("There was a problem reading from line %s of the kickstart file") % lineno
52 class KickstartError(Exception):
53 """A generic exception class for unspecific error conditions."""
54 def __init__(self, val = ""):
55 """Create a new KickstartError exception instance with the descriptive
56 message val. val should be the return value of formatErrorMsg.
57 """
58 Exception.__init__(self)
59 self.value = val
61 def __str__ (self):
62 return self.value
64 class KickstartParseError(KickstartError):
65 """An exception class for errors when processing the input file, such as
66 unknown options, commands, or sections.
67 """
68 def __init__(self, msg):
69 """Create a new KickstartParseError exception instance with the
70 descriptive message val. val should be the return value of
71 formatErrorMsg.
72 """
73 KickstartError.__init__(self, msg)
75 def __str__(self):
76 return self.value
78 class KickstartValueError(KickstartError):
79 """An exception class for errors when processing arguments to commands,
80 such as too many arguments, too few arguments, or missing required
81 arguments.
82 """
83 def __init__(self, msg):
84 """Create a new KickstartValueError exception instance with the
85 descriptive message val. val should be the return value of
86 formatErrorMsg.
87 """
88 KickstartError.__init__(self, msg)
90 def __str__ (self):
91 return self.value
93 class KickstartVersionError(KickstartError):
94 """An exception class for errors related to using an incorrect version of
95 kickstart syntax.
96 """
97 def __init__(self, msg):
98 """Create a new KickstartVersionError exception instance with the
99 descriptive message val. val should be the return value of
100 formatErrorMsg.
102 KickstartError.__init__(self, msg)
104 def __str__ (self):
105 return self.value