summaryrefslogtreecommitdiff
path: root/serial/tools/list_ports.py
diff options
context:
space:
mode:
authorNJDFan <rob.gaddi@gmail.com>2019-06-20 16:04:55 -0700
committerGitHub <noreply@github.com>2019-06-20 16:04:55 -0700
commit3215eb3088a4ca55c5217c2e99da5584c3ee02c1 (patch)
treec64894a3b91f219add4a296db8376d9b3b9bdcef /serial/tools/list_ports.py
parent5c021d4bdab2297602b4459f75bef2e00e5ec9ab (diff)
parentacab9d2c0efb63323faebfd5e3405d77cd4b5617 (diff)
downloadpyserial-git-3215eb3088a4ca55c5217c2e99da5584c3ee02c1.tar.gz
Merge pull request #1 from pyserial/master
Catch up to the main fork
Diffstat (limited to 'serial/tools/list_ports.py')
-rw-r--r--serial/tools/list_ports.py15
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: