winvol.py 2.28 KB
from dialog import Dialog

import logger
import winver
from mount import mount,umount
from runcmd import runProcess
from vars.modulevar import Modulevar


def getInstance(modname):
    return WinVol(modname)

class WinVol(Modulevar):

    def __init__(self,modname):
        self.name = "winvol"
        self.parentModule = modname
        self.description = "Windows 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 getFATVolumes(self):
        result = runProcess("scripts/list_fat.sh")
        resultlst =result[0].decode("utf-8").splitlines()
        volumes = []
        for res in resultlst:
            output,code = runProcess(["dosfslabel","/dev/" + res])
            volumes.append((res,output.decode("utf-8").rstrip()))
        return volumes

    def getWindowsVolumes(self):
        volumes = self.getNTFSVolumes() + self.getFATVolumes()
        winvols = []
        for volume in volumes:
            mntpoint = "/mnt/"
            mntid = mount("/dev/" + volume[0])
            mntpoint += mntid
            if(winver.getWindowsDirectory(mntpoint) != None):
                winvols.append(volume)
            umount(mntid)
        return winvols

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