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