Esempio n. 1
0
 def run(self, workingDir="", variables={}, printer=Printer()):
     printer.verbose("Diff:", self.paths)
     _leftpath = replaceVariables(self.paths[0], variables, printer)
     _rightpath = replaceVariables(self.paths[1], variables, printer)
     _ignore = []
     for ignoreLine in self.ignore:
         _ignoreline = replaceVariables(ignoreLine, variables, printer)
         _ignore.append(_ignoreline)
     workingDirPath = pathlib.Path(workingDir)
     return diff(workingDirPath.joinpath(_leftpath),
                 workingDirPath.joinpath(_rightpath), self.binarycompare,
                 self.strategy, _ignore, printer)
Esempio n. 2
0
    def run(self, workingDir=".", variables={}, printer=Printer()):

        printer.verbose("Run:", self.cmd)
        replCmd = replaceVariables(self.cmd, variables)
        printer.verbose("cwd:", os.getcwd())
        printer.verbose("call:", replCmd)
        cmdNArgs = shlex.split(replCmd)

        if self.shell == "powershell":
            return self.__run_powershell(replCmd, workingDir, variables,
                                         printer)
        if self.shell == "cmd":
            return self.__run_cmd(replCmd, workingDir, variables, printer)
        if self.shell == "sh":
            return self.__run_sh(replCmd, workingDir, variables, printer)
        elif self.shell != None:
            printer.error("unknown shell ", self.shell)
            return false

        inputfileData = None
        if self.inputfile:
            with open(
                    pathlib.PurePath(workingDir).joinpath(
                        replaceVariables(self.inputfile, variables)),
                    "rb") as fh:
                inputfileData = fh.read()
        shell = (sys.platform == "win32")
        subProcessRes = subprocess.run(cmdNArgs,
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.STDOUT,
                                       input=inputfileData,
                                       cwd=workingDir,
                                       shell=shell)
        if self.outputfile:
            outputfileFullPath = str(
                pathlib.PurePath(workingDir).joinpath(
                    replaceVariables(self.outputfile, variables)))
            ensure_dir(outputfileFullPath)
            with open(outputfileFullPath, "wb") as fh:
                fh.write(subProcessRes.stdout)

        res = True
        if (self.exitcode != None):
            res = subProcessRes.returncode == self.exitcode
            if not res:
                printer.error("different exitcode received:",
                              subProcessRes.returncode, "!=", self.exitcode,
                              "for command '" + str(replCmd) + "'")
        return res
Esempio n. 3
0
    def __run_powershell(self,
                         replCmd,
                         workingDir=".",
                         variables={},
                         printer=Printer()):
        if self.inputfile:
            printer.error("inputfile not allowed when shell = ", self.shell)
            return false
        inputData = str.encode(replCmd)
        subProcessRes = subprocess.run(
            ["powershell", "-NonInteractive", "-NoLogo"],
            stdout=subprocess.PIPE,
            stderr=subprocess.STDOUT,
            input=inputData,
            cwd=workingDir,
            shell=False)
        if self.outputfile:
            outputfileFullPath = str(
                pathlib.PurePath(workingDir).joinpath(
                    replaceVariables(self.outputfile, variables)))
            ensure_dir(outputfileFullPath)
            with open(outputfileFullPath, "wb") as fh:
                fh.write(subProcessRes.stdout)

        res = True
        if (self.exitcode != None):
            res = subProcessRes.returncode == self.exitcode
            if not res:
                printer.error("different exitcode received:",
                              subProcessRes.returncode, "!=", self.exitcode,
                              "for command '" + str(replCmd) + "'")
        return res
Esempio n. 4
0
 def test_basic(self):
     line = replaceVariables("Replace ${repl1} ${repl2} ${repl3} \${esc}", {
         'repl1': '${repl2}',
         'repl2': '${repl3}',
         'repl3': '${repl1}'
     })
     self.assertEqual(line, "Replace ${repl2} ${repl3} ${repl1} ${esc}")
Esempio n. 5
0
 def test_missingVar(self):
     with self.assertRaisesRegex(GeneratorException, "Variable .*") as e:
         line = replaceVariables(
             "Replace ${repl1} ${repl2} ${repl3} ${repl4}", {
                 'repl1': '${repl2}',
                 'repl2': '${repl3}',
                 'repl3': '${repl1}'
             })
Esempio n. 6
0
 def run(self, workingDir="", variables={}, printer=Printer()):
     printer.verbose("Rmdir:", self.dir)
     _dir = replaceVariables(self.dir, variables, printer)
     return rmtree(str(pathlib.PurePath(workingDir).joinpath(_dir)),
                   printer)
Esempio n. 7
0
 def run(self, workingDir="", variables={}, printer=Printer()):
     printer.verbose("Makedirs:", self.dir)
     _dir = replaceVariables(self.dir, variables, printer)
     _dir = str(pathlib.PurePath(workingDir).joinpath(_dir)) + "/"
     ensure_dir(_dir)
     return True