Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 1 | # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | # |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 5 | """ This module manages the platform properties in mttools/platforms. """ |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 6 | from collections import namedtuple |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 7 | import json |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 8 | import os |
| 9 | import re |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 10 | import sys |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 11 | |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 12 | from cros_remote import CrOSRemote |
| 13 | from util import AskUser, ExecuteException |
| 14 | from xorg_conf import XorgInputClassParser |
| 15 | |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 16 | # path to current script directory |
| 17 | script_dir = os.path.dirname(os.path.realpath(__file__)) |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 18 | platforms_dir = os.path.realpath(os.path.join(script_dir, '..', 'platforms')) |
Chung-yih Wang | 35613f1 | 2014-04-25 13:57:23 +0800 | [diff] [blame] | 19 | xorg_conf_project_path = 'src/platform/xorg-conf' |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 20 | |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 21 | props_template = """\ |
| 22 | { |
| 23 | "gestures": { |
| 24 | }, |
| 25 | "xorg": { |
| 26 | "file": "%s", |
| 27 | "identifiers": %s |
| 28 | }, |
| 29 | "ignore": [ |
| 30 | ] |
| 31 | }""" |
| 32 | |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 33 | AbsInfo = namedtuple("AbsInfo", ("min", "max", "res")) |
| 34 | |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 35 | class PlatformProperties(object): |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 36 | """ A class containing hardware and xorg properties for a platform. |
| 37 | |
| 38 | The class can be created from an activity log or by providing |
| 39 | the name of the platform. Information will then be read from the |
| 40 | 'platforms_dir' directory. |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 41 | """ |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 42 | def __init__(self, platform=None, log=None): |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 43 | self.absinfos = {} |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 44 | self.device_class = "touchpad" |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 45 | self.properties = {} |
| 46 | self.ignore_properties = [] |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 47 | if platform: |
| 48 | basename = os.path.join(platforms_dir, platform) |
| 49 | self.name = platform |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 50 | self.hwprops_file = basename + '.hwprops' |
| 51 | self.props_file = basename + '.props' |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 52 | self.xorg_parser = XorgInputClassParser() |
| 53 | self._ParseHWProperties(open(self.hwprops_file).read()) |
| 54 | self._ParseProperties(open(self.props_file).read()) |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 55 | elif log: |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 56 | self.name = '' |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 57 | if log.evdev: |
| 58 | self._ParseEvdevLog(log.evdev) |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 59 | |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 60 | def _ParseEvdevLog(self, evdev_data): |
Dennis Kempin | 143ef16 | 2014-04-09 13:46:50 -0700 | [diff] [blame] | 61 | # Look for embedded hwproperties in header. Format: |
| 62 | # absinfo: axis min max 0 0 res |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 63 | values_regex = 6 * ' ([-0-9]+)' |
| 64 | abs_regex = re.compile('# absinfo:' + values_regex) |
| 65 | for match in abs_regex.finditer(evdev_data): |
| 66 | axis = int(match.group(1)) |
| 67 | info = AbsInfo(min=int(match.group(2)), max=int(match.group(3)), |
| 68 | res=int(match.group(6))) |
| 69 | self.absinfos[axis] = info |
Dennis Kempin | 143ef16 | 2014-04-09 13:46:50 -0700 | [diff] [blame] | 70 | |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 71 | def _ParseHWProperties(self, data): |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 72 | """Parse x and y dimensions and resolution from hwprops file.""" |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 73 | values_regex = 6 * ' ([0-9\\-a-fA-F]+)' |
| 74 | abs_regex = re.compile('A:' + values_regex) |
| 75 | for match in abs_regex.finditer(data): |
| 76 | axis = int(match.group(1), 16) |
| 77 | info = AbsInfo(min=int(match.group(2)), max=int(match.group(3)), |
| 78 | res=int(match.group(6))) |
| 79 | self.absinfos[axis] = info |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 80 | |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 81 | def _ParseProperties(self, data): |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 82 | """ Parse properties from file and inject xorg properties. """ |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 83 | self.properties = {} |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 84 | self.ignore_properties = [] |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 85 | data = json.loads(data) |
| 86 | |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 87 | if 'gestures' in data: |
| 88 | self.properties.update(data['gestures']) |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 89 | |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 90 | if 'device_class' in data: |
| 91 | self.device_class = data['device_class'] |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 92 | |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 93 | if 'ignore' in data: |
| 94 | self.ignore_properties.extend(data['ignore']) |
| 95 | |
Chung-yih Wang | 35613f1 | 2014-04-25 13:57:23 +0800 | [diff] [blame] | 96 | # Sanity check: Make sure it is not used inside ebuild. |
| 97 | if os.environ.get('PN') and os.environ.get('S'): |
| 98 | raise Exception("Should not be executed inside ebuild") |
| 99 | |
| 100 | # If run on a Chromebook device, access xorg-conf files from their normal |
| 101 | # installed location. If run from inside chroot, access xorg-conf files |
| 102 | # from the xorg-conf project repository. |
| 103 | src_root = os.environ.get('CROS_WORKON_SRCROOT') |
| 104 | if src_root: |
| 105 | xorg_conf_path = os.path.join(src_root, xorg_conf_project_path) |
| 106 | else: |
Andrew de los Reyes | c012597 | 2015-01-28 10:04:44 -0800 | [diff] [blame] | 107 | xorg_conf_path = '/etc/gesture' |
| 108 | if not os.path.exists(xorg_conf_path): |
| 109 | xorg_conf_path = '/etc/X11/xorg.conf.d' |
Chung-yih Wang | 35613f1 | 2014-04-25 13:57:23 +0800 | [diff] [blame] | 110 | |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 111 | if xorg_conf_path and 'xorg' in data and 'file' in data['xorg']: |
| 112 | filename = os.path.join(xorg_conf_path, data['xorg']['file']) |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 113 | input_classes = self.xorg_parser.Parse(file=filename) |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 114 | if 'identifier' in data['xorg']: |
| 115 | properties = input_classes[data['xorg']['identifier']] |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 116 | self.properties.update(properties) |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 117 | if 'identifiers' in data['xorg']: |
| 118 | for identifier in data['xorg']['identifiers']: |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 119 | properties = input_classes[identifier] |
| 120 | self.properties.update(properties) |
| 121 | |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 122 | for prop in self.ignore_properties: |
| 123 | if prop in self.properties: |
| 124 | del self.properties[prop] |
| 125 | |
Dennis Kempin | 55af9cc | 2013-06-20 15:07:21 -0700 | [diff] [blame] | 126 | def Match(self, other, loose, debug=False): |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 127 | """ Compare properties and return similarity. |
| 128 | |
| 129 | Compare these properties to another PlatformProperties instance. |
| 130 | The return value is a score between 1. 0 meaning there is a big mismatch |
| 131 | and 1 meaning the properties match completely. |
| 132 | Only a selected range of properties are compared in order to |
| 133 | prevent property adjustments to cause platforms to be mismatched. |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 134 | """ |
| 135 | scores = [] |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 136 | def compare_absinfo_prop(a, b, field): |
| 137 | a_value = float(getattr(a, field)) if a else None |
| 138 | b_value = float(getattr(b, field)) if b else None |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 139 | |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 140 | score = 0.0 |
| 141 | if a_value is not None and b_value is not None: |
| 142 | delta = abs(float(a_value) - float(b_value)) |
| 143 | if delta > 0: |
| 144 | score = 1.0 - min(1.0, delta / max(abs(a_value), abs(b_value))) |
| 145 | else: |
| 146 | score = 1.0 |
| 147 | scores.append(score) |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 148 | |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 149 | a_str = str(a_value) if a_value is not None else "N/A" |
| 150 | b_str = str(b_value) if b_value is not None else "N/A" |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 151 | if debug: |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 152 | print " %s: %.2f (%s == %s)" % (field, score, a_str, b_str) |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 153 | |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 154 | for axis in set(self.absinfos.keys() + other.absinfos.keys()): |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 155 | if debug: |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 156 | print "axis %d:" % axis |
| 157 | self_absinfo = self.absinfos.get(axis, None) |
| 158 | other_absinfo = other.absinfos.get(axis, None) |
| 159 | compare_absinfo_prop(self_absinfo, other_absinfo, "min") |
| 160 | compare_absinfo_prop(self_absinfo, other_absinfo, "max") |
| 161 | compare_absinfo_prop(self_absinfo, other_absinfo, "res") |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 162 | |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 163 | return reduce(lambda x, y: (x * y), scores) |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 164 | |
| 165 | class PlatformDatabase(object): |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 166 | """ Class for managing platforms. |
| 167 | |
| 168 | This class reads all available platforms from the platforms_dir and allows |
| 169 | to search for matching platforms to an activity log file. |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 170 | """ |
| 171 | def __init__(self): |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 172 | platform_files = [f for f in os.listdir(platforms_dir) |
| 173 | if f.endswith('.hwprops')] |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 174 | self.platforms = {} |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 175 | for filename in platform_files: |
| 176 | name = filename.replace('.hwprops', '') |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 177 | self.platforms[name] = PlatformProperties(platform=name) |
| 178 | |
Dennis Kempin | 55af9cc | 2013-06-20 15:07:21 -0700 | [diff] [blame] | 179 | def FindMatching(self, log, loose=True, debug=False): |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 180 | """ Find platform matching activity_data. |
| 181 | |
| 182 | Returns the PlatformProperties instance of the platform matching |
| 183 | the activity log data. This method might terminate the program in |
| 184 | case no match can be made, or the match is ambiguous. |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 185 | """ |
| 186 | result = None |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 187 | properties = PlatformProperties(log=log) |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 188 | for name, platform in self.platforms.items(): |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 189 | if debug: |
Dennis Kempin | 3cb7b90 | 2015-04-06 11:12:40 -0700 | [diff] [blame] | 190 | print "-" * 30, name |
Dennis Kempin | 55af9cc | 2013-06-20 15:07:21 -0700 | [diff] [blame] | 191 | score = platform.Match(properties, loose, debug) |
Dennis Kempin | 1a8a5be | 2013-06-18 11:00:02 -0700 | [diff] [blame] | 192 | if debug: |
| 193 | print name, "score =", score |
Andrew de los Reyes | f56af27 | 2014-07-21 14:32:21 -0700 | [diff] [blame] | 194 | if score > 0.96: |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 195 | if result: |
Dennis Kempin | 55af9cc | 2013-06-20 15:07:21 -0700 | [diff] [blame] | 196 | if loose: |
| 197 | if debug: |
| 198 | print "-" * 10, "Multiple matches. Try strict" |
| 199 | return self.FindMatching(log, False, debug) |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 200 | print ('multiple matching platforms:', result.name, |
| 201 | 'and', platform.name) |
Dennis Kempin | 19e972b | 2013-06-20 13:21:38 -0700 | [diff] [blame] | 202 | return None |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 203 | result = platform |
| 204 | if not result: |
Dennis Kempin | 17766a6 | 2013-06-17 14:09:33 -0700 | [diff] [blame] | 205 | print 'cannot find matching platform' |
Dennis Kempin | 19e972b | 2013-06-20 13:21:38 -0700 | [diff] [blame] | 206 | return None |
Dennis Kempin | 037675e | 2013-06-14 14:12:39 -0700 | [diff] [blame] | 207 | return result |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 208 | |
| 209 | @staticmethod |
| 210 | def RegisterPlatformFromDevice(ip): |
| 211 | # get list of multitouch devices |
| 212 | remote = CrOSRemote(ip) |
Amirhossein Simjour | 9127ff1 | 2015-03-11 15:47:14 -0400 | [diff] [blame] | 213 | inputcontrolexist = True |
| 214 | try: |
| 215 | devices = remote.SafeExecute( |
| 216 | "/opt/google/input/inputcontrol -t multitouch --names", |
| 217 | verbose=True) |
| 218 | except ExecuteException: |
| 219 | inputcontrolexist = False |
| 220 | if inputcontrolexist: |
| 221 | # Each line has the format: |
| 222 | # id: Device Name |
| 223 | # devices[*][0] will have the id |
| 224 | # devices[*][1] will have the name |
| 225 | devices = devices.splitlines() |
| 226 | devices = [l.split(":", 1) for l in devices] |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 227 | |
Amirhossein Simjour | 9127ff1 | 2015-03-11 15:47:14 -0400 | [diff] [blame] | 228 | # select one device from list |
| 229 | idx = AskUser.Select([d[1] for d in devices], |
| 230 | "Which device would you like to register?") |
| 231 | device_id = devices[idx][0] |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 232 | |
Amirhossein Simjour | 9127ff1 | 2015-03-11 15:47:14 -0400 | [diff] [blame] | 233 | # read hardware properties |
| 234 | hwprops = remote.SafeExecute( |
| 235 | "/opt/google/input/inputcontrol --id %s --hwprops" % device_id, |
| 236 | verbose=True) |
| 237 | else: |
Charlie Mooney | 5fe577f | 2015-08-20 13:22:17 -0700 | [diff] [blame^] | 238 | event_devices = remote.SafeExecute( |
Amirhossein Simjour | 9127ff1 | 2015-03-11 15:47:14 -0400 | [diff] [blame] | 239 | "ls /dev/input/ | grep event", |
| 240 | verbose=True) |
Charlie Mooney | 5fe577f | 2015-08-20 13:22:17 -0700 | [diff] [blame^] | 241 | event_devices = event_devices.splitlines() |
| 242 | devices = [] |
| 243 | for d in event_devices: |
Amirhossein Simjour | 9127ff1 | 2015-03-11 15:47:14 -0400 | [diff] [blame] | 244 | device_desc_evemu = remote.SafeExecute( |
| 245 | "evemu-describe /dev/input/%s |grep N:" % d, |
| 246 | verbose=False) |
Charlie Mooney | 5fe577f | 2015-08-20 13:22:17 -0700 | [diff] [blame^] | 247 | event_number = int((d.split("event", 1))[1]) |
Amirhossein Simjour | bcc3701 | 2015-07-07 14:59:56 -0400 | [diff] [blame] | 248 | device_desc_evemu = device_desc_evemu.split("N:",1)[1] |
Charlie Mooney | 5fe577f | 2015-08-20 13:22:17 -0700 | [diff] [blame^] | 249 | |
| 250 | devices.append([event_number, device_desc_evemu]) |
| 251 | |
| 252 | idx = AskUser.Select([t[1] for t in devices], |
Amirhossein Simjour | 9127ff1 | 2015-03-11 15:47:14 -0400 | [diff] [blame] | 253 | "Which device would you like to register?") |
Charlie Mooney | 5fe577f | 2015-08-20 13:22:17 -0700 | [diff] [blame^] | 254 | device_id = devices[idx][0] |
Amirhossein Simjour | 9127ff1 | 2015-03-11 15:47:14 -0400 | [diff] [blame] | 255 | hwprops = remote.SafeExecute( |
Charlie Mooney | 5fe577f | 2015-08-20 13:22:17 -0700 | [diff] [blame^] | 256 | "evemu-describe /dev/input/event%s" % devices[idx][0], |
Amirhossein Simjour | 9127ff1 | 2015-03-11 15:47:14 -0400 | [diff] [blame] | 257 | verbose=True) |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 258 | if not hwprops: |
Amirhossein Simjour | 9127ff1 | 2015-03-11 15:47:14 -0400 | [diff] [blame] | 259 | print "Please update your device to latest canary or:" |
| 260 | print " emerge-${BOARD} inputcontrol" |
| 261 | print " cros deploy $DEVICE_IP inputcontrol" |
| 262 | return None |
Charlie Mooney | 5fe577f | 2015-08-20 13:22:17 -0700 | [diff] [blame^] | 263 | |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 264 | |
Dennis Kempin | cd7caba | 2014-04-16 13:37:18 -0700 | [diff] [blame] | 265 | xorg_files = [ |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 266 | "/etc/X11/xorg.conf.d/60-touchpad-cmt-*.conf", |
| 267 | "/etc/X11/xorg.conf.d/50-touchpad-cmt-*.conf", |
Amirhossein Simjour | 9127ff1 | 2015-03-11 15:47:14 -0400 | [diff] [blame] | 268 | "/etc/X11/xorg.conf.d/40-touchpad-cmt.conf", |
| 269 | "/etc/gesture/60-touchpad-cmt-*.conf", |
| 270 | "/etc/gesture/50-touchpad-cmt-*.conf", |
| 271 | "/etc/gesture/40-touchpad-cmt.conf" |
Dennis Kempin | cd7caba | 2014-04-16 13:37:18 -0700 | [diff] [blame] | 272 | ] |
| 273 | |
| 274 | for pattern in xorg_files: |
| 275 | # find filename of xorg configuration file |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 276 | xorg_file = remote.Execute("ls " + pattern, verbose=False) |
Dennis Kempin | cd7caba | 2014-04-16 13:37:18 -0700 | [diff] [blame] | 277 | if not xorg_file: |
| 278 | continue |
| 279 | xorg_file = xorg_file.strip() |
| 280 | |
| 281 | # extract identifiers |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 282 | print "Selecting Xorg identifiers from", xorg_file |
| 283 | conf = remote.Read(xorg_file) |
Dennis Kempin | cd7caba | 2014-04-16 13:37:18 -0700 | [diff] [blame] | 284 | all_ids = [] |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 285 | for match in re.finditer("Identifier\\s+\"([a-zA-Z0-9-_ ]+)\"", conf): |
Dennis Kempin | cd7caba | 2014-04-16 13:37:18 -0700 | [diff] [blame] | 286 | all_ids.append(match.group(1)) |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 287 | |
Dennis Kempin | cd7caba | 2014-04-16 13:37:18 -0700 | [diff] [blame] | 288 | # ask user to select |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 289 | idxs = AskUser.SelectMulti( |
| 290 | all_ids, "Which xorg identifiers apply to this device?", |
| 291 | allow_none=True) |
Dennis Kempin | cd7caba | 2014-04-16 13:37:18 -0700 | [diff] [blame] | 292 | ids = [all_ids[i] for i in idxs] |
| 293 | if ids: |
| 294 | break |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 295 | |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 296 | if not ids: |
Dennis Kempin | cd7caba | 2014-04-16 13:37:18 -0700 | [diff] [blame] | 297 | print "Please configure the platform properties manually" |
| 298 | xorg_file = "todo: add correct xorg conf file" |
| 299 | ids = ["todo: add correct xorg identifier"] |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 300 | |
Dennis Kempin | 58d9a74 | 2014-05-08 18:34:59 -0700 | [diff] [blame] | 301 | ids_string = "[" + ", ".join(["\"%s\"" % i for i in ids]) + "]" |
Dennis Kempin | d0b722a | 2014-04-15 11:54:48 -0700 | [diff] [blame] | 302 | xorg_file = os.path.basename(xorg_file) |
| 303 | |
| 304 | sys.stdout.write("Please name this platform: ") |
| 305 | sys.stdout.flush() |
| 306 | platform_name = sys.stdin.readline().strip() |
| 307 | |
| 308 | # write platform info to files |
| 309 | hwprops_file = os.path.join(platforms_dir, platform_name + ".hwprops") |
| 310 | props_file = os.path.join(platforms_dir, platform_name + ".props") |
| 311 | |
| 312 | open(hwprops_file, "w").write(hwprops) |
| 313 | open(props_file, "w").write(props_template % (xorg_file, ids_string)) |
| 314 | |
| 315 | print "Created files: " |
| 316 | print " ", hwprops_file |
| 317 | print " ", props_file |
| 318 | |
| 319 | return platform_name |