Improve fetching logical disks

This commit is contained in:
Ivan Kravets
2017-08-14 15:27:12 +03:00
parent 4a7cd5be6a
commit d7d66fd4a6

View File

@ -429,19 +429,29 @@ def get_serialports(filter_hwid=False):
def get_logicaldisks(): def get_logicaldisks():
disks = [] disks = []
if platform.system() == "Windows": if platform.system() == "Windows":
result = exec_command( try:
["wmic", "logicaldisk", "get", "name,VolumeName"]).get("out", "") result = exec_command(
disknamere = re.compile(r"^([A-Z]{1}\:)\s*(\S+)?") ["wmic", "logicaldisk", "get", "name,VolumeName"]).get(
for line in result.split("\n"): "out", "")
match = disknamere.match(line.strip()) disknamere = re.compile(r"^([A-Z]{1}\:)\s*(\S+)?")
if not match: for line in result.split("\n"):
continue match = disknamere.match(line.strip())
disks.append({"disk": match.group(1), "name": match.group(2)}) if not match:
continue
disks.append({"disk": match.group(1), "name": match.group(2)})
return disks
except WindowsError: # pylint: disable=undefined-variable
pass
# try "fsutil"
result = exec_command(["fsutil", "fsinfo", "drives"]).get("out", "")
for disk in re.findall(r"[A-Z]:\\", result):
disks.append({"disk": disk[:-1], "name": disk})
return disks
else: else:
result = exec_command(["df"]).get("out") result = exec_command(["df"]).get("out")
disknamere = re.compile(r"\d+\%\s+([a-z\d\-_/]+)$", flags=re.I) disknamere = re.compile(r"^/.+\d+\%\s+([a-z\d\-_/]+)$", flags=re.I)
for line in result.split("\n"): for line in result.split("\n"):
match = disknamere.search(line.strip()) match = disknamere.match(line.strip())
if not match: if not match:
continue continue
disks.append({ disks.append({