summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2011-08-25 08:32:54 +0000
committercliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2011-08-25 08:32:54 +0000
commit8f4f4836d11ef37e9071bc551faa69ad5c3f327f (patch)
treec2094497a33b4f59de8615b9bcb48680d48f3912
parentb148448c754ba5c9a8c56cbfb30e5e23d6b9e538 (diff)
downloadpyserial-8f4f4836d11ef37e9071bc551faa69ad5c3f327f.tar.gz
add more command line options to list_ports
git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk/pyserial@432 f19166aa-fa4f-0410-85c2-fa1106f25c8a
-rw-r--r--serial/tools/list_ports.py67
1 files changed, 53 insertions, 14 deletions
diff --git a/serial/tools/list_ports.py b/serial/tools/list_ports.py
index c652fef..52eb7a1 100644
--- a/serial/tools/list_ports.py
+++ b/serial/tools/list_ports.py
@@ -42,19 +42,58 @@ def grep(regexp):
if re.search(regexp, port, re.I) or re.search(regexp, desc) or re.search(regexp, hwid):
yield port, desc, hwid
-# test
-if __name__ == '__main__':
+
+def main():
+ import optparse
+
+ parser = optparse.OptionParser(
+ usage = "%prog [options] [<regexp>]",
+ description = "Miniterm - A simple terminal program for the serial port."
+ )
+
+ parser.add_option("--debug",
+ help="print debug messages and tracebacks (development mode)",
+ dest="debug",
+ default=False,
+ action='store_true')
+
+ parser.add_option("-v", "--verbose",
+ help="show more messages (can be given multiple times)",
+ dest="verbose",
+ default=1,
+ action='count')
+
+ parser.add_option("-q", "--quiet",
+ help="suppress all messages",
+ dest="verbose",
+ action='store_const',
+ const=0)
+
+ (options, args) = parser.parse_args()
+
+
hits = 0
- if len(sys.argv) > 1:
- print "Filtered list with regexp: %r" % (sys.argv[1],)
- for port, desc, hwid in sorted(grep(sys.argv[1])):
- print "%-20s: %s [%s]" % (port, desc, hwid)
- hits += 1
- else:
- for port, desc, hwid in sorted(comports()):
- print "%-20s: %s [%s]" % (port, desc, hwid)
- hits += 1
- if hits:
- print "%d ports found" % (hits,)
+ # get iteraror w/ or w/o filter
+ if args:
+ if len(args) > 1:
+ parser.error('more than one regexp not supported')
+ print "Filtered list with regexp: %r" % (args[0],)
+ iterator = sorted(grep(args[0]))
else:
- print "no ports found"
+ iterator = sorted(comports())
+ # list them
+ for port, desc, hwid in iterator:
+ print "%-20s" % (port,)
+ if options.verbose > 1:
+ print " desc: %s" % (desc,)
+ print " hwid: %s" % (hwid,)
+ hits += 1
+ if options.verbose:
+ if hits:
+ print "%d ports found" % (hits,)
+ else:
+ print "no ports found"
+
+# test
+if __name__ == '__main__':
+ main()