Add new RHEL7 logvol objects to master
[pykickstart.git] / pykickstart / commands / keyboard.py
blob56893e662e57d071dc621e1f3de77659e1626172
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 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_Keyboard(KickstartCommand):
28 removedKeywords = KickstartCommand.removedKeywords
29 removedAttrs = KickstartCommand.removedAttrs
31 def __init__(self, writePriority=0, *args, **kwargs):
32 KickstartCommand.__init__(self, writePriority, *args, **kwargs)
33 self.op = self._getParser()
34 self.keyboard = kwargs.get("keyboard", "")
36 def __str__(self):
37 retval = KickstartCommand.__str__(self)
39 if self.keyboard != "":
40 retval += "# System keyboard\nkeyboard %s\n" % self.keyboard
42 return retval
44 def _getParser(self):
45 op = KSOptionParser()
46 return op
48 def parse(self, args):
49 (_opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
51 if len(extra) != 1:
52 raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Kickstart command %s requires one argument") % "keyboard"))
54 self.keyboard = extra[0]
55 return self
57 class F18_Keyboard(FC3_Keyboard):
58 # pylint: disable=super-init-not-called
59 def __init__(self, writePriority=0, *args, **kwargs):
60 # pylint: disable=non-parent-init-called
61 KickstartCommand.__init__(self, writePriority, *args, **kwargs)
62 self.op = self._getParser()
63 self._keyboard = kwargs.get("_keyboard", "")
64 self.vc_keymap = kwargs.get("vc_keymap", "")
65 self.x_layouts = kwargs.get("x_layouts", [])
66 self.switch_options = kwargs.get("switch_options", [])
68 def __str__(self):
69 if not any((self._keyboard, self.x_layouts, self.vc_keymap)):
70 return ""
72 retval = "# Keyboard layouts\n"
73 if not self.vc_keymap and not self.x_layouts:
74 retval += "keyboard '%s'\n" % self._keyboard
75 return retval
77 if self._keyboard:
78 retval += "# old format: keyboard %s\n" % self._keyboard
79 retval += "# new format:\n"
80 retval += "keyboard" + self._getArgsAsStr() + "\n"
82 return retval
84 def _getArgsAsStr(self):
85 retval = ""
87 if self.vc_keymap:
88 retval += " --vckeymap=%s" % self.vc_keymap
90 if self.x_layouts:
91 layouts_str = "'%s'" % self.x_layouts[0]
92 for layout in self.x_layouts[1:]:
93 layouts_str += ",'%s'" % layout
94 retval += " --xlayouts=%s" % layouts_str
96 if self.switch_options:
97 switch_str = "'%s'" % self.switch_options[0]
98 for opt in self.switch_options[1:]:
99 switch_str += ",'%s'" % opt
100 retval += " --switch=%s" % switch_str
102 return retval
104 def _getParser(self):
105 def csv_parse_callback(option, _opt_str, value, parser):
106 for item in value.split(","):
107 if item:
108 parser.values.ensure_value(option.dest, []).append(item)
110 op = FC3_Keyboard._getParser(self)
111 op.add_option("--vckeymap", dest="vc_keymap", action="store", default="")
112 op.add_option("--xlayouts", dest="x_layouts", action="callback",
113 callback=csv_parse_callback, nargs=1, type="string")
114 op.add_option("--switch", dest="switch_options", action="callback",
115 callback=csv_parse_callback, nargs=1, type="string")
117 return op
119 def parse(self, args):
120 (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
121 self._setToSelf(self.op, opts)
123 if len(extra) > 1:
124 message = _("A single argument is expected for the %s command") % \
125 "keyboard"
126 raise KickstartValueError(formatErrorMsg(self.lineno, msg=message))
128 elif len(extra) == 0 and not self.vc_keymap and not self.x_layouts:
129 message = _("One of --xlayouts, --vckeymap options with value(s) "
130 "or argument is expected for the keyboard command")
131 raise KickstartValueError(formatErrorMsg(self.lineno, msg=message))
133 if len(extra) > 0:
134 self._keyboard = extra[0]
136 return self
138 # property for backwards compatibility
139 # pylint: disable=method-hidden
140 @property
141 def keyboard(self):
142 if self.x_layouts:
143 return self._keyboard or self.vc_keymap or self.x_layouts[0]
144 else:
145 return self._keyboard or self.vc_keymap or ""
147 # pylint: disable=function-redefined,no-member
148 @keyboard.setter
149 def keyboard(self, value):
150 self._keyboard = value