aboutsummaryrefslogtreecommitdiffstats
path: root/mpm/python/usrp_mpm/periph_manager/udev.py
diff options
context:
space:
mode:
authorMartin Braun <martin.braun@ettus.com>2017-05-31 21:58:45 -0700
committerMartin Braun <martin.braun@ettus.com>2017-12-22 15:03:58 -0800
commit3c50e39d644767ea3f668bbf2146ea4c636ce8e2 (patch)
treeb0056aea97ab0a2452692603987ac83d8cf9fed0 /mpm/python/usrp_mpm/periph_manager/udev.py
parentcd533c8080287f8558cdb283d28ad00661c1a164 (diff)
downloaduhd-3c50e39d644767ea3f668bbf2146ea4c636ce8e2.tar.gz
uhd-3c50e39d644767ea3f668bbf2146ea4c636ce8e2.tar.bz2
uhd-3c50e39d644767ea3f668bbf2146ea4c636ce8e2.zip
mpm: Removed gratuitous encode(), safer udev lookups
- Udev lookups now just return empty lists when they can't find anything - Made SPI dev interface factory Py2/3 safe
Diffstat (limited to 'mpm/python/usrp_mpm/periph_manager/udev.py')
-rw-r--r--mpm/python/usrp_mpm/periph_manager/udev.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/mpm/python/usrp_mpm/periph_manager/udev.py b/mpm/python/usrp_mpm/periph_manager/udev.py
index cb3b35a66..33cb3367a 100644
--- a/mpm/python/usrp_mpm/periph_manager/udev.py
+++ b/mpm/python/usrp_mpm/periph_manager/udev.py
@@ -21,27 +21,32 @@ from ..mpmlog import get_logger
def get_eeprom_paths(address):
"""
- Return EEPROM device paths for a given I2C address
+ Return list of EEPROM device paths for a given I2C address.
+ If no device paths are found, an empty list is returned.
"""
context = pyudev.Context()
parent = pyudev.Device.from_name(context, "platform", address)
paths = [d.device_node if d.device_node is not None else d.sys_path
for d in context.list_devices(parent=parent, subsystem="nvmem")]
+ if len(paths) == 0:
+ return []
# We need to sort this so 9-0050 comes before 10-0050 (etc.)
maxlen = max((len(os.path.split(p)[1]) for p in paths))
paths = sorted(
paths,
key=lambda x: "{:>0{maxlen}}".format(os.path.split(x)[1], maxlen=maxlen)
)
- return [os.path.join(x.encode('ascii'), 'nvmem') for x in paths]
+ return [os.path.join(x, 'nvmem') for x in paths]
def get_spidev_nodes(spi_master):
"""
- Return found spidev device paths for a given SPI master
+ Return list of spidev device paths for a given SPI master. If no valid paths
+ can be found, an empty list is returned.
"""
context = pyudev.Context()
parent = pyudev.Device.from_name(context, "platform", spi_master)
- paths = [device.device_node.encode('ascii')
- for device in context.list_devices(parent=parent, subsystem="spidev")]
- return paths
+ return [
+ device.device_node
+ for device in context.list_devices(parent=parent, subsystem="spidev")
+ ]