Skip to content

Commit b659e0b

Browse files
committed
Make the MICROBIT volume detection more robust
On MacOS, the volume names can have spaces (e.g., "MICROBIT 1")
1 parent d05abdc commit b659e0b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

btlejack/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,14 @@ def main():
191191

192192

193193
if os.name == 'posix':
194-
mount_output = check_output('mount').splitlines()
195-
mounted_volumes = [x.split()[2] for x in mount_output]
196194
flashed = 0
197-
for volume in mounted_volumes:
198-
if re.match(b'.*MICROBIT[0-9]*$', volume):
199-
print('[i] Flashing %s ...' % volume.decode('ascii'))
200-
path = os.path.join(volume.decode('ascii'),'fw.hex')
195+
for line in check_output('mount').splitlines():
196+
line = line.decode('ascii')
197+
match = re.match(r'^\S+ on (.*MICROBIT(\s?[0-9]+)?)', line)
198+
if match:
199+
volume = match.group(1)
200+
print('[i] Flashing %s ...' % volume)
201+
path = os.path.join(volume,'fw.hex')
201202
fw = open(fw_path,'r').read()
202203
# copy our firmware on it
203204
with open(path, 'wb') as output:

0 commit comments

Comments
 (0)