Skip to content

Commit

Permalink
Make the MICROBIT volume detection more robust
Browse files Browse the repository at this point in the history
On MacOS, the volume names can have spaces (e.g., "MICROBIT 1")
  • Loading branch information
nviennot committed May 14, 2019
1 parent d05abdc commit b659e0b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions btlejack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,14 @@ def main():


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

0 comments on commit b659e0b

Please sign in to comment.