diff options
Diffstat (limited to 'serial/tools/list_ports.py')
-rw-r--r-- | serial/tools/list_ports.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/serial/tools/list_ports.py b/serial/tools/list_ports.py index 2271dd1..0d7e3d4 100644 --- a/serial/tools/list_ports.py +++ b/serial/tools/list_ports.py @@ -16,6 +16,8 @@ Additionally a grep function is supplied that can be used to search for ports based on their descriptions or hardware ID. """ +from __future__ import absolute_import + import sys import os import re @@ -34,14 +36,14 @@ else: # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -def grep(regexp): +def grep(regexp, include_links=False): """\ Search for ports using a regular expression. Port name, description and hardware ID are searched. The function returns an iterable that returns the same tuples as comport() would do. """ r = re.compile(regexp, re.I) - for info in comports(): + for info in comports(include_links): port, desc, hwid = info if r.search(port) or r.search(desc) or r.search(hwid): yield info @@ -73,6 +75,11 @@ def main(): type=int, help='only output the N-th entry') + parser.add_argument( + '-s', '--include-links', + action='store_true', + help='include entries that are symlinks to real devices') + args = parser.parse_args() hits = 0 @@ -80,9 +87,9 @@ def main(): if args.regexp: if not args.quiet: sys.stderr.write("Filtered list with regexp: {!r}\n".format(args.regexp)) - iterator = sorted(grep(args.regexp)) + iterator = sorted(grep(args.regexp, include_links=args.include_links)) else: - iterator = sorted(comports()) + iterator = sorted(comports(include_links=args.include_links)) # list them for n, (port, desc, hwid) in enumerate(iterator, 1): if args.n is None or args.n == n: |