Example #1
0
    def runCommandWithOutput(self, commands, style=None):
        """
        Returns the stdout,stderr from process.communicate()
        """
        if type(commands) in (str, unicode):
            commands = [commands]

        with withDirectoryChange(self.env_dir):
            if os.name == "nt":
                commands = [r"call scripts\activate.bat"] + commands
            else:
                commands = [". bin/activate"] + commands

            popen_arg = " && ".join(commands)

            if style is not None:
                my_print("Executing: %s" % popen_arg, style=style)

            # Use subprocess and also return outputs, stdout, stderr, result
            process = subprocess.Popen(
                args=popen_arg,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                shell=True,
            )
            return process.communicate()
Example #2
0
def withVirtualenv(env_name, base_dir=None, python=None, delete=True, style=None):
    """Create a virtualenv and change into it.

    Activating for actual use will be your task.
    """

    print("Creating virtualenv for quick test:")

    if python is None:
        python = sys.executable

    if base_dir is not None:
        env_dir = os.path.join(base_dir, env_name)
    else:
        env_dir = env_name

    removeDirectory(env_dir, ignore_errors=False)

    with withDirectoryChange(base_dir, allow_none=True):
        command = [python, "-m", "virtualenv", env_name]
        if style is not None:
            my_print("Executing: %s" % " ".join(command))
        check_call(command)

        yield Virtualenv(env_dir)

    if delete:
        removeDirectory(env_dir, ignore_errors=False)
Example #3
0
    def runCommand(self, commands):
        if type(commands) in (str, unicode):
            commands = [commands]

        with withDirectoryChange(self.env_dir):
            if os.name == "nt":
                commands = [r"call scripts\activate.bat"] + commands
            else:
                commands = [". bin/activate"] + commands

            command = " && ".join(commands)
            assert os.system(command) == 0, command
Example #4
0
def publishCoverageData():
    def copyToGlobalCoverageData(source, target):
        coverage_dir = os.environ.get("COVERAGE_DIR")

        if coverage_dir is None:
            return

        check_call(("scp", source, os.path.join(coverage_dir, target)))

    if os.name == "nt":
        suffix = "win"
    else:
        import platform

        suffix = platform.uname()[0] + "." + platform.uname()[4]

    with open("data.coverage", "w") as data_file:
        source_dir = os.path.abspath(os.path.dirname(
            os.path.dirname(__file__)))

        with withDirectoryChange(source_dir):
            nuitka_id = check_output("git rev-parse HEAD".split())
        nuitka_id = nuitka_id.strip()

        if sys.version_info > (3, ):
            nuitka_id = nuitka_id.decode()

        data_file.write("NUITKA_SOURCE_DIR=%r\n" % source_dir)
        data_file.write("NUITKA_COMMIT=%r\n" % nuitka_id)

    copyToGlobalCoverageData("data.coverage", "meta.coverage." + suffix)

    def makeCoverageRelative(filename):
        """Normalize coverage data."""

        with open(filename) as input_file:
            data = input_file.read()

        data = data.replace(
            (os.path.abspath(".") + os.path.sep).replace("\\", "\\\\"), "")

        if os.path.sep != "/":
            data.replace(os.path.sep, "/")

        with open(filename, "w") as output_file:
            output_file.write(data)

    coverage_file = os.environ.get("COVERAGE_FILE", ".coverage")

    makeCoverageRelative(coverage_file)
    copyToGlobalCoverageData(coverage_file, "data.coverage." + suffix)