diff options
author | David Kiliani <mail@davidkiliani.de> | 2012-08-22 15:49:41 +0200 |
---|---|---|
committer | David Kiliani <mail@davidkiliani.de> | 2012-08-22 16:24:32 +0200 |
commit | 05acd08a66542888dfb0034abdeed5cd31d5664c (patch) | |
tree | fdc791c0f3cf305d24579cb654344df07a75d0a1 /support/scripts | |
parent | e34badc2102112fb4a42886d1b0e450320563d0d (diff) | |
download | librambutan-05acd08a66542888dfb0034abdeed5cd31d5664c.tar.gz librambutan-05acd08a66542888dfb0034abdeed5cd31d5664c.zip |
Improve Maple device detection in reset.py on Linux
Adds a function to lookup the USB vendor & product id from
the udev info in the sysfs tree. This removes invalid choices
and reduces user queries for the correct ttyACM device.
Signed-off-by: David Kiliani <mail@davidkiliani.de>
Diffstat (limited to 'support/scripts')
-rwxr-xr-x | support/scripts/reset.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/support/scripts/reset.py b/support/scripts/reset.py index 54a7aee..bfc91e1 100755 --- a/support/scripts/reset.py +++ b/support/scripts/reset.py @@ -11,13 +11,21 @@ from struct import pack def unix_get_maple_path(file_prefix): """Try to find the device file for the Maple on *nix; assuming - that it looks like /dev/<file_prefix>*. If there are multiple - possibilities, ask the user what to do. If the user chooses not - to say, returns None.""" + that it looks like /dev/<file_prefix>* and has the correct ID in + the /sys tree. If there are multiple possibilities, ask the user + what to do. If the user chooses not to say, returns None.""" possible_paths = [os.path.join('/dev', x) for x in os.listdir('/dev') \ - if x.startswith(file_prefix)] + if (x.startswith(file_prefix) and tty_is_maple(x))] return choose_path(possible_paths) +def tty_is_maple(device): + try: + sysfile = open("/sys/class/tty/%s/device/uevent" % device, "r") + text = "".join(sysfile.readlines()) + return "PRODUCT=1eaf/4" in text + except IOError: # no udev info available + return True + def windows_get_maple_path(): """Similar to unix_get_maple_path(), but on Windows.""" import _winreg as reg |