| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 | |
| 7 """Makes changes to mounted Chromium OS image to allow it to run with VMs | |
| 8 | |
| 9 This script changes two files within the Chromium OS image to let the image | |
| 10 work with VMs, particularly QEMU | |
| 11 | |
| 12 Currently this script does the following, | |
| 13 1.) Modify the post install script to remove EFI fixup section; the VM's we | |
| 14 support don't have EFI support anyway and this section of the script needs | |
| 15 access to the actual device drives | |
| 16 | |
| 17 2.) For QEMU/KVM, we change the xorg.conf to remove mouse support and instead | |
| 18 change it to complete tablet support. This is done to provide better mouse | |
| 19 response in the VM since tablets work of absolute coordinates while the mouse | |
| 20 works of relative. In a screen that doesn't support a mouse grab (e.g., VNC), | |
| 21 relative coordinates can cause the mouse to be flaky | |
| 22 | |
| 23 """ | |
| 24 | |
| 25 from optparse import OptionParser | |
| 26 import os | |
| 27 import stat | |
| 28 import sys | |
| 29 | |
| 30 USAGE = "usage: %prog --mounted_dir=directory --enable_tablet=[true]" | |
| 31 | |
| 32 INPUT_SECTION_MARKER = r'Section "InputDevice"' | |
| 33 SECTION_END_MARKER = r'EndSection' | |
| 34 | |
| 35 MOUSE_SECTION_IDENTIFIERS = [] | |
| 36 MOUSE_SECTION_IDENTIFIERS += ['Identifier "Mouse'] | |
| 37 MOUSE_SECTION_IDENTIFIERS += ['Identifier "USBMouse'] | |
| 38 | |
| 39 REPLACE_USB_MOUSE_PAIR = ('InputDevice "USBMouse" "AlwaysCore"', '') | |
| 40 XORG_CONF_FILENAME = os.path.join('etc', 'X11', 'xorg.conf') | |
| 41 | |
| 42 | |
| 43 TABLET_DEVICE_CONFIG = """ | |
| 44 Section "InputDevice" | |
| 45 Identifier "Mouse1" | |
| 46 Driver "evdev" | |
| 47 Option "Device" "/dev/input/event2" | |
| 48 Option "CorePointer" "true" | |
| 49 EndSection | |
| 50 """ | |
| 51 | |
| 52 | |
| 53 # Modify the xorg.conf file to remove all mouse sections and replace it | |
| 54 # with ours containing the tablet - note: when running under QEMU, you | |
| 55 # *need* to specify the -usbdevice tablet option to get the mouse to work | |
| 56 def FixXorgConf(mount_point): | |
| 57 xorg_conf_filename = os.path.join(mount_point, XORG_CONF_FILENAME) | |
| 58 f = open(xorg_conf_filename, 'r') | |
| 59 xorg_conf = f.read() | |
| 60 f.close() | |
| 61 | |
| 62 more_sections = 1 | |
| 63 last_found = 0 | |
| 64 while (more_sections): | |
| 65 # Find the input section. | |
| 66 m1 = xorg_conf.find(INPUT_SECTION_MARKER, last_found) | |
| 67 if m1 > -1: | |
| 68 m2 = xorg_conf.find(SECTION_END_MARKER, m1) | |
| 69 m2 += len(SECTION_END_MARKER) | |
| 70 # Make sure the next iteration doesn't rinse/repeat. | |
| 71 last_found = m2 | |
| 72 # Check if this is a mouse section. | |
| 73 for ident in MOUSE_SECTION_IDENTIFIERS: | |
| 74 if xorg_conf.find(ident, m1, m2) != -1: | |
| 75 xorg_conf = xorg_conf[0:m1] + xorg_conf[m2:] | |
| 76 last_found -= (m2-m1) | |
| 77 break | |
| 78 else: | |
| 79 more_sections = 0 | |
| 80 | |
| 81 xorg_conf = xorg_conf[0:last_found] + TABLET_DEVICE_CONFIG + \ | |
| 82 xorg_conf[last_found:] | |
| 83 | |
| 84 # Replace UsbMouse with Tablet. | |
| 85 xorg_conf = xorg_conf.replace(REPLACE_USB_MOUSE_PAIR[0], | |
| 86 REPLACE_USB_MOUSE_PAIR[1]) | |
| 87 | |
| 88 # Write the file back out. | |
| 89 f = open(xorg_conf_filename, 'w') | |
| 90 f.write(xorg_conf) | |
| 91 f.close() | |
| 92 | |
| 93 def main(): | |
| 94 parser = OptionParser(USAGE) | |
| 95 parser.add_option('--mounted_dir', dest='mounted_dir', | |
| 96 help='directory where the Chromium OS image is mounted') | |
| 97 parser.add_option('--enable_tablet', dest='enable_tablet', | |
| 98 default="true", | |
| 99 help='fixup image for qemu') | |
| 100 (options, args) = parser.parse_args() | |
| 101 | |
| 102 if not options.mounted_dir: | |
| 103 parser.error("Please specify the mount point for the Chromium OS image"); | |
| 104 if options.enable_tablet not in ('true', 'false'): | |
| 105 parser.error("Please specify either true or false for --enable_tablet") | |
| 106 | |
| 107 if (options.enable_tablet == 'true'): | |
| 108 FixXorgConf(options.mounted_dir) | |
| 109 | |
| 110 | |
| 111 if __name__ == '__main__': | |
| 112 main() | |
| OLD | NEW |