[chirp_devel] [PATCH] The sort order of discovered ports is annoying. Fixes #4461

Aaron Pelly
Wed Jan 25 15:38:06 PST 2017


# HG changeset patch
# User Aaron Pelly <aaron at pelly.co>
# Date 1485386832 -46800
#      Thu Jan 26 12:27:12 2017 +1300
# Node ID fc0266dc222404c620bea773a97b89a8651d553c
# Parent  3923a6bd67dec42839192ded5d2ee76ae1d32bec
The sort order of discovered ports is annoying. Fixes #4461

diff -r 3923a6bd67de -r fc0266dc2224 chirp/platform.py
--- a/chirp/platform.py	Tue Jan 10 17:17:02 2017 +1300
+++ b/chirp/platform.py	Thu Jan 26 12:27:12 2017 +1300
@@ -299,16 +299,28 @@
         os.system("firefox '%s'" % path)
 
     def list_serial_ports(self):
-        ports = ["/dev/ttyS*",
+        """Return a list of OS files matching known patterns.
+
+        Each pattern is expanded and sorted, then appended
+        to the result. The primary point being to show ttyUSB*
+        before the huge list of ttyS*
+        """
+        ports = [
+                 "/dev/ttyACM*",
+                 "/dev/ttyAMA*",
+                 "/dev/cu.*",
+                 "/dev/cua0*",
+                 "/dev/cuaU*",
+                 "/dev/term/*",
+                 "/dev/tty.KeySerial*",
                  "/dev/ttyUSB*",
-                 "/dev/ttyAMA*",
-                 "/dev/ttyACM*",
-                 "/dev/cu.*",
-                 "/dev/cuaU*",
-                 "/dev/cua0*",
-                 "/dev/term/*",
-                 "/dev/tty.KeySerial*"]
-        return natural_sorted(sum([glob.glob(x) for x in ports], []))
+                 "/dev/ttyS*"]
+
+        available_ports = []
+        for port_pattern in ports:
+            for port in natural_sorted(glob.glob(port_pattern)):
+                available_ports.append(port)
+        return available_ports
 
     def os_version_string(self):
         try:



More information about the chirp_devel mailing list