ntfsvol.py 1.49 KB
from dialog import Dialog
import logger
from runcmd import runProcess
from vars.modulevar import Modulevar


def getInstance(modname):
    return NTFSVol(modname)

class NTFSVol(Modulevar):

    def __init__(self,modname):
        self.name = "ntfsvol"
        self.parentModule = modname
        self.description = "NTFS Volume"
        self.value = None

    def getNTFSVolumes(self):
        result = runProcess("scripts/list_ntfs.sh")
        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").rstrip()))
        return volumes

    def query(self):
        d = Dialog(dialog="dialog", autowidgetsize=True)
        d.set_background_title("[" + self.parentModule + "] Setting variable: ntfsvol")
        volumes = self.getNTFSVolumes()
        if(len(volumes) == 0):
            raise Exception("[" + self.name + "] No NTFS Volumes found")
        logger.msgLog("Detected NTFS volumes in " + repr(volumes), "ntfsvol", logger.TYPE_INFO)
        volumeList = []
        for vol in volumes:
            volumeList.append((vol[0],vol[1], False))
        code, vols = d.checklist("Select NTFS volumes",
                                 choices=volumeList,
                                 title="Module selection")
        if code == d.OK:
            self.value = vols
        else:
            raise Exception("[" + self.name + "] Operation Cancelled")