def main(self): FvmUtil.createWinUsbImg("abc.img", 1024, "ntfs")
def _executeWorkListOnLine(self, workList, startIndex): """usb.img directory structure: [usb.img] |--config.ini |--autoit |--autoit files |--work1 |--_do_work.bat |--xxxx.au3 |--work2 |--_do_work.bat |--xxxx.au3 |--other files |--work3 |--_do_work.bat |--xxxx.bat |--other files |--work4 |--_do_work.bat |--xxxx.exe config.ini format: [config] winLang = "xxxx" reqList = "xx1 xx2" [boot] bootNo = 1 bootInfo = "xxxx" shutdownFlag = false""" self.infoPrinter.printInfo(">> Doing on-line operation...") self.infoPrinter.incIndent() # prepare usb disk usbFile = os.path.join(self.param.tmpDir, "usb.img") FvmUtil.createWinUsbImg(usbFile, 1024, "ntfs") mptObj = WinDiskMountPoint(self.param, usbFile, self._getWinLang()) # copy files to usb disk batFileList = [] reqList = None workCount = 0 try: mptObj.addAutoIt() mptObj.addSevenZip() # process work i = 0 while (startIndex + i) < len(workList): w = workList[startIndex + i] if not self._isWorkOnLine(w): break if self._mergeReqList(reqList, w) is None: break # create work-dir workDir = "work%d" % (i) mptObj.mkdir(workDir) if isinstance(w, FvmWorkOnLineFree): # fill usb disk absWorkDir = os.path.join(mptObj.getMountDir(), workDir) w.fillUsbDataDir(self.param, absWorkDir) # generate _do_work.bat (execFile, argList) = w.getCmdLine() tmpf = self._generateTmpDoWorkBatFile(execFile, argList) mptObj.addTmpFile(tmpf, workDir, False) elif isinstance(w, FvmWorkOnLineExec): # fill usb disk for fname, isBinary in w.fileList: mptObj.addFile(fname, workDir, isBinary) for fname, isBinary in w.tmpFileList: mptObj.addTmpFile(fname, workDir, isBinary) for fname in w.zipFileList: d = os.path.join(workDir, os.path.splitext(os.path.basename(fname))[0]) mptObj.mkdir(d) mptObj.addZipFile(fname, d) if True: isBinary = w.execFile.endswith(".exe") mptObj.addFile(w.execFile, workDir, isBinary) # generate _do_work.bat tmpf = self._generateTmpDoWorkBatFile(os.path.basename(w.execFile), w.argList) mptObj.addTmpFile(tmpf, workDir, False) else: assert False reqList = self._mergeReqList(reqList, w) batFileList.append("%s\\_do_work.bat" % (os.path.basename(workDir))) i = i + 1 # get workCount workCount = i assert workCount > 0 # add config.ini tmpf = self._generateTmpConfigIniFile(reqList) mptObj.addTmpFile(tmpf, "", False) finally: mptObj.umount() for i in range(0, workCount): self.infoPrinter.printInfo(">> %s" % (workList[startIndex + i].workName)) # pre-run virtual machine cdromf = self._getCdromFileFromReqList(reqList) if cdromf is not None: self.vmObj.setLocalCdromImage(cdromf) self.vmObj.setLocalUsbImage(usbFile) if "noNetwork" in reqList: self.vmObj.setNetworkStatus("none") elif "network" not in reqList: self.vmObj.setNetworkStatus("isolate") # run virtual machine FvmUtil.winPauseAutoActivity(self.param, self.vmObj.getMainDiskImage(), self._getWinLang()) self._createAndInjectStartupFile(batFileList, (cdromf is not None)) self.vmObj.run() FvmUtil.winResumeAutoActivity(self.param, self.vmObj.getMainDiskImage(), self._getWinLang()) self.infoPrinter.decIndent() self._resetVmEnvironment() return workCount
def _executeWorkListOnLine(self, workList, startIndex): """usb.img directory structure: [usb.img] |--config.ini |--autoit |--autoit files |--work1 |--_do_work.bat |--xxxx.au3 |--work2 |--_do_work.bat |--xxxx.au3 |--other files |--work3 |--_do_work.bat |--xxxx.bat |--other files |--work4 |--_do_work.bat |--xxxx.exe config.ini format: [config] winLang = "xxxx" reqList = "xx1 xx2" [boot] bootNo = 1 bootInfo = "xxxx" shutdownFlag = false""" self.infoPrinter.printInfo(">> Doing on-line operation...") self.infoPrinter.incIndent() # prepare usb disk usbFile = os.path.join(self.param.tmpDir, "usb.img") FvmUtil.createWinUsbImg(usbFile, 1024, "ntfs") mptObj = WinDiskMountPoint(self.param, usbFile, self._getWinLang()) # copy files to usb disk batFileList = [] reqList = None workCount = 0 try: mptObj.addAutoIt() mptObj.addSevenZip() # process work i = 0 while (startIndex + i) < len(workList): w = workList[startIndex + i] if not self._isWorkOnLine(w): break if self._mergeReqList(reqList, w) is None: break # create work-dir workDir = "work%d" % (i) mptObj.mkdir(workDir) if isinstance(w, FvmWorkOnLineFree): # fill usb disk absWorkDir = os.path.join(mptObj.getMountDir(), workDir) w.fillUsbDataDir(self.param, absWorkDir) # generate _do_work.bat (execFile, argList) = w.getCmdLine() tmpf = self._generateTmpDoWorkBatFile(execFile, argList) mptObj.addTmpFile(tmpf, workDir, False) elif isinstance(w, FvmWorkOnLineExec): # fill usb disk for fname, isBinary in w.fileList: mptObj.addFile(fname, workDir, isBinary) for fname, isBinary in w.tmpFileList: mptObj.addTmpFile(fname, workDir, isBinary) for fname in w.zipFileList: d = os.path.join( workDir, os.path.splitext(os.path.basename(fname))[0]) mptObj.mkdir(d) mptObj.addZipFile(fname, d) if True: isBinary = w.execFile.endswith(".exe") mptObj.addFile(w.execFile, workDir, isBinary) # generate _do_work.bat tmpf = self._generateTmpDoWorkBatFile( os.path.basename(w.execFile), w.argList) mptObj.addTmpFile(tmpf, workDir, False) else: assert False reqList = self._mergeReqList(reqList, w) batFileList.append("%s\\_do_work.bat" % (os.path.basename(workDir))) i = i + 1 # get workCount workCount = i assert workCount > 0 # add config.ini tmpf = self._generateTmpConfigIniFile(reqList) mptObj.addTmpFile(tmpf, "", False) finally: mptObj.umount() for i in range(0, workCount): self.infoPrinter.printInfo(">> %s" % (workList[startIndex + i].workName)) # pre-run virtual machine cdromf = self._getCdromFileFromReqList(reqList) if cdromf is not None: self.vmObj.setLocalCdromImage(cdromf) self.vmObj.setLocalUsbImage(usbFile) if "noNetwork" in reqList: self.vmObj.setNetworkStatus("none") elif "network" not in reqList: self.vmObj.setNetworkStatus("isolate") # run virtual machine FvmUtil.winPauseAutoActivity(self.param, self.vmObj.getMainDiskImage(), self._getWinLang()) self._createAndInjectStartupFile(batFileList, (cdromf is not None)) self.vmObj.run() FvmUtil.winResumeAutoActivity(self.param, self.vmObj.getMainDiskImage(), self._getWinLang()) self.infoPrinter.decIndent() self._resetVmEnvironment() return workCount
def doWork(self, param, vmObj, infoPrinter): """do driver update operation""" # prepare parameter self.param = param self.vmObj = vmObj # create assistant usb disk usbFile = os.path.join(self.param.tmpDir, "usb.img") if True: FvmUtil.createWinUsbImg(usbFile, 300, "ntfs") mptObj = WinDiskMountPoint(self.param, usbFile, FvmUtil.getWinLang(self.osName)) try: mptObj.addAutoIt() mptObj.addFile(os.path.join(self.dataDir, "autocfg-update-driver.au3"), "", False) mptObj.addFile(os.path.join(self.dataDir, "autocfg-enable-vdagent.au3"), "", False) finally: mptObj.umount() self.vmObj.setLocalUsbImage(usbFile) # update virtio harddisk driver if self.vmObj.getVmInfo().vmCfgHw.mainDiskInterface != "ide": # create and inject startup file sFileList = ["autocfg-update-driver.au3", "autocfg-enable-vdagent.au3"] msf = MyStartupFile(self.param, self.osName, sFileList) msf.injectTo(self.vmObj.getMainDiskImage()) # run virtual machine self.vmObj.setLocalFakeHarddisk(self.vmObj.getVmInfo().vmCfgHw.mainDiskInterface) self.vmObj.run() self.vmObj.setLocalFakeHarddisk("") # update drivers if True: # create and inject startup.bat to disk-main.img sFileList = ["autocfg-update-driver.au3", # VirtIO SCSI driver "autocfg-update-driver.au3", # VirtIO Balloon driver "autocfg-update-driver.au3", # VirtIO Serial driver "autocfg-update-driver.au3"] # Red Hat QXL GPU driver msf = MyStartupFile(self.param, self.osName, sFileList) msf.injectTo(self.vmObj.getMainDiskImage()) # run virtual machine self.vmObj.setSetupMode(False) self.vmObj.setNetworkStatus("isolate") self.vmObj.run() self.vmObj.setNetworkStatus("") # update virtio network driver if self.vmObj.getVmInfo().vmCfgHw.networkAdapterInterface != "user": # create and inject startup.bat to disk-main.img sFileList = ["autocfg-update-driver.au3"] # VirtIO Network driver msf = MyStartupFile(self.param, self.osName, sFileList) msf.injectTo(self.vmObj.getMainDiskImage()) # run virtual machine self.vmObj.setNetworkStatus("virtio-dummy") self.vmObj.run() self.vmObj.setNetworkStatus("")
def doWork(self, param, vmObj, infoPrinter): """do driver update operation""" # prepare parameter self.param = param self.vmObj = vmObj # do preparation configuration in main disk image mptObj = WinDiskMountPoint(self.param, self.vmObj.getMainDiskImage(), FvmUtil.getWinLang(self.osName)) try: winreg = WinRegistry(self.param, mptObj.getMountDir()) # add sleep.exe, needed by delay code in startup.bat mptObj.addFile(os.path.join(self.dataDir, "sleep.exe"), "WINDOWS/system32", True) # Dismiss screen check, so it won't disturb us winreg.addOrModify("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\DontShowMeThisDialogAgain", "ScreenCheck", "REG_SZ", "no") # Dismiss balloon tips, so it won't disturb us winreg.addOrModify("HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", "EnableBalloonTips", "REG_DWORD", 0) # Disable "AutoPlay & AutoRun", they will disturb some config's autoit script winreg.addOrModify("HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\policies\\Explorer", "NoDriveTypeAutoRun", "REG_DWORD", 0xff) finally: mptObj.umount() # boot with usb disk, so it can be the first hardware device recognized usbFile = os.path.join(self.param.tmpDir, "usb.img") if True: FvmUtil.createWinUsbImg(usbFile, 300, "ntfs") mptObj = WinDiskMountPoint(self.param, usbFile, FvmUtil.getWinLang(self.osName)) try: mptObj.addAutoIt() # dismiss start menu show, so it won't disturb us mptObj.addFile(os.path.join(self.dataDir, "autocfg-dismiss-start-menu-show.au3"), "", False) # disable swapfile and snapshot as early as possible mptObj.addFile(os.path.join(self.dataDir, "autocfg-disable-swapfile.au3"), "", False) mptObj.addFile(os.path.join(self.dataDir, "autocfg-disable-snapshot.au3"), "", False) # disable anti-virus check, so it won't disturb us mptObj.addFile(os.path.join(self.dataDir, "autocfg-disable-antivirues-check.au3"), "", False) # disable screen saver, so it won't disturb us in future mptObj.addFile(os.path.join(self.dataDir, "autocfg-disable-screensaver.au3"), "", False) # disable desktop cleanup wizard mptObj.addFile(os.path.join(self.dataDir, "autocfg-disable-desktop-cleanup-wizard.au3"), "", False) # dismiss explore xp, so it won't disturb us # it can't be dismissed by directly modify the registry, don't know why mptObj.addFile(os.path.join(self.dataDir, "autocfg-dismiss-explore-winxp.au3"), "", False) finally: mptObj.umount() self.vmObj.setLocalUsbImage(usbFile) # create and inject startup file sFileList = ["autocfg-dismiss-start-menu-show.au3", "autocfg-disable-swapfile.au3", "autocfg-disable-snapshot.au3", "autocfg-disable-antivirues-check.au3", "autocfg-disable-screensaver.au3", "autocfg-disable-desktop-cleanup-wizard.au3", "autocfg-dismiss-explore-winxp.au3"] msf = MyStartupFile(self.param, self.osName, sFileList) msf.injectTo(self.vmObj.getMainDiskImage()) # run virtual machine # this boot will also dimiss the start menu show, so it won't disturb us in future self.vmObj.run()