diff options
Diffstat (limited to 'util/uf2conv.py')
| -rwxr-xr-x | util/uf2conv.py | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/util/uf2conv.py b/util/uf2conv.py index 67cf92f169..a0507b00b9 100755 --- a/util/uf2conv.py +++ b/util/uf2conv.py @@ -142,9 +142,9 @@ def convert_to_uf2(file_content): return b"".join(outp) class Block: - def __init__(self, addr): + def __init__(self, addr, default_data=0xFF): self.addr = addr - self.bytes = bytearray(256) + self.bytes = bytearray([default_data] * 256) def encode(self, blockno, numblocks): global familyid @@ -210,24 +210,26 @@ def to_str(b): def get_drives(): drives = [] if sys.platform == "win32": - r = subprocess.check_output(["wmic", "PATH", "Win32_LogicalDisk", - "get", "DeviceID,", "VolumeName,", - "FileSystem,", "DriveType"]) - for line in to_str(r).split('\n'): - words = re.split(r'\s+', line) - if len(words) >= 3 and words[1] == "2" and words[2] == "FAT": - drives.append(words[0]) + r = subprocess.check_output([ + "powershell", + "-Command", + '(Get-WmiObject Win32_LogicalDisk -Filter "FileSystem=\'FAT\'").DeviceID' + ]) + drives = [drive.strip() for drive in to_str(r).splitlines()] else: - searchpaths = ["/media"] + searchpaths = ["/mnt", "/media"] if sys.platform == "darwin": searchpaths = ["/Volumes"] elif sys.platform == "linux": - searchpaths += ["/media/" + os.environ["USER"], '/run/media/' + os.environ["USER"]] + searchpaths += ["/media/" + os.environ["USER"], "/run/media/" + os.environ["USER"]] + if "SUDO_USER" in os.environ.keys(): + searchpaths += ["/media/" + os.environ["SUDO_USER"]] + searchpaths += ["/run/media/" + os.environ["SUDO_USER"]] for rootpath in searchpaths: if os.path.isdir(rootpath): for d in os.listdir(rootpath): - if os.path.isdir(rootpath): + if os.path.isdir(os.path.join(rootpath, d)): drives.append(os.path.join(rootpath, d)) |