From bdafdde4e69c948d8a2149eebb73bd2dc01ecc6a Mon Sep 17 00:00:00 2001 From: renzo Date: Tue, 4 Sep 2018 22:50:23 +0200 Subject: [PATCH 1/2] call mount -l --- btlejack/__init__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/btlejack/__init__.py b/btlejack/__init__.py index 6f28b51..1f6ad93 100755 --- a/btlejack/__init__.py +++ b/btlejack/__init__.py @@ -179,13 +179,15 @@ def main(): if os.name == 'posix': - mount_output = check_output('mount').splitlines() - mounted_volumes = [x.split()[2] for x in mount_output] + mount_output = check_output(['mount', '-l']).splitlines() + mounted_volumes = [x.split() 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') + mount_point = volume[2] + device_name = volume[-1] + if re.match(b'.*MICROBIT[0-9]*', device_name): + print('[i] Flashing %s ...' % mount_point.decode('ascii')) + path = os.path.join(mount_point.decode('ascii'),'fw.hex') fw = open(fw_path,'r').read() # copy our firmware on it with open(path, 'wb') as output: From 45d817420b1650e7f806458f0e69284167aad7b1 Mon Sep 17 00:00:00 2001 From: renzo Date: Tue, 4 Sep 2018 23:11:06 +0200 Subject: [PATCH 2/2] use lsblk --- btlejack/__init__.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/btlejack/__init__.py b/btlejack/__init__.py index 1f6ad93..8c39b56 100755 --- a/btlejack/__init__.py +++ b/btlejack/__init__.py @@ -179,15 +179,14 @@ def main(): if os.name == 'posix': - mount_output = check_output(['mount', '-l']).splitlines() - mounted_volumes = [x.split() for x in mount_output] + lsblk_output = check_output(['lsblk', '-n', '-P', '-o', 'NAME,MOUNTPOINT,LABEL']) flashed = 0 - for volume in mounted_volumes: - mount_point = volume[2] - device_name = volume[-1] - if re.match(b'.*MICROBIT[0-9]*', device_name): - print('[i] Flashing %s ...' % mount_point.decode('ascii')) - path = os.path.join(mount_point.decode('ascii'),'fw.hex') + for volume_line in lsblk_output.splitlines(): + result = re.match(r'NAME="(.+)" MOUNTPOINT="(.+)" LABEL=".*MICROBIT[0-9]*"', volume_line.decode('ascii')) + if result: + mount_point = result.group(2) + print('[i] Flashing %s ...' % mount_point) + path = os.path.join(mount_point, 'fw.hex') fw = open(fw_path,'r').read() # copy our firmware on it with open(path, 'wb') as output: