diff options
author | Nick Sanders <nsanders@google.com> | 2022-04-21 18:01:05 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-06-23 16:08:52 +0000 |
commit | 275a875a350e6f0e898a88ec82aa0b8edce5d1e6 (patch) | |
tree | 9879c7e958cc28a7e79513c4adab39a30af45093 /extra/usb_serial | |
parent | bd1b447a11ce622ac92c297dca29dd51b540d9c6 (diff) | |
download | chrome-ec-275a875a350e6f0e898a88ec82aa0b8edce5d1e6.tar.gz |
tigertool: cleanup
Fix serial number detect
new python3.9 incompatibilities.
cros lint to the extent possible
BUG=b:216199797
TEST=./tigertest.py -c 10; servo_updater -b servo_v4
BRANCH=none
Signed-off-by: Nick Sanders <nsanders@chromium.org>
Change-Id: I2ec628389f63711a540223fc9004c9fff7155c1e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3615478
Reviewed-by: Ruben Rodriguez Buchillon <coconutruben@chromium.org>
Diffstat (limited to 'extra/usb_serial')
-rwxr-xr-x | extra/usb_serial/console.py | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/extra/usb_serial/console.py b/extra/usb_serial/console.py index d06b33ce23..7211dceff6 100755 --- a/extra/usb_serial/console.py +++ b/extra/usb_serial/console.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # Copyright 2016 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -19,15 +19,14 @@ import sys import termios import threading import time -import traceback import tty try: import usb -except: - print("import usb failed") - print("try running these commands:") - print(" sudo apt-get install python-pip") - print(" sudo pip install --pre pyusb") +except ModuleNotFoundError: + print('import usb failed') + print('try running these commands:') + print(' sudo apt-get install python-pip') + print(' sudo pip install --pre pyusb') print() sys.exit(-1) @@ -77,9 +76,9 @@ class Susb(): Discovers and connects to USB endpoints. Args: - vendor : usb vendor id of device - product : usb product id of device - interface : interface number ( 1 - 8 ) of device to use + vendor: usb vendor id of device + product: usb product id of device + interface: interface number ( 1 - 8 ) of device to use serialname: string of device serialnumber. Raises: @@ -89,7 +88,7 @@ class Susb(): dev_g = usb.core.find(idVendor=vendor, idProduct=product, find_all=True) dev_list = list(dev_g) if dev_list is None: - raise SusbError("USB device not found") + raise SusbError('USB device not found') # Check if we have multiple devices. dev = None @@ -104,7 +103,7 @@ class Susb(): dev = d break if dev is None: - raise SusbError("USB device(%s) not found" % (serialname,)) + raise SusbError('USB device(%s) not found' % (serialname,)) else: try: dev = dev_list[0] @@ -112,7 +111,7 @@ class Susb(): try: dev = dev_list.next() except: - raise SusbError("USB device %04x:%04x not found" % (vendor, product)) + raise SusbError('USB device %04x:%04x not found' % (vendor, product)) # If we can't set configuration, it's already been set. try: @@ -126,7 +125,7 @@ class Susb(): self._intf = intf if not intf: - raise SusbError("Interface not found") + raise SusbError('Interface not found') # Detach raiden.ko if it is loaded. if dev.is_kernel_driver_active(intf.bInterfaceNumber) is True: @@ -181,7 +180,7 @@ class Suart(): """ self._done = threading.Event() self._susb = Susb(vendor=vendor, product=product, - interface=interface, serialname=serialname) + interface=interface, serialname=serialname) def wait_until_done(self, timeout=None): return self._done.wait(timeout=timeout) @@ -199,7 +198,7 @@ class Suart(): # If we miss some characters on pty disconnect, that's fine. # ep.read() also throws USBError on timeout, which we discard. if not isinstance(e, (OSError, usb.core.USBError)): - print("rx %s" % e) + print('rx %s' % e) finally: self._done.set() @@ -208,19 +207,18 @@ class Suart(): while True: try: r = GetBuffer(sys.stdin).read(1) - if not r or r == b"\x03": + if not r or r == b'\x03': break if r: self._susb._write_ep.write(array.array('B', r), self._susb.TIMEOUT_MS) except Exception as e: - print("tx %s" % e) + print('tx %s' % e) finally: self._done.set() def run(self): - """Creates pthreads to poll USB & PTY for data. - """ + """Creates pthreads to poll USB & PTY for data.""" self._exit = False self._rx_thread = threading.Thread(target=self.run_rx_thread) @@ -239,18 +237,17 @@ class Suart(): Ctrl-C exits. """ -parser = argparse.ArgumentParser(description="Open a console to a USB device") +parser = argparse.ArgumentParser(description='Open a console to a USB device') parser.add_argument('-d', '--device', type=str, - help="vid:pid of target device", default="18d1:501c") + help='vid:pid of target device', default='18d1:501c') parser.add_argument('-i', '--interface', type=int, - help="interface number of console", default=0) + help='interface number of console', default=0) parser.add_argument('-s', '--serialno', type=str, - help="serial number of device", default="") + help='serial number of device', default='') parser.add_argument('-S', '--notty-exit-sleep', type=float, default=0.2, - help="When stdin is *not* a TTY, wait this many seconds after EOF from " - "stdin before exiting, to give time for receiving a reply from the USB " - "device.") - + help='When stdin is *not* a TTY, wait this many seconds ' + 'after EOF from stdin before exiting, to give time for ' + 'receiving a reply from the USB device.') def runconsole(): """Run the usb console code @@ -280,7 +277,7 @@ def main(): stdin_isatty = sys.stdin.isatty() if stdin_isatty: fd = sys.stdin.fileno() - os.system("stty -echo") + os.system('stty -echo') old_settings = termios.tcgetattr(fd) try: @@ -288,7 +285,7 @@ def main(): finally: if stdin_isatty: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) - os.system("stty echo") + os.system('stty echo') # Avoid having the user's shell prompt start mid-line after the final output # from this program. print() |