Hi,
virt-install checks the host system to determine the keyboard layout
for virtual machines it creates.
One of the places it checks is /etc/default/console-setup. In the
next version of Debian, the file to look for is /etc/default/keyboard
[1].
Currently, the Debian package has a patch to virt-install to check
this different path:
-CONSOLE_SETUP_CONF = "/etc/default/console-setup"
+CONSOLE_SETUP_CONF = "/etc/default/keyboard"
I've attached a patch that will check for 'keyboard' and then 'console-setup'
This patch:
* Makes the above distro-specific patch unnecessary;
* Allows the Debian package to be used on Ubuntu (great when Ubuntu
is behind the latest version);
* Is more robust for users upgrading from one Debian version to the
next (particularly if they don't upgrade everything at once);
* Reduces the amount of code in util.py without breaking API compatibility
* Removes a copy and paste error in util.py (XORG_CONF in
_console_setup_keymap()).
Martin
[1] http://debian-user.blogspot.com/2010/06/etcdefaultkeyboard-replaces.html
diff -r b2eec170e9fa virtinst/_util.py
--- a/virtinst/_util.py Wed Oct 27 13:11:47 2010 -0400
+++ b/virtinst/_util.py Thu Oct 28 20:29:45 2010 +0100
@@ -440,6 +440,48 @@
return ret
+def find_xkblayout(path):
+ """
+ Reads a keyboard layout from a file that defines an XKBLAYOUT
+ variable, e.g. /etc/default/{keyboard,console-setup}.
+ The format of these files is such that they can be 'sourced'
+ in a shell script.
+ """
+
+ kt = None
+ try:
+ f = open(path, "r")
+ except IOError, e:
+ logging.debug('Could not open "%s": %s ' % (path, str(e)))
+ else:
+ keymap_re = re.compile(r'\s*XKBLAYOUT="(?P<kt>[a-z-]+)"')
+ for line in f:
+ m = keymap_re.match(line)
+ if m:
+ kt = m.group('kt')
+ break
+ else:
+ logging.debug("Didn't find keymap in '%s'!" % path)
+ f.close()
+ return kt
+
+def find_keymap_from_etc_default():
+ """
+ Look under /etc/default for the host machine's keymap.
+
+ This checks both /etc/default/keyboard and /etc/default/console-setup.
+ The former is used by Debian 6.0 (Squeeze) and later. The latter is
+ used by older versions of Debian, and Ubuntu.
+ """
+
+ KEYBOARD_DEFAULT = "/etc/default/keyboard"
+ paths = [ KEYBOARD_DEFAULT, util.CONSOLE_SETUP_CONF ]
+ for path in paths:
+ kt = find_xkblayout(path)
+ if kt != None:
+ break
+ return kt
+
#
# These functions accidentally ended up in the API under virtinst.util
#
diff -r b2eec170e9fa virtinst/util.py
--- a/virtinst/util.py Wed Oct 27 13:11:47 2010 -0400
+++ b/virtinst/util.py Thu Oct 28 20:29:45 2010 +0100
@@ -325,23 +325,7 @@
def _console_setup_keymap():
"""Look in /etc/default/console-setup for the host machine's keymap, and attempt to
map it to a keymap supported by qemu"""
-
- kt = None
- try:
- f = open(CONSOLE_SETUP_CONF, "r")
- except IOError, e:
- logging.debug('Could not open "%s": %s ' % (CONSOLE_SETUP_CONF, str(e)))
- else:
- keymap_re = re.compile(r'\s*XKBLAYOUT="(?P<kt>[a-z-]+)"')
- for line in f:
- m = keymap_re.match(line)
- if m:
- kt = m.group('kt')
- break
- else:
- logging.debug("Didn't find keymap in '%s'!" % XORG_CONF)
- f.close()
- return kt
+ return virtinst._util.find_xkblayout(CONSOLE_SETUP_CONF)
def default_keymap():
"""Look in /etc/sysconfig for the host machine's keymap, and attempt to
@@ -358,7 +342,7 @@
logging.debug('Could not open "/etc/sysconfig/keyboard" ' + str(e))
kt = _xorg_keymap()
if not kt:
- kt = _console_setup_keymap()
+ kt = virtinst._util.find_keymap_from_etc_default()
else:
while 1:
s = f.readline()
_______________________________________________
virt-tools-list mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virt-tools-list