def get_file_for_sha1_cached(sha1, size_arg, cache_ext): cache_zip = get_cache_zip_for_sha1(sha1) if cache_zip is not None: try: return cache_zip.open("{}/{}{}".format(sha1[:2], sha1, cache_ext)) except KeyError: pass cache_dir = FSGSDirectories.images_dir_for_sha1(sha1) cache_file = os.path.join(cache_dir, sha1 + cache_ext) if os.path.exists(cache_file): # An old bug made it possible for 0-byte files to exist, so # we check for that here... if os.path.getsize(cache_file) > 0: return cache_file url = "{}/image/{}{}".format(openretro_url_prefix(), sha1, size_arg) print("[IMAGES]", url) r = requests.get(url, stream=True) try: r.raise_for_status() cache_file_partial = "{}.{}.partial".format(cache_file, str(uuid4())[:8]) if not os.path.exists(os.path.dirname(cache_file_partial)): os.makedirs(os.path.dirname(cache_file_partial)) with open(cache_file_partial, "wb") as f: for chunk in r.iter_content(chunk_size=65536): f.write(chunk) finally: r.close() os.rename(cache_file_partial, cache_file) return cache_file
def load_info(self, values): self.config["languages"] = values["languages"] self.config["players"] = values["players"] self.config["year"] = values["year"] self.config["publisher"] = values["publisher"] self.config["developer"] = values["developer"] self.config["x_game_notice"] = values["game_notice"] self.config["x_variant_notice"] = values["variant_notice"] self.config["x_variant_warning"] = values["variant_warning"] self.config["x_variant_error"] = values["variant_error"] self.config["database_url"] = "{0}/game/{1}".format( openretro_url_prefix(), values["parent_uuid"]) for key in ["mobygames_url"]: self.config[key] = values[key] for key in [ "download_file", "download_page", "download_terms", "download_notice", ]: if key in values: self.config[key] = values[key]
def get_url(self): config = get_config(self) variant_uuid = config.get("variant_uuid", "") if not variant_uuid: return return "{0}/game/{1}/edit#{1}".format( openretro_url_prefix(), variant_uuid )
def open_locker_uri(uri): sha1 = uri[9:] assert len(sha1) == 40 context = SynchronizerContext() url = "{0}/api/locker/{1}".format(openretro_url_prefix(), sha1) path = Downloader.cache_file_from_url(url, auth=(context.username, context.password)) return path
def url_prefix(self): if self.host: if is_http_url(self.host): url_prefix = self.host else: url_prefix = "http://{}".format(self.host) else: url_prefix = openretro_url_prefix() return url_prefix
def __init__(self, uuid=""): self.config = {} self.options = {} self.viewport = [] self.values = {} self.uuid = uuid self._file_list = None self._cue_sheets = None if uuid: self.options["database_url"] = "{0}/game/{1}".format( openretro_url_prefix(), uuid)
def post(self, path, params=None, data=None, auth=True): headers = {} url = "{0}{1}".format(openretro_url_prefix(), path) if not data and params: data = urlencode(params) headers["Content-Type"] = "application/x-www-form-urlencoded" print(url, headers) r = requests.post(url, data, headers=headers, auth=(self.auth() if auth else None)) r.raise_for_status() return r.json()
def url_prefix(self): return openretro_url_prefix()