Welcome to mirror list, hosted at ThFree Co, Russian Federation.

LinuxRemovableDrivePlugin.py « RemovableDriveOutputDevice « plugins - github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7b3363308dea69b6d264a91e41f3f50761043800 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Copyright (c) 2015 Ultimaker B.V.
# Copyright (c) 2013 David Braam
# Uranium is released under the terms of the LGPLv3 or higher.

from . import RemovableDrivePlugin

from UM.Logger import Logger

import glob
import os
import subprocess


class LinuxRemovableDrivePlugin(RemovableDrivePlugin.RemovableDrivePlugin):
    """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.
    """

    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()
        Logger.log("d", "umount returned: %s.", repr(output))

        return_code = p.wait()
        if return_code != 0:
            return False
        else:
            return True