Переглянути джерело

Auto-detect device in test_sink script

If there's a single PD Buddy Sink attached, it's pretty clear which one
we want to be testing.  As such, the testing script shouldn't require
the device to be specified if it can find exactly one Sink.  This commit
does just that, and like so, I will almost never have to figure out
which device file I need when testing a Sink again.
Clara Hobbs 6 роки тому
джерело
коміт
18dc3ae125
1 змінених файлів з 11 додано та 2 видалено
  1. 11
    2
      pdbuddy/tools/test_sink.py

+ 11
- 2
pdbuddy/tools/test_sink.py Переглянути файл

@@ -57,9 +57,18 @@ def main():
57 57
                     sinkinfo.product, sinkinfo.serial_number)
58 58
         sys.exit(0)
59 59
 
60
-    # If there's no device file specified, complain and exit
60
+    # If there's no device file specified, try to auto-detect
61 61
     if not args.tty:
62
-        parser.error('the following arguments are required: tty')
62
+        devices = list(pdbuddy.Sink.get_devices())
63
+        # If the wrong number of devices is present, complain and exit.
64
+        if len(devices) < 1:
65
+            print('No PD Buddy Sink devices found')
66
+            sys.exit(1)
67
+        elif len(devices) > 1:
68
+            print('Multiple PD Buddy Sink devices found')
69
+            sys.exit(1)
70
+        # Set args.tty to the auto-detected Sink
71
+        args.tty = devices[0].device
63 72
 
64 73
     # Define configurations for testing
65 74
     cfg_20v = pdbuddy.SinkConfig(status=pdbuddy.SinkStatus.VALID,

Завантаження…
Відмінити
Зберегти