Skip to content

Commit c307720

Browse files
committed
Refactoring of regex compile calls
1 parent 11e6a49 commit c307720

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

mbed_lstools/lstools_linux_generic.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ def __init__(self):
3333
self.name_link_pattern = "(usb-[0-9a-zA-Z_-]*_[0-9a-zA-Z]*-.*$)"
3434
self.mount_media_pattern = "^/[a-zA-Z0-9/]* on (/[a-zA-Z0-9/]*) "
3535

36+
self.nlp = re.compile(self.name_link_pattern)
37+
self.hup = re.compile(self.hex_uuid_pattern)
38+
3639
def list_mbeds(self):
3740
"""! Returns detailed list of connected mbeds
3841
@return Returns list of structures with detailed info about each mbed
@@ -174,14 +177,12 @@ def get_disk_hex_ids(self, disk_list):
174177
@return Returns map of disks and corresponding disks' Hex ids
175178
@details Uses regular expressions to get Hex strings (TargeTIDs) from list of disks
176179
"""
177-
nlp = re.compile(self.name_link_pattern)
178-
hup = re.compile(self.hex_uuid_pattern)
179180
disk_hex_ids = {}
180181
for dl in disk_list:
181-
m = nlp.search(dl)
182+
m = self.nlp.search(dl)
182183
if m and len(m.groups()):
183184
disk_link = m.group(1)
184-
m = hup.search(disk_link)
185+
m = self.hup.search(disk_link)
185186
if m and len(m.groups()):
186187
disk_hex_ids[m.group(1)] = disk_link
187188
return disk_hex_ids
@@ -193,10 +194,9 @@ def get_mbed_serial(self, serial_list, dhi):
193194
@return Returns None if corresponding serial device is not found, else returns serial device path
194195
@details Devices are located in Linux '/dev/' directory structure
195196
"""
196-
nlp = re.compile(self.name_link_pattern)
197197
for sl in serial_list:
198198
if dhi in sl:
199-
m = nlp.search(sl)
199+
m = self.nlp.search(sl)
200200
if m and len(m.groups()):
201201
serial_link = m.group(1)
202202
mbed_dev_serial = "/dev/" + self.get_dev_name(serial_link)

0 commit comments

Comments
 (0)