mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 14:37:29 -06:00
Update OSX removable drive code to handle 10.12 plist format
Fixes CURA-2618
This commit is contained in:
parent
d3f58a049b
commit
ae389742ff
1 changed files with 41 additions and 22 deletions
|
@ -17,41 +17,60 @@ class OSXRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin):
|
||||||
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()
|
|
||||||
|
|
||||||
for entry in plist:
|
result = self._recursiveSearch(plist, "removable_media")
|
||||||
if "_items" in entry:
|
|
||||||
for item in entry["_items"]:
|
|
||||||
for dev in item["_items"]:
|
|
||||||
if "removable_media" in dev and dev["removable_media"] == "yes" and "volumes" in dev and len(dev["volumes"]) > 0:
|
|
||||||
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])
|
||||||
p.wait()
|
|
||||||
|
|
||||||
for entry in plist:
|
result.extend(self._recursiveSearch(plist, "removable_media"))
|
||||||
if "_items" in entry:
|
|
||||||
for item in entry["_items"]:
|
for drive in result:
|
||||||
for dev in item["_items"]:
|
# Ignore everything not explicitly marked as removable
|
||||||
if "removable_media" in dev and dev["removable_media"] == "yes" and "volumes" in dev and len(dev["volumes"]) > 0:
|
if drive["removable_media"] != "yes":
|
||||||
for vol in dev["volumes"]:
|
continue
|
||||||
if "mount_point" in vol:
|
|
||||||
volume = vol["mount_point"]
|
# Ignore any removable device that does not have an actual volume
|
||||||
drives[volume] = os.path.basename(volume)
|
if "volumes" not in drive or not drive["volumes"]:
|
||||||
|
continue
|
||||||
|
|
||||||
|
for volume in drive["volumes"]:
|
||||||
|
if not "mount_point" in volume:
|
||||||
|
continue
|
||||||
|
|
||||||
|
mount_point = volume["mount_point"]
|
||||||
|
|
||||||
|
if "_name" in volume:
|
||||||
|
drive_name = volume["_name"]
|
||||||
|
else:
|
||||||
|
drive_name = os.path.basename(mount_point)
|
||||||
|
|
||||||
|
drives[mount_point] = drive_name
|
||||||
|
|
||||||
return drives
|
return drives
|
||||||
|
|
||||||
def performEjectDevice(self, device):
|
def performEjectDevice(self, device):
|
||||||
p = subprocess.Popen(["diskutil", "eject", device.getId()], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
|
p = subprocess.Popen(["diskutil", "eject", device.getId()], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
|
||||||
output = p.communicate()
|
output = p.communicate()
|
||||||
Logger.log("d", "umount returned: %s.", repr(output))
|
|
||||||
|
|
||||||
return_code = p.wait()
|
return_code = p.wait()
|
||||||
if return_code != 0:
|
if return_code != 0:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# Recursively search for key in a plist parsed by plistlib
|
||||||
|
def _recursiveSearch(self, plist, key):
|
||||||
|
result = []
|
||||||
|
for entry in plist:
|
||||||
|
if key in entry:
|
||||||
|
result.append(entry)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if "_items" in entry:
|
||||||
|
result.extend(self._recursiveSearch(entry["_items"], key))
|
||||||
|
|
||||||
|
if "Media" in entry:
|
||||||
|
result.extend(self._recursiveSearch(entry["Media"], key))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue