Multiple device commands can be specified in a kickstart file.
[pykickstart.git] / pykickstart / commands / device.py
blobf4a9d893a733c068e73a695119b7d40ebe2f1135
2 # Chris Lumens <clumens@redhat.com>
4 # Copyright 2005, 2006, 2007 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 *
21 from pykickstart.options import *
23 from rhpl.translate import _
24 import rhpl.translate as translate
26 translate.textdomain("pykickstart")
28 class F8_DeviceData(BaseData):
29 def __init__(self, moduleName="", moduleOpts=""):
30 BaseData.__init__(self)
31 self.moduleName = moduleName
32 self.moduleOpts = moduleOpts
34 def __str__(self):
35 if self.moduleName != "":
36 if self.moduleOpts != "":
37 retval = "--opts=%s" % self.moduleOpts
38 else:
39 retval = ""
41 return "device %s %s\n" % (self.moduleName, retval)
42 else:
43 return ""
45 class FC3_Device(KickstartCommand):
46 def __init__(self, writePriority=0, type="", moduleName="", moduleOpts=""):
47 KickstartCommand.__init__(self, writePriority)
48 self.type = type
49 self.moduleName = moduleName
50 self.moduleOpts = moduleOpts
52 def __str__(self):
53 if self.moduleName != "":
54 if self.moduleOpts != "":
55 retval = "--opts=%s" % self.moduleOpts
56 else:
57 retval = ""
59 return "device %s %s %s\n" % (self.type, self.moduleName, retval)
60 else:
61 return ""
63 def parse(self, args):
64 op = KSOptionParser(lineno=self.lineno)
65 op.add_option("--opts", dest="moduleOpts", default="")
67 (opts, extra) = op.parse_args(args=args)
69 if len(extra) != 2:
70 raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("device command requires two arguments: module type and name"))
72 self.opts = opts.moduleOpts
73 self.type = extra[0]
74 self.moduleName = extra[1]
76 class F8_Device(KickstartCommand):
77 def __init__(self, writePriority=0, deviceList=None):
78 KickstartCommand.__init__(self, writePriority)
80 if deviceList == None:
81 deviceList = []
83 self.deviceList = deviceList
85 def __str__(self):
86 retval = ""
87 for device in self.deviceList:
88 retval += device.__str__()
90 return retval
92 def parse(self, args):
93 op = KSOptionParser(lineno=self.lineno)
94 op.add_option("--opts", dest="moduleOpts", default="")
96 (opts, extra) = op.parse_args(args=args)
98 if len(extra) != 1:
99 raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("%s command requires a single argument: %s") % ("device", "module name"))
101 dd = F8_DeviceData()
102 self._setToObj(op, opts, dd)
103 dd.moduleName = extra[1]
104 self.add(dd)
106 def add(self, newObj):
107 self.deviceList.append(newObj)