Blame view

vars/ntfsvol.py 1.37 KB
1
from modulevar import Modulevar
2
3
from dialog import Dialog
from runcmd import runProcess
4
5
6
def getInstance(modname):
    return NTFSVol(modname)
7
8
9

class NTFSVol(Modulevar):
10
    def __init__(self,modname):
11
        self.name = "ntfsvol"
12
        self.parentModule = modname
13
14
15
        self.description = "NTFS Volume"
        self.value = None
16
17
    def getNTFSVolumes(self):
        result = runProcess("scripts/list_ntfs.sh")
18
19
20
21
22
23
        resultlst =result[0].decode("utf-8").splitlines()
        volumes = []
        for res in resultlst:
            output,code = runProcess(["ntfslabel","/dev/" + res])
            volumes.append((res,output.decode("utf-8")))
        return volumes
24
25
    def query(self):
26
27
        d = Dialog(dialog="dialog", autowidgetsize=True)
        d.set_background_title("[" + self.parentModule + "] Setting variable: ntfsvol")
28
29
30
31
32
33
34
        volumes = self.getNTFSVolumes()
        if(len(volumes) == 0):
            raise Exception("[" + self.name + "] No Windows Volumes found")
        volumeList = []
        for vol in volumes:
            volumeList.append((vol[0],vol[1], False))
        code, vols = d.checklist("Select NTFS volumes",
35
36
37
38
39
40
                                 choices=volumeList,
                                 title="Module selection")
        if code == d.OK:
            self.value = vols
        else:
            raise Exception("[" + self.name + "] Operation Cancelled")