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]" ))
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." ))
def error(message, **kwargs): """ Displays `message` to the user, as an error. """ interface.error(message)