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
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", "")
37 retval
= KickstartCommand
.__str
__(self
)
39 if self
.keyboard
!= "":
40 retval
+= "# System keyboard\nkeyboard %s\n" % self
.keyboard
48 def parse(self
, args
):
49 (_opts
, extra
) = self
.op
.parse_args(args
=args
, lineno
=self
.lineno
)
52 raise KickstartValueError(formatErrorMsg(self
.lineno
, msg
=_("Kickstart command %s requires one argument") % "keyboard"))
54 self
.keyboard
= extra
[0]
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", [])
69 if not any((self
._keyboard
, self
.x_layouts
, self
.vc_keymap
)):
72 retval
= "# Keyboard layouts\n"
73 if not self
.vc_keymap
and not self
.x_layouts
:
74 retval
+= "keyboard '%s'\n" % self
._keyboard
78 retval
+= "# old format: keyboard %s\n" % self
._keyboard
79 retval
+= "# new format:\n"
80 retval
+= "keyboard" + self
._getArgsAsStr
() + "\n"
84 def _getArgsAsStr(self
):
88 retval
+= " --vckeymap=%s" % self
.vc_keymap
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
104 def _getParser(self
):
105 def csv_parse_callback(option
, _opt_str
, value
, parser
):
106 for item
in value
.split(","):
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")
119 def parse(self
, args
):
120 (opts
, extra
) = self
.op
.parse_args(args
=args
, lineno
=self
.lineno
)
121 self
._setToSelf
(self
.op
, opts
)
124 message
= _("A single argument is expected for the %s command") % \
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
))
134 self
._keyboard
= extra
[0]
138 # property for backwards compatibility
139 # pylint: disable=method-hidden
143 return self
._keyboard
or self
.vc_keymap
or self
.x_layouts
[0]
145 return self
._keyboard
or self
.vc_keymap
or ""
147 # pylint: disable=function-redefined,no-member
149 def keyboard(self
, value
):
150 self
._keyboard
= value