def _createAndInjectStartupFile(self, batFileList, hasCdrom): """windows path elements in batFileList is relative to usb disk drive root directory""" # create startup file in tmpDir tmpf = os.path.join(self.param.tmpDir, "startup.bat") nbuf = "" if True: lineList = FvmUtil.readFile(os.path.join(self.param.dataDir, "startup.bat.in")).split("\n") tmplBegin = lineList.index("@@execute_template@@") tmplEnd = lineList.index("@@execute_template_end@@") nbuf += "\n".join(lineList[:tmplBegin]) + "\n" tmplBuf = "\n".join(lineList[tmplBegin + 1:tmplEnd]) + "\n" for vsi in batFileList: ntbuf = tmplBuf ntbuf = ntbuf.replace("@@execName@@", vsi) ntbuf = ntbuf.replace("@@execWorkDir@@", FvmUtil.winDirname(vsi)) ntbuf = ntbuf.replace("@@execFile@@", vsi) nbuf += ntbuf nbuf += "\n".join(lineList[tmplEnd + 1:]) if hasCdrom: nbuf = nbuf.replace("@@driverLetter@@", "E:") else: nbuf = nbuf.replace("@@driverLetter@@", "D:") FvmUtil.writeFile(tmpf, nbuf) # inject startup file mptObj = WinDiskMountPoint(self.param, self.vmObj.getMainDiskImage(), self._getWinLang()) try: startupDir = FvmUtil.getWinDir("startup", self._getWinLang(), FvmUtil.getWinUser()) mptObj.addTmpFile(tmpf, startupDir, False) finally: mptObj.umount()
def injectTo(self, mainDiskImage): # write to tmp file tmpf = os.path.join(self.param.tmpDir, "startup.bat") FvmUtil.writeFile(tmpf, self.buf) # inject operation mptObj = WinDiskMountPoint(self.param, mainDiskImage, FvmUtil.getWinLang(self.osName)) try: startupDir = FvmUtil.getWinDir("startup", FvmUtil.getWinLang(self.osName), FvmUtil.getWinUser()) mptObj.addFile(tmpf, startupDir, False) finally: mptObj.umount() os.remove(tmpf)
def _createAndInjectStartupFile(self, batFileList, hasCdrom): """windows path elements in batFileList is relative to usb disk drive root directory""" # create startup file in tmpDir tmpf = os.path.join(self.param.tmpDir, "startup.bat") nbuf = "" if True: lineList = FvmUtil.readFile( os.path.join(self.param.dataDir, "startup.bat.in")).split("\n") tmplBegin = lineList.index("@@execute_template@@") tmplEnd = lineList.index("@@execute_template_end@@") nbuf += "\n".join(lineList[:tmplBegin]) + "\n" tmplBuf = "\n".join(lineList[tmplBegin + 1:tmplEnd]) + "\n" for vsi in batFileList: ntbuf = tmplBuf ntbuf = ntbuf.replace("@@execName@@", vsi) ntbuf = ntbuf.replace("@@execWorkDir@@", FvmUtil.winDirname(vsi)) ntbuf = ntbuf.replace("@@execFile@@", vsi) nbuf += ntbuf nbuf += "\n".join(lineList[tmplEnd + 1:]) if hasCdrom: nbuf = nbuf.replace("@@driverLetter@@", "E:") else: nbuf = nbuf.replace("@@driverLetter@@", "D:") FvmUtil.writeFile(tmpf, nbuf) # inject startup file mptObj = WinDiskMountPoint(self.param, self.vmObj.getMainDiskImage(), self._getWinLang()) try: startupDir = FvmUtil.getWinDir("startup", self._getWinLang(), FvmUtil.getWinUser()) mptObj.addTmpFile(tmpf, startupDir, False) finally: mptObj.umount()