Removable drives with any name are now accepted by OSX

I have no idea why the old plugin only accepted drives with the name
"MASS STORAGE DEVICE", but it now simply lists all removable drives

CURA-1365
This commit is contained in:
Jaime van Kessel 2016-04-07 13:31:20 +02:00
parent b62c890bfa
commit 24950627dc

View File

@ -16,16 +16,19 @@ import plistlib
class OSXRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin): class OSXRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin):
def checkRemovableDrives(self): def checkRemovableDrives(self):
drives = {} drives = {}
p = subprocess.Popen(["system_profiler", "SPUSBDataType", "-xml"], stdout=subprocess.PIPE) p = subprocess.Popen(["system_profiler", "SPUSBDataType", "-xml"], stdout = subprocess.PIPE)
plist = plistlib.loads(p.communicate()[0]) plist = plistlib.loads(p.communicate()[0])
p.wait() p.wait()
for dev in self._findInTree(plist, "Mass Storage Device"): for entry in plist:
if "removable_media" in dev and dev["removable_media"] == "yes" and "volumes" in dev and len(dev["volumes"]) > 0: if "_items" in entry:
for vol in dev["volumes"]: for item in entry["_items"]:
if "mount_point" in vol: for dev in item["_items"]:
volume = vol["mount_point"] if "removable_media" in dev and dev["removable_media"] == "yes" and "volumes" in dev and len(dev["volumes"]) > 0:
drives[volume] = os.path.basename(volume) for vol in dev["volumes"]:
if "mount_point" in vol:
volume = vol["mount_point"]
drives[volume] = os.path.basename(volume)
p = subprocess.Popen(["system_profiler", "SPCardReaderDataType", "-xml"], stdout=subprocess.PIPE) p = subprocess.Popen(["system_profiler", "SPCardReaderDataType", "-xml"], stdout=subprocess.PIPE)
plist = plistlib.loads(p.communicate()[0]) plist = plistlib.loads(p.communicate()[0])
@ -51,16 +54,4 @@ class OSXRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin):
if return_code != 0: if return_code != 0:
return False return False
else: else:
return True return True
def _findInTree(self, t, n):
ret = []
if type(t) is dict:
if "_name" in t and t["_name"] == n:
ret.append(t)
for k, v in t.items():
ret += self._findInTree(v, n)
if type(t) is list:
for v in t:
ret += self._findInTree(v, n)
return ret