New version.
[pykickstart.git] / pykickstart / commands / driverdisk.py
blobc806a1e15f0fbf4a78c9feab2b051b2a0df096b3
2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2005, 2006, 2007, 2008 Red Hat, Inc.
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 from pykickstart.base import BaseData, KickstartCommand
21 from pykickstart.errors import KickstartValueError, formatErrorMsg
22 from pykickstart.options import KSOptionParser
24 import gettext
25 _ = lambda x: gettext.ldgettext("pykickstart", x)
27 class FC3_DriverDiskData(BaseData):
28 removedKeywords = BaseData.removedKeywords
29 removedAttrs = BaseData.removedAttrs
31 def __init__(self, writePriority=0, *args, **kwargs):
32 BaseData.__init__(self, writePriority, *args, **kwargs)
34 self.partition = kwargs.get("partition", "")
35 self.source = kwargs.get("source", "")
36 self.type = kwargs.get("type", "")
38 def _getArgsAsStr(self):
39 retval = ""
41 if self.partition:
42 retval += "%s" % self.partition
44 if hasattr(self, "type") and self.type:
45 retval += " --type=%s" % self.type
46 elif self.source:
47 retval += "--source=%s" % self.source
48 return retval
50 def __str__(self):
51 retval = BaseData.__str__(self)
52 retval += "driverdisk %s\n" % self._getArgsAsStr()
53 return retval
55 class FC4_DriverDiskData(FC3_DriverDiskData):
56 removedKeywords = FC3_DriverDiskData.removedKeywords
57 removedAttrs = FC3_DriverDiskData.removedAttrs
59 def __init__(self, writePriority=0, *args, **kwargs):
60 FC3_DriverDiskData.__init__(self, *args, **kwargs)
61 self.deleteRemovedAttrs()
63 self.biospart = kwargs.get("biospart", "")
65 def _getArgsAsStr(self):
66 retval = ""
68 if self.partition:
69 retval += "%s" % self.partition
71 if hasattr(self, "type") and self.type:
72 retval += " --type=%s" % self.type
73 elif self.source:
74 retval += "--source=%s" % self.source
75 elif self.biospart:
76 retval += "--biospart=%s" % self.biospart
78 return retval
80 class F12_DriverDiskData(FC4_DriverDiskData):
81 removedKeywords = FC4_DriverDiskData.removedKeywords + ["type"]
82 removedAttrs = FC4_DriverDiskData.removedAttrs + ["type"]
84 def __init__(self, *args, **kwargs):
85 FC4_DriverDiskData.__init__(self, *args, **kwargs)
86 self.deleteRemovedAttrs()
88 F14_DriverDiskData = F12_DriverDiskData
90 class FC3_DriverDisk(KickstartCommand):
91 removedKeywords = KickstartCommand.removedKeywords
92 removedAttrs = KickstartCommand.removedAttrs
94 def __init__(self, writePriority=0, *args, **kwargs):
95 KickstartCommand.__init__(self, writePriority, *args, **kwargs)
96 self.op = self._getParser()
98 self.driverdiskList = kwargs.get("driverdiskList", [])
100 def __str__(self):
101 retval = ""
102 for dd in self.driverdiskList:
103 retval += dd.__str__()
105 return retval
107 def _getParser(self):
108 op = KSOptionParser()
109 op.add_option("--source")
110 op.add_option("--type")
111 return op
113 def parse(self, args):
114 (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
116 if len(extra) > 1:
117 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Only one partition may be specified for driverdisk command.")))
119 if len(extra) == 1 and opts.source:
120 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Only one of --source and partition may be specified for driverdisk command.")))
122 if not extra and not opts.source:
123 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("One of --source or partition must be specified for driverdisk command.")))
125 ddd = self.handler.DriverDiskData()
126 self._setToObj(self.op, opts, ddd)
127 ddd.lineno = self.lineno
128 if len(extra) == 1:
129 ddd.partition = extra[0]
131 return ddd
133 def dataList(self):
134 return self.driverdiskList
136 class FC4_DriverDisk(FC3_DriverDisk):
137 removedKeywords = FC3_DriverDisk.removedKeywords
138 removedAttrs = FC3_DriverDisk.removedKeywords
140 def _getParser(self):
141 op = FC3_DriverDisk._getParser(self)
142 op.add_option("--biospart")
143 return op
145 def parse(self, args):
146 (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
148 if len(extra) > 1:
149 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Only one partition may be specified for driverdisk command.")))
151 if len(extra) == 1 and opts.source:
152 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Only one of --source and partition may be specified for driverdisk command.")))
153 elif len(extra) == 1 and opts.biospart:
154 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Only one of --biospart and partition may be specified for driverdisk command.")))
155 elif opts.source and opts.biospart:
156 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Only one of --biospart and --source may be specified for driverdisk command.")))
158 if not extra and not opts.source and not opts.biospart:
159 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("One of --source, --biospart, or partition must be specified for driverdisk command.")))
161 ddd = self.handler.DriverDiskData()
162 self._setToObj(self.op, opts, ddd)
163 ddd.lineno = self.lineno
164 if len(extra) == 1:
165 ddd.partition = extra[0]
167 return ddd
169 class F12_DriverDisk(FC4_DriverDisk):
170 removedKeywords = FC4_DriverDisk.removedKeywords
171 removedAttrs = FC4_DriverDisk.removedKeywords
173 def _getParser(self):
174 op = FC4_DriverDisk._getParser(self)
175 op.add_option("--type", deprecated=1)
176 return op
178 class F14_DriverDisk(F12_DriverDisk):
179 removedKeywords = F12_DriverDisk.removedKeywords
180 removedAttrs = F12_DriverDisk.removedKeywords
182 def _getParser(self):
183 op = F12_DriverDisk._getParser(self)
184 op.remove_option("--type")
185 return op