Skip to content

Commit 48504f7

Browse files
committed
list_ports: set default name attribute
See pyserial#262 Set the default `ListPortInfo.name` attribute from the full `device` name, using `os.path.basename(device)` This should be valid for all platforms, but can be easily overridden in platform specific code that populates the `ListPortInfo` object.
1 parent 797018b commit 48504f7

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

serial/tools/list_ports_common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import re
1111
import glob
1212
import os
13+
import os.path
1314

1415

1516
def numsplit(text):
@@ -33,7 +34,7 @@ class ListPortInfo(object):
3334

3435
def __init__(self, device=None):
3536
self.device = device
36-
self.name = None
37+
self.name = os.path.basename(device)
3738
self.description = 'n/a'
3839
self.hwid = 'n/a'
3940
# USB specific data

serial/tools/list_ports_linux.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def __init__(self, device):
2424
is_link = True
2525
else:
2626
is_link = False
27-
self.name = os.path.basename(device)
2827
self.usb_device_path = None
2928
if os.path.exists('/sys/class/tty/{}/device'.format(self.name)):
3029
self.device_path = os.path.realpath('/sys/class/tty/{}/device'.format(self.name))

0 commit comments

Comments
 (0)