summaryrefslogtreecommitdiff
path: root/serial/tools/list_ports_linux.py
diff options
context:
space:
mode:
Diffstat (limited to 'serial/tools/list_ports_linux.py')
-rw-r--r--serial/tools/list_ports_linux.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/serial/tools/list_ports_linux.py b/serial/tools/list_ports_linux.py
index f7491e5..3e37d72 100644
--- a/serial/tools/list_ports_linux.py
+++ b/serial/tools/list_ports_linux.py
@@ -15,7 +15,7 @@ import glob
import os
import re
import subprocess
-import sys
+
def read_command(argv):
"""run a command and return its output"""
@@ -24,6 +24,7 @@ def read_command(argv):
except subprocess.SubprocessError as e:
raise IOError('command %r failed: %s' % (argv, e))
+
def read_line(*args):
"""\
Helper function to read a single line from a file.
@@ -37,6 +38,7 @@ def read_line(*args):
except IOError:
return None
+
def re_group(regexp, text):
"""search for regexp in text, return 1st group on match"""
m = re.search(regexp, text)
@@ -63,6 +65,7 @@ def usb_sysfs_hw_string(sysfs_path):
snr_txt
)
+
def usb_lsusb_string(sysfs_path):
base = os.path.basename(os.path.realpath(sysfs_path))
bus = base.split('-')[0]
@@ -82,6 +85,7 @@ def usb_lsusb_string(sysfs_path):
# create descriptions. prefer text from device, fall back to the others
return '%s %s %s' % (iManufacturer or idVendor, iProduct or idProduct, iSerial)
+
def describe(device):
"""\
Get a human readable description.
@@ -106,6 +110,7 @@ def describe(device):
return read_line(product_name_file)
return base
+
def hwinfo(device):
"""Try to get a HW identification using sysfs"""
base = os.path.basename(device)
@@ -126,6 +131,7 @@ def hwinfo(device):
return usb_sysfs_hw_string(sys_dev_path + '/..')
return 'n/a' # XXX directly remove these from the list?
+
def comports():
devices = glob.glob('/dev/ttyS*') # built-in serial ports
devices.extend(glob.glob('/dev/ttyUSB*')) # usb-serial with own driver
@@ -138,4 +144,3 @@ def comports():
if __name__ == '__main__':
for port, desc, hwid in sorted(comports()):
print("%s: %s [%s]" % (port, desc, hwid))
-