hostkeymap: Globally cache the host lookup

Rather than make the callers worry about it
This commit is contained in:
Cole Robinson 2013-07-13 20:58:09 -04:00
parent ed826315a5
commit 41afdfd9aa
3 changed files with 10 additions and 17 deletions

View File

@ -125,10 +125,6 @@ class VirtualGraphics(VirtualDevice):
if channels: if channels:
self.channels = channels self.channels = channels
def _cache(self):
# Make sure we've cached the _local_keymap value before copy()
self._default_keymap()
def _default_keymap(self, force_local=False): def _default_keymap(self, force_local=False):
if (not force_local and if (not force_local and
self.conn.check_conn_support( self.conn.check_conn_support(

View File

@ -20,6 +20,9 @@
import logging import logging
import re import re
_cached_keymap = None
# Host keytable entry : keymap name in qemu/xen # Host keytable entry : keymap name in qemu/xen
# Only use lower case entries: all lookups are .lower()'d # Only use lower case entries: all lookups are .lower()'d
keytable = { keytable = {
@ -130,6 +133,13 @@ def _xorg_keymap():
def default_keymap(): def default_keymap():
global _cached_keymap
if _cached_keymap is None:
_cached_keymap = _default_keymap()
return _cached_keymap
def _default_keymap():
""" """
Look in various config files for the host machine's keymap, and attempt Look in various config files for the host machine's keymap, and attempt
to map it to a keymap supported by qemu to map it to a keymap supported by qemu
@ -168,13 +178,10 @@ def default_keymap():
return default return default
kt = kt.lower() kt = kt.lower()
keymap = sanitize_keymap(kt) keymap = sanitize_keymap(kt)
if not keymap: if not keymap:
logging.debug("Didn't match keymap '%s' in keytable!", kt) logging.debug("Didn't match keymap '%s' in keytable!", kt)
return default return default
return keymap return keymap

View File

@ -519,17 +519,7 @@ class XMLBuilder(object):
self._parsexml(parsexml, parsexmlnode) self._parsexml(parsexml, parsexmlnode)
def _cache(self):
"""
This is a hook for classes to cache any state that is expensive
to lookup before we copy the object as part of Guest.get_xml_config.
Saves us from possibly doing the lookup over and over
"""
pass
def copy(self): def copy(self):
self._cache()
return copy.copy(self) return copy.copy(self)
def _get_conn(self): def _get_conn(self):