From b659e0b7fdea0873c2ae364d280550bd6a91359e Mon Sep 17 00:00:00 2001 From: Nicolas Viennot Date: Sun, 12 May 2019 17:58:30 -0400 Subject: [PATCH] Make the MICROBIT volume detection more robust On MacOS, the volume names can have spaces (e.g., "MICROBIT 1") --- btlejack/__init__.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/btlejack/__init__.py b/btlejack/__init__.py index 292bdfb..14f14f2 100755 --- a/btlejack/__init__.py +++ b/btlejack/__init__.py @@ -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: