Add new RHEL7 logvol objects to master
[pykickstart.git] / pykickstart / commands / device.py
blob1d63d3a04c864a9e5a7d71812093883225e9ebc7
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 BaseData, KickstartCommand
21 from pykickstart.errors import KickstartValueError, formatErrorMsg
22 from pykickstart.options import KSOptionParser
24 import gettext
25 import warnings
26 _ = lambda x: gettext.ldgettext("pykickstart", x)
28 class F8_DeviceData(BaseData):
29 removedKeywords = BaseData.removedKeywords
30 removedAttrs = BaseData.removedAttrs
32 def __init__(self, *args, **kwargs):
33 BaseData.__init__(self, *args, **kwargs)
34 self.moduleName = kwargs.get("moduleName", "")
35 self.moduleOpts = kwargs.get("moduleOpts", "")
37 def __eq__(self, y):
38 if not y:
39 return False
41 return self.moduleName == y.moduleName
43 def __ne__(self, y):
44 return not self == y
46 def __str__(self):
47 retval = BaseData.__str__(self)
49 if self.moduleName != "":
50 retval += "device %s" % self.moduleName
52 if self.moduleOpts != "":
53 retval += " --opts=\"%s\"" % self.moduleOpts
55 return retval + "\n"
57 class FC3_Device(KickstartCommand):
58 removedKeywords = KickstartCommand.removedKeywords
59 removedAttrs = KickstartCommand.removedAttrs
61 def __init__(self, writePriority=0, *args, **kwargs):
62 KickstartCommand.__init__(self, writePriority, *args, **kwargs)
63 self.op = self._getParser()
65 self.type = kwargs.get("type", "")
66 self.moduleName = kwargs.get("moduleName", "")
67 self.moduleOpts = kwargs.get("moduleOpts", "")
69 def __eq__(self, y):
70 if not y:
71 return False
73 return self.moduleName == y.moduleName
75 def __ne__(self, y):
76 return not self == y
78 def __str__(self):
79 retval = KickstartCommand.__str__(self)
81 if self.moduleName != "":
82 retval += "device %s %s" % (self.type, self.moduleName)
84 if self.moduleOpts != "":
85 retval += " --opts=\"%s\"" % self.moduleOpts
87 return retval + "\n"
89 def _getParser(self):
90 op = KSOptionParser()
91 op.add_option("--opts", dest="moduleOpts", default="")
92 return op
94 def parse(self, args):
95 (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
97 if len(extra) != 2:
98 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("device command requires two arguments: module type and name")))
100 self.moduleOpts = opts.moduleOpts
101 self.type = extra[0]
102 self.moduleName = extra[1]
103 return self
105 class F8_Device(FC3_Device):
106 removedKeywords = FC3_Device.removedKeywords
107 removedAttrs = FC3_Device.removedAttrs
109 def __init__(self, writePriority=0, *args, **kwargs):
110 FC3_Device.__init__(self, writePriority, *args, **kwargs)
111 self.deviceList = kwargs.get("deviceList", [])
113 def __str__(self):
114 retval = ""
115 for device in self.deviceList:
116 retval += device.__str__()
118 return retval
120 def parse(self, args):
121 (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
123 if len(extra) != 1:
124 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("%s command requires a single argument: %s") % ("device", "module name")))
126 dd = F8_DeviceData()
127 self._setToObj(self.op, opts, dd)
128 dd.lineno = self.lineno
129 dd.moduleName = extra[0]
131 # Check for duplicates in the data list.
132 if dd in self.dataList():
133 warnings.warn(_("A module with the name %s has already been defined.") % dd.moduleName)
135 return dd
137 def dataList(self):
138 return self.deviceList