예제 #1
0
파일: __main__.py 프로젝트: swissvoc/Nuitka
def getCPythonResults(cpython_cmd, cpython_cached):
    cached = False
    if cpython_cached:
        # TODO: Hashing stuff and creating cache filename is duplicate code
        # and should be shared.
        hash_input = " -- ".join(cpython_cmd)
        if str is not bytes:
            hash_input = hash_input.encode("utf8")

        command_hash = hashlib.md5(hash_input)

        for element in cpython_cmd:
            if os.path.exists(element):
                with open(element, "rb") as element_file:
                    command_hash.update(element_file.read())

        cache_filename = os.path.join(getTestingCPythonOutputsCacheDir(),
                                      command_hash.hexdigest())

        if os.path.exists(cache_filename):
            with open(cache_filename, "rb") as cache_file:
                cpython_time, stdout_cpython, stderr_cpython, exit_cpython = \
                  pickle.load(cache_file)
                cached = True

    if not cached:
        cpython_time, stdout_cpython, stderr_cpython, exit_cpython = _getCPythonResults(
            cpython_cmd)

        if cpython_cached:
            with open(cache_filename, "wb") as cache_file:
                pickle.dump((cpython_time, stdout_cpython, stderr_cpython,
                             exit_cpython), cache_file)

    return cpython_time, stdout_cpython, stderr_cpython, exit_cpython
예제 #2
0
def getCPythonResults(cpython_cmd, cpython_cached, force_update):
    # Many details, pylint: disable=too-many-locals

    cached = False
    if cpython_cached:
        # TODO: Hashing stuff and creating cache filename is duplicate code
        # and should be shared.
        hash_input = " -- ".join(cpython_cmd)
        if str is not bytes:
            hash_input = hash_input.encode("utf8")

        command_hash = hashlib.md5(hash_input)

        for element in cpython_cmd:
            if os.path.exists(element):
                with open(element, "rb") as element_file:
                    command_hash.update(element_file.read())

        hash_salt = os.environ.get("NUITKA_HASH_SALT", "")

        if str is not bytes:
            hash_salt = hash_salt.encode("utf8")
        command_hash.update(hash_salt)

        if os.name == "nt" and python_version < 0x300:
            curdir = os.getcwdu()
        else:
            curdir = os.getcwd()

        command_hash.update(curdir.encode("utf8"))

        cache_filename = os.path.join(
            getTestingCPythonOutputsCacheDir(), command_hash.hexdigest()
        )

        if os.path.exists(cache_filename) and not force_update:
            with open(cache_filename, "rb") as cache_file:
                (
                    cpython_time,
                    stdout_cpython,
                    stderr_cpython,
                    exit_cpython,
                ) = pickle.load(cache_file)
                cached = True

    if not cached:
        cpython_time, stdout_cpython, stderr_cpython, exit_cpython = _getCPythonResults(
            cpython_cmd
        )

        if cpython_cached:
            with open(cache_filename, "wb") as cache_file:
                pickle.dump(
                    (cpython_time, stdout_cpython, stderr_cpython, exit_cpython),
                    cache_file,
                )

    return cpython_time, stdout_cpython, stderr_cpython, exit_cpython
예제 #3
0
def getCPythonResults(cpython_cmd, cpython_cached):
    cached = False
    if cpython_cached:
        # TODO: Hashing stuff and creating cache filename is duplicate code
        # and should be shared.

        hash_input = " -- ".join(cpython_cmd)
        if str is not bytes:
            hash_input = hash_input.encode("utf8")

        command_hash = hashlib.md5(hash_input)

        cache_filename = os.path.join(
            getTestingCPythonOutputsCacheDir(),
            command_hash.hexdigest()
        )

        if os.path.exists(cache_filename):
            with open(cache_filename, "rb") as cache_file:
                cpython_time, stdout_cpython, stderr_cpython, exit_cpython = \
                  pickle.load(cache_file)
                cached = True

    if not cached:
        start_time = time.time()

        # Try a coupile of times for permission denied, on Windows it can
        # be transient.
        for _i in range(5):
            with withPythonPathChange(os.getcwd()):
                process = subprocess.Popen(
                    args   = cpython_cmd,
                    stdout = subprocess.PIPE,
                    stderr = subprocess.PIPE
                )

            stdout_cpython, stderr_cpython = process.communicate()
            exit_cpython = process.returncode

            if checkNoPermissionError(stdout_cpython) and \
               checkNoPermissionError(stderr_cpython):
                break

            my_print("Retrying CPython due to permission problems after delay.")
            time.sleep(2)

            start_time = time.time()

        cpython_time = time.time() - start_time

        if cpython_cached:
            with open(cache_filename, "wb") as cache_file:
                pickle.dump(
                    (cpython_time, stdout_cpython, stderr_cpython, exit_cpython),
                    cache_file
                )

    return cpython_time, stdout_cpython, stderr_cpython, exit_cpython