mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 14:37:29 -06:00
Add RemovableDrive plugin that has been moved from Uranium
Since it now depends on GCodeWriter we should put it somewhere where GCodeWriter actually exists.
This commit is contained in:
parent
3e024e1618
commit
825349b47b
6 changed files with 395 additions and 0 deletions
|
@ -0,0 +1,64 @@
|
|||
# Copyright (c) 2015 Ultimaker B.V.
|
||||
# Copyright (c) 2013 David Braam
|
||||
# Uranium is released under the terms of the AGPLv3 or higher.
|
||||
|
||||
from . import RemovableDrivePlugin
|
||||
|
||||
import threading
|
||||
|
||||
import subprocess
|
||||
import time
|
||||
import os
|
||||
|
||||
import plistlib
|
||||
|
||||
## Support for removable devices on Mac OSX
|
||||
class OSXRemovableDrives(RemovableDrivePlugin.RemovableDrivePlugin):
|
||||
def run(self):
|
||||
drives = {}
|
||||
p = subprocess.Popen(["system_profiler", "SPUSBDataType", "-xml"], stdout=subprocess.PIPE)
|
||||
plist = plistlib.loads(p.communicate()[0])
|
||||
p.wait()
|
||||
|
||||
for dev in self._findInTree(plist, "Mass Storage Device"):
|
||||
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)
|
||||
plist = plistlib.loads(p.communicate()[0])
|
||||
p.wait()
|
||||
|
||||
for entry in plist:
|
||||
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)
|
||||
|
||||
def performEjectDevice(self, device):
|
||||
p = subprocess.Popen(["diskutil", "eject", path], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
output = p.communicate()
|
||||
|
||||
return_code = p.wait()
|
||||
if return_code != 0:
|
||||
return False
|
||||
else:
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue