Skip to content

Commit 695d8c8

Browse files
committed
Merge pull request #35 from ARMmbed/devel_mount_name
Extended mount point naming convention
2 parents a56090b + 9912959 commit 695d8c8

File tree

2 files changed

+91
-32
lines changed

2 files changed

+91
-32
lines changed

mbed_lstools/lstools_linux_generic.py

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class MbedLsToolsLinuxGeneric(MbedLsToolsBase):
2525
""" MbedLsToolsLinuxGeneric supports mbed-enabled platforms detection across Linux family
2626
"""
2727
def __init__(self):
28-
""" ctor
28+
"""! ctor
2929
"""
3030
MbedLsToolsBase.__init__(self)
3131
self.os_supported.append('LinuxGeneric')
@@ -35,11 +35,8 @@ def __init__(self):
3535

3636
def list_mbeds(self):
3737
"""! Returns detailed list of connected mbeds
38-
3938
@return Returns list of structures with detailed info about each mbed
40-
4139
@details Function returns list of dictionaries with mbed attributes such as mount point, TargetID name etc.
42-
4340
Function returns mbed list with platform names if possible
4441
all_devices =
4542
[
@@ -122,9 +119,7 @@ def list_mbeds(self):
122119

123120
def get_dev_by_id(self, subdir):
124121
"""! Lists disk devices by id
125-
126122
@return List of strings from 'ls' command executed in shell
127-
128123
@details Uses Linux shell command: 'ls -oA /dev/disk/by-id/'
129124
"""
130125
result = []
@@ -143,9 +138,7 @@ def get_dev_by_id(self, subdir):
143138

144139
def get_mounts(self):
145140
"""! Lists mounted devices with vfat file system (potential mbeds)
146-
147141
@result Returns list of all mounted vfat devices
148-
149142
@details Uses Linux shell command: 'mount | grep vfat'
150143
"""
151144
result = []
@@ -164,11 +157,8 @@ def get_mounts(self):
164157

165158
def get_disk_hex_ids(self, disk_list):
166159
"""! Get only hexadecimal IDs for mbed disks
167-
168160
@param disk_list List of disks in a system with USBID decoration
169-
170161
@return Returns map of disks and corresponding disks' Hex ids
171-
172162
@details Uses regular expressions to get Hex strings (TargeTIDs) from list of disks
173163
"""
174164
nlp = re.compile(self.name_link_pattern)
@@ -185,12 +175,9 @@ def get_disk_hex_ids(self, disk_list):
185175

186176
def get_mbed_serial(self, serial_list, dhi):
187177
"""! Get mbed serial by unique hex id (dhi) in disk name
188-
189-
@return Returns None if corresponding serial device is not found, else returns serial device path
190-
191178
@param serial_list List of all serial ports
192179
@param dhi Unique Hex id of possible mbed device
193-
180+
@return Returns None if corresponding serial device is not found, else returns serial device path
194181
@details Devices are located in Linux '/dev/' directory structure
195182
"""
196183
nlp = re.compile(self.name_link_pattern)
@@ -205,14 +192,11 @@ def get_mbed_serial(self, serial_list, dhi):
205192

206193
def get_detected(self, tids, disk_list, serial_list, mount_list):
207194
"""! Find all known mbed devices and assign name by targetID
208-
209-
@return list of lists [mbed_name, mbed_dev_disk, mbed_mount_point, mbed_dev_serial, disk_hex_id]
210-
211195
@param tids TargetID comprehensive list for detection (manufacturers_ids)
212196
@param disk_list List of disks (mount points in /dev/disk)
213197
@param serial_list List of serial devices (serial ports in /dev/serial)
214198
@param mount_list List of lines from 'mount' command
215-
199+
@return list of lists [mbed_name, mbed_dev_disk, mbed_mount_point, mbed_dev_serial, disk_hex_id]
216200
@details Find for all disk connected all MBED ones we know about from TID list
217201
"""
218202
# Find for all disk connected all MBED ones we know about from TID list
@@ -241,14 +225,11 @@ def get_detected(self, tids, disk_list, serial_list, mount_list):
241225

242226
def get_not_detected(self, tids, disk_list, serial_list, mount_list):
243227
"""! Find all unknown mbed-enabled devices (may have 'mbed' string in USBID name)
244-
245-
@return list of lists [mbed_name, mbed_dev_disk, mbed_mount_point, mbed_dev_serial, disk_hex_id]
246-
247228
@param tids TargetID comprehensive list for detection (manufacturers_ids)
248229
@param disk_list List of disks (mount points in /dev/disk)
249230
@param serial_list List of serial devices (serial ports in /dev/serial)
250231
@param mount_list List of lines from 'mount' command
251-
232+
@return list of lists [mbed_name, mbed_dev_disk, mbed_mount_point, mbed_dev_serial, disk_hex_id]
252233
@details Find for all disk connected all MBED ones we know about from TID list
253234
"""
254235
map_tid_to_mbed = self.get_tid_mbed_name_remap(tids)
@@ -279,12 +260,12 @@ def get_not_detected(self, tids, disk_list, serial_list, mount_list):
279260
return result
280261

281262
def get_tid_mbed_name_remap(self, tids):
282-
""" Remap to get mapping: ID -> mbed name
263+
"""! Remap to get mapping: ID -> mbed name
283264
"""
284265
return tids
285266

286267
def get_dev_name(self, link):
287-
""" Get device name from symbolic link list
268+
"""! Get device name from symbolic link list
288269
"""
289270
device_sufix_pattern = ".*/([a-zA-Z0-9]*)$"
290271
dsp = re.compile(device_sufix_pattern)
@@ -293,16 +274,16 @@ def get_dev_name(self, link):
293274
return mbed_dev
294275

295276
def get_mount_point(self, dev_name, mount_list):
296-
""" Find mount points for MBED devices using mount command output
297-
298-
@return Returns None if mount point not found. Else returns device mount path
299-
277+
"""! Find mount points for MBED devices using mount command output
300278
@param dev_name Device name (e.g 'sda')
301279
@param mount_list List of all mounted devices (strings from Linux mount shell command)
302-
303-
@details
280+
@return Returns None if mount point not found. Else returns device mount path
281+
@details We want to scan names of mount points like this:
282+
/media/MBED_xxx
283+
/media/MBED__xxx
284+
/media/MBED-xxx
304285
"""
305-
mount_media_pattern = "^/[a-zA-Z0-9/]*/" + dev_name + " on (/[a-zA-Z0-9/]*) "
286+
mount_media_pattern = "^/[a-zA-Z0-9/]*/" + dev_name + " on (/[a-zA-Z0-9_\-/]*) "
306287
mmp = re.compile(mount_media_pattern)
307288
for mount in mount_list:
308289
m = mmp.search(mount)

test/os_linux_generic.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env python
2+
"""
3+
mbed SDK
4+
Copyright (c) 2011-2015 ARM Limited
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
"""
18+
19+
import unittest
20+
import os
21+
import errno
22+
import logging
23+
from mbed_lstools.lstools_linux_generic import MbedLsToolsLinuxGeneric
24+
25+
26+
27+
class BasicTestCase(unittest.TestCase):
28+
""" Basic test cases checking trivial asserts
29+
"""
30+
31+
def setUp(self):
32+
self.linux_generic = MbedLsToolsLinuxGeneric()
33+
34+
self.vfat_devices = [
35+
"/dev/sdb on /media/usb0 type vfat (rw,noexec,nodev,sync,noatime,nodiratime,gid=1000,uid=1000,dmask=000,fmask=000)",
36+
"/dev/sdd on /media/usb2 type vfat (rw,noexec,nodev,sync,noatime,nodiratime,gid=1000,uid=1000,dmask=000,fmask=000)",
37+
"/dev/sde on /media/usb3 type vfat (rw,noexec,nodev,sync,noatime,nodiratime,gid=1000,uid=1000,dmask=000,fmask=000)",
38+
"/dev/sdc on /media/usb1 type vfat (rw,noexec,nodev,sync,noatime,nodiratime,gid=1000,uid=1000,dmask=000,fmask=000)"
39+
]
40+
41+
self.vfat_devices_ext = [
42+
"/dev/sdb on /media/MBED_xxx type vfat (rw,noexec,nodev,sync,noatime,nodiratime,gid=1000,uid=1000,dmask=000,fmask=000)",
43+
"/dev/sdd on /media/MBED___x type vfat (rw,noexec,nodev,sync,noatime,nodiratime,gid=1000,uid=1000,dmask=000,fmask=000)",
44+
"/dev/sde on /media/MBED-xxx type vfat (rw,noexec,nodev,sync,noatime,nodiratime,gid=1000,uid=1000,dmask=000,fmask=000)",
45+
"/dev/sdc on /media/MBED_x-x type vfat (rw,noexec,nodev,sync,noatime,nodiratime,gid=1000,uid=1000,dmask=000,fmask=000)"
46+
]
47+
48+
def tearDown(self):
49+
pass
50+
51+
def test_example(self):
52+
self.assertEqual(True, True)
53+
self.assertNotEqual(True, False)
54+
55+
def test_get_mount_point_basic(self):
56+
self.assertEqual('/media/usb0', self.linux_generic.get_mount_point('sdb', self.vfat_devices))
57+
self.assertEqual('/media/usb2', self.linux_generic.get_mount_point('sdd', self.vfat_devices))
58+
self.assertEqual('/media/usb3', self.linux_generic.get_mount_point('sde', self.vfat_devices))
59+
self.assertEqual('/media/usb1', self.linux_generic.get_mount_point('sdc', self.vfat_devices))
60+
61+
def test_get_mount_point_ext(self):
62+
self.assertEqual('/media/MBED_xxx', self.linux_generic.get_mount_point('sdb', self.vfat_devices_ext))
63+
self.assertEqual('/media/MBED___x', self.linux_generic.get_mount_point('sdd', self.vfat_devices_ext))
64+
self.assertEqual('/media/MBED-xxx', self.linux_generic.get_mount_point('sde', self.vfat_devices_ext))
65+
self.assertEqual('/media/MBED_x-x', self.linux_generic.get_mount_point('sdc', self.vfat_devices_ext))
66+
67+
def test_get_dev_name(self):
68+
self.assertEqual('ttyACM0', self.linux_generic.get_dev_name('usb-MBED_MBED_CMSIS-DAP_02400201489A1E6CB564E3D4-if01 -> ../../ttyACM0'))
69+
self.assertEqual('ttyACM2', self.linux_generic.get_dev_name('usb-STMicroelectronics_STM32_STLink_0672FF485649785087171742-if02 -> ../../ttyACM2'))
70+
self.assertEqual('ttyACM3', self.linux_generic.get_dev_name('usb-MBED_MBED_CMSIS-DAP_0240020152986E5EAF6693E6-if01 -> ../../ttyACM3'))
71+
self.assertEqual('ttyACM2', self.linux_generic.get_dev_name('/dev/ttyACM2'))
72+
self.assertEqual('sdb', self.linux_generic.get_dev_name('usb-MBED_microcontroller_02400201489A1E6CB564E3D4-0:0 -> ../../sdb'))
73+
self.assertEqual('sde', self.linux_generic.get_dev_name('usb-MBED_microcontroller_0240020152986E5EAF6693E6-0:0 -> ../../sde'))
74+
self.assertEqual('sdd', self.linux_generic.get_dev_name('usb-MBED_microcontroller_0672FF485649785087171742-0:0 -> ../../sdd'))
75+
76+
77+
if __name__ == '__main__':
78+
unittest.main()

0 commit comments

Comments
 (0)