Ejemplo n.º 1
0
def download(url, filename, hash=None):
    """
    Downloads `url` to `filename`, a tempfile.
    """
    global download_url

    global download_file

    download_url = url
    download_file = _friendly(filename)

    filename = _path(filename)

    if hash is not None:
        if _check_hash(filename, hash):
            return

    progress_time = time.time()

    try:

        response = requests.get(url, stream=True)
        response.raise_for_status()

        total_size = int(response.headers.get('content-length', 1))

        downloaded = 0

        with open(filename, "wb") as f:

            for i in response.iter_content(65536):

                f.write(i)
                downloaded += len(i)

                if time.time() - progress_time > 0.1:
                    progress_time = time.time()
                    if not quiet:
                        interface.processing(
                            _("Downloading [installer.download_file]..."),
                            complete=downloaded,
                            total=total_size)

    except requests.HTTPError as e:
        if not quiet:
            raise

        interface.error(
            _("Could not download [installer.download_file] from [installer.download_url]:\n{b}[installer.download_error]"
              ))

    if hash is not None:
        if not quiet:
            raise Exception("Hash check failed.")
        if not _check_hash(filename, hash):
            interface.error(
                _("The downloaded file [installer.download_file] from [installer.download_url] is not correct."
                  ))
Ejemplo n.º 2
0
def run(*args, **kwargs):
    """
    Runs a program with the given arguments, in the target directory.
    """

    environ = {
        renpy.exports.fsencode(k): renpy.exports.fsencode(v)
        for k, v in os.environ.items()
    }

    for k, v in kwargs.pop("environ", {}).items():
        environ[renpy.exports.fsencode(k)] = renpy.exports.fsencode(v)

    global install_args
    global install_error

    args = [renpy.exports.fsencode(i) for i in args]

    try:
        subprocess.check_call(args, cwd=target, env=environ)  # type: ignore
    except Exception as e:
        install_args = args
        install_error = str(e)

        interface.error(
            _("Could not run [installer.install_args!r]:\n[installer.install_error]"
              ))
Ejemplo n.º 3
0
def manifest(url, renpy=False, insecure=False):
    """
    Executes the manifest at `url`.

    `renpy`
        If true, the manifest applies to Ren'Py. If False, the manifest applies
        to the current project.

    `insecure`
        If true, verificaiton is disabled.
    """

    import ecdsa

    download(url, "temp:manifest.py")

    with open(_path("temp:manifest.py"), "rb") as f:
        manifest = f.read()

    if not insecure:
        download(url + ".sig", "temp:manifest.py.sig")

        with open(_path("temp:manifest.py.sig"), "rb") as f:
            sig = f.read()

        key = ecdsa.VerifyingKey.from_pem(
            _renpy.exports.file("renpy_ecdsa_public.pem").read())

        if not key.verify(sig, manifest):
            error(_("The manifest signature is not valid."))
            return

    if renpy:
        set_target(config.renpy_base)
    else:
        if project.current is None:
            error(_("No project has been selected."))
            return

        set_target(project.current.path)

    exec(manifest.decode("utf-8"), {}, {})
Ejemplo n.º 4
0
def local_manifest(filename, renpy=False):
    """
    Executes the manifest in `filename`.

    `renpy`
        If true, the manifest applies to Ren'Py. If False, the manifest applies
        to the current project.
    """

    if renpy:
        set_target(config.renpy_base)
    else:
        if project.current is None:
            error(_("No project has been selected."))
            return

        set_target(project.current.path)

    with open(filename, "r") as f:
        exec(f.read(), {}, {})
Ejemplo n.º 5
0
def unpack(archive, destination):
    """
    Unpacks `archive` to `destination`. `archive` should be the name of
    a zip or (perhaps compressed) tar file. `destination` should be a
    directory that the contents are unpacked into.
    """

    global unpack_archive
    unpack_archive = _friendly(archive)

    if not quiet:
        interface.processing(_("Unpacking [installer.unpack_archive]..."))

    archive = _path(archive)
    destination = _path(destination)

    if not os.path.exists(destination):
        os.makedirs(destination)

    old_cwd = os.getcwd()

    try:

        os.chdir(destination)

        if tarfile.is_tarfile(archive):
            tar = tarfile.open(archive)
            tar.extractall(".")
            tar.close()

        elif zipfile.is_zipfile(archive):
            zip = _FixedZipFile(archive)
            zip.extractall(".")
            zip.close()

        else:
            raise Exception("Unknown file type.")

    finally:
        os.chdir(old_cwd)