Add a new version of the device command that does not take a type argument.
[pykickstart.git] / pykickstart / commands / device.py
blobaec09605130fa563de2b21a5497f0c267f2c83f3
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 FC3_Device(KickstartCommand):
29 def __init__(self, writePriority=0, type="", moduleName="", moduleOpts=""):
30 KickstartCommand.__init__(self, writePriority)
31 self.type = type
32 self.moduleName = moduleName
33 self.moduleOpts = moduleOpts
35 def __str__(self):
36 if self.moduleName != "":
37 if self.moduleOpts != "":
38 retval = "--opts=%s" % self.moduleOpts
39 else:
40 retval = ""
42 return "device %s %s %s\n" % (self.type, self.moduleName, retval)
43 else:
44 return ""
46 def parse(self, args):
47 op = KSOptionParser(lineno=self.lineno)
48 op.add_option("--opts", dest="moduleOpts", default="")
50 (opts, extra) = op.parse_args(args=args)
52 if len(extra) != 2:
53 raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("device command requires two arguments: module type and name"))
55 self.opts = opts.moduleOpts
56 self.type = extra[0]
57 self.moduleName = extra[1]
59 class F8_Device(KickstartCommand):
60 def __init__(self, writePriority=0, moduleName="", moduleOpts=""):
61 KickstartCommand.__init__(self, writePriority)
62 self.moduleName = moduleName
63 self.moduleOpts = moduleOpts
65 def __str__(self):
66 if self.moduleName != "":
67 if self.moduleOpts != "":
68 retval = "--opts=%s" % self.moduleOpts
69 else:
70 retval = ""
72 return "device %s %s\n" % (self.moduleName, retval)
73 else:
74 return ""
76 def parse(self, args):
77 op = KSOptionParser(lineno=self.lineno)
78 op.add_option("--opts", dest="moduleOpts", default="")
80 (opts, extra) = op.parse_args(args=args)
82 if len(extra) != 1:
83 raise KickstartValueError, formatErrorMsg(self.lineno, msg=_("%s command requires a single argument: %s") % ("device", "module name"))
85 self.opts = opts.moduleOpts
86 self.moduleName = extra[1]