Sort serial ports naturally
This commit is contained in:
1 parent
60baf54d7b
commit
f9548a7ece
2 files changed
+8
-3
No files matched your search
@@ -24,7 +24,7 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms
|
||||
import re
|
||||
|
||||
from octoprint.settings import settings
|
||||
from octoprint.util import deprecated
|
||||
from octoprint.util import deprecated, natural_key
|
||||
from octoprint.filemanager import FileDestinations
|
||||
|
||||
|
||||
@@ -68,8 +68,8 @@ class PrinterInterface(object):
|
||||
"""
|
||||
import octoprint.util.comm as comm
|
||||
return {
|
||||
"ports": comm.serialList(),
|
||||
"baudrates": comm.baudrateList(),
|
||||
"ports": sorted(comm.serialList(), key=natural_key),
|
||||
"baudrates": sorted(comm.baudrateList(), reverse=True),
|
||||
"portPreference": settings().get(["serial", "port"]),
|
||||
"baudratePreference": settings().getInt(["serial", "baudrate"]),
|
||||
"autoconnect": settings().getBoolean(["serial", "autoconnect"])
|
||||
|
||||
@@ -1554,3 +1554,8 @@ class CaseInsensitiveSet(collections.Set):
|
||||
|
||||
def __len__(self):
|
||||
return len(self.data)
|
||||
|
||||
|
||||
# originally from https://stackoverflow.com/a/5967539
|
||||
def natural_key(text):
|
||||
return [ int(c) if c.isdigit() else c for c in re.split("(\d+)", text) ]
|
||||
Reference in new issue
Block a user