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,41 @@
|
|||
# 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 glob
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
## Support for removable devices on Linux.
|
||||
#
|
||||
# TODO: This code uses the most basic interfaces for handling this.
|
||||
# We should instead use UDisks2 to handle mount/unmount and hotplugging events.
|
||||
#
|
||||
class LinuxRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin):
|
||||
def checkRemovableDrives(self):
|
||||
drives = {}
|
||||
for volume in glob.glob("/media/*"):
|
||||
if os.path.ismount(volume):
|
||||
drives[volume] = os.path.basename(volume)
|
||||
elif volume == "/media/"+os.getenv("USER"):
|
||||
for volume in glob.glob("/media/"+os.getenv("USER")+"/*"):
|
||||
if os.path.ismount(volume):
|
||||
drives[volume] = os.path.basename(volume)
|
||||
|
||||
for volume in glob.glob("/run/media/" + os.getenv("USER") + "/*"):
|
||||
if os.path.ismount(volume):
|
||||
drives[volume] = os.path.basename(volume)
|
||||
|
||||
return drives
|
||||
|
||||
def performEjectDevice(self, device):
|
||||
p = subprocess.Popen(["umount", device.getId()], 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
|
Loading…
Add table
Add a link
Reference in a new issue