Пример #1
0
    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()
Пример #2
0
    def _generateTmpDoWorkBatFile(self, execFile, argList):
        """execFile and argList should be windows path"""

        assert not FvmUtil.isWinAbsPath(execFile)

        buf = ''
        buf += '@echo off\n'
        buf += 'setlocal enabledelayedexpansion\n'
        buf += '\n'
        if execFile.endswith(".au3"):
            buf += '"..\\autoit\\autoit3.exe" "%s"' % (execFile)
        elif execFile.endswith(".bat"):
            buf += 'call "%s"' % (execFile)
        elif execFile.endswith(".exe"):
            buf += '"%s"' % (execFile)
        else:
            assert False
        for a in argList:
            buf += ' "%s"' % (a)
        buf += '\n'
        buf += 'goto :eof\n'
        buf += '\n'

        tmpf = os.path.join(self.param.tmpDir, "_do_work.bat")
        FvmUtil.writeFile(tmpf, buf)
        return tmpf
Пример #3
0
    def _generateTmpDoWorkBatFile(self, execFile, argList):
        """execFile and argList should be windows path"""

        assert not FvmUtil.isWinAbsPath(execFile)

        buf = ''
        buf += '@echo off\n'
        buf += 'setlocal enabledelayedexpansion\n'
        buf += '\n'
        if execFile.endswith(".au3"):
            buf += '"..\\autoit\\autoit3.exe" "%s"' % (execFile)
        elif execFile.endswith(".bat"):
            buf += 'call "%s"' % (execFile)
        elif execFile.endswith(".exe"):
            buf += '"%s"' % (execFile)
        else:
            assert False
        for a in argList:
            buf += ' "%s"' % (a)
        buf += '\n'
        buf += 'goto :eof\n'
        buf += '\n'

        tmpf = os.path.join(self.param.tmpDir, "_do_work.bat")
        FvmUtil.writeFile(tmpf, buf)
        return tmpf
Пример #4
0
    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)
Пример #5
0
    def _generateUnattendXmlScript(self, uatFile):

        # read template
        uatTemplateFile = self._getFile(self.osName, "autounattend")
        buf = FvmUtil.readFile(uatTemplateFile)

        # replace content
        buf = buf.replace("@@timezone@@", self._getTimezone())
        buf = buf.replace("@@serial_id@@", self._getSerial())
        buf = buf.replace("@@x_resolution@@", "1024")
        buf = buf.replace("@@y_resolution@@", "768")
        buf = buf.replace("@@country_code@@", "86")
        buf = buf.replace("@@area_code@@", "00")
        buf = buf.replace("@@dialing@@", "Tone")
        buf = buf.replace("@@language_group@@", "10")
        buf = buf.replace("@@language@@", "00000804")

        # write file
        FvmUtil.writeFile(uatFile, buf)
Пример #6
0
    def _generateTmpConfigIniFile(self, reqList):

        shutdownFlag = "true"
        if "rebootAndShutdown" in reqList:
            shutdownFlag = "false"

        buf = ''
        buf += '[config]\n'
        buf += 'reqList=%s\n' % (" ".join(reqList))
        buf += 'winLang=%s\n' % (self._getWinLang())
        buf += '\n'
        buf += '[boot]\n'
        buf += 'bootNo=0\n'						# startup.bat will increase it in every boot process
        buf += 'bootInfo=\n'
        buf += 'shutdownFlag=%s\n' % (shutdownFlag)
        buf += '\n'

        tmpf = os.path.join(self.param.tmpDir, "config.ini")
        FvmUtil.writeFile(tmpf, buf)
        return tmpf
Пример #7
0
    def _generateTmpConfigIniFile(self, reqList):

        shutdownFlag = "true"
        if "rebootAndShutdown" in reqList:
            shutdownFlag = "false"

        buf = ''
        buf += '[config]\n'
        buf += 'reqList=%s\n' % (" ".join(reqList))
        buf += 'winLang=%s\n' % (self._getWinLang())
        buf += '\n'
        buf += '[boot]\n'
        buf += 'bootNo=0\n'  # startup.bat will increase it in every boot process
        buf += 'bootInfo=\n'
        buf += 'shutdownFlag=%s\n' % (shutdownFlag)
        buf += '\n'

        tmpf = os.path.join(self.param.tmpDir, "config.ini")
        FvmUtil.writeFile(tmpf, buf)
        return tmpf
Пример #8
0
    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()