Beispiel #1
0
def open_locker_uri(uri, opener_cache_dict=None):
    sha1 = uri[9:]
    assert len(sha1) == 40
    context = SynchronizerContext()
    opener = opener_for_url_prefix(
        openretro_url_prefix(), username=context.username,
        password=context.password, cache_dict=opener_cache_dict)
    url = "{0}/api/locker/{1}".format(openretro_url_prefix(), sha1)
    path = Downloader.cache_file_from_url(url, opener=opener)
    return path
Beispiel #2
0
def open_locker_uri(uri, opener_cache_dict=None):
    sha1 = uri[9:]
    assert len(sha1) == 40
    context = SynchronizerContext()
    opener = opener_for_url_prefix(openretro_url_prefix(),
                                   username=context.username,
                                   password=context.password,
                                   cache_dict=opener_cache_dict)
    url = "{0}/api/locker/{1}".format(openretro_url_prefix(), sha1)
    path = Downloader.cache_file_from_url(url, opener=opener)
    return path
Beispiel #3
0
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 = urlopen(url)
    data = r.read()
    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:
        f.write(data)
    os.rename(cache_file_partial, cache_file)
    return cache_file
Beispiel #4
0
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
Beispiel #5
0
 def get_url(self):
     variant_uuid = LauncherConfig.get("variant_uuid", "")
     if not variant_uuid:
         return
     return "{0}/game/{1}/edit#{1}".format(
         openretro_url_prefix(), variant_uuid
     )
Beispiel #6
0
    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]
Beispiel #7
0
    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]
Beispiel #8
0
 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
Beispiel #9
0
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 __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)
Beispiel #13
0
 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()
Beispiel #14
0
 def post(self, path, params=None, data=None, auth=True):
     headers = {}
     if auth:
         credentials = self.credentials()
         headers[str("Authorization")] = str(
             "Basic "
             + base64.b64encode(
                 "{0}:{1}".format(*credentials).encode("UTF-8")
             ).decode("UTF-8")
         )
     connection = openretro_http_connection()
     url = "{0}{1}".format(openretro_url_prefix(), path)
     # if params:
     #     url += "?" + urlencode(params)
     if not data and params:
         data = urlencode(params)
         headers[str("Content-Type")] = str(
             "application/x-www-form-urlencoded"
         )
     print(url, headers)
     if isinstance(data, dict):
         data = json.dumps(data)
     # print(data)
     connection.request(str("POST"), str(url), data, headers=headers)
     response = connection.getresponse()
     if response.status not in [200]:
         print(response.status, response.reason)
         if response.status == 400:
             class_ = BadRequestError
         elif response.status == 401:
             class_ = UnauthorizedError
         elif response.status == 403:
             class_ = ForbiddenError
         elif response.status == 404:
             class_ = NotFoundError
         else:
             class_ = HTTPError
         raise class_(
             url,
             response.status,
             response.reason,
             response.getheaders(),
             None,
         )
     data = response.read()
     if len(data) > 0 and data[0:1] == b"{":
         doc = json.loads(data.decode("UTF-8"))
         return doc
     return data
Beispiel #15
0
 def post(self, path, params=None, data=None, auth=True):
     headers = {}
     if auth:
         credentials = self.get_credentials()
         headers[str("Authorization")] = str(
             "Basic " + base64.b64encode("{0}:{1}".format(
                 *credentials).encode("UTF-8")).decode("UTF-8"))
     connection = openretro_http_connection()
     url = "{0}{1}".format(openretro_url_prefix(), path)
     # if params:
     #     url += "?" + urlencode(params)
     if not data and params:
         data = urlencode(params)
         headers[str("Content-Type")] = \
             str("application/x-www-form-urlencoded")
     print(url, headers)
     if isinstance(data, dict):
         data = json.dumps(data)
     # print(data)
     connection.request(str("POST"), str(url), data, headers=headers)
     response = connection.getresponse()
     if response.status not in [200]:
         print(response.status, response.reason)
         if response.status == 400:
             class_ = BadRequestError
         elif response.status == 401:
             class_ = UnauthorizedError
         elif response.status == 403:
             class_ = ForbiddenError
         elif response.status == 404:
             class_ = NotFoundError
         else:
             class_ = HTTPError
         raise class_(url, response.status, response.reason,
                      response.getheaders(), None)
     data = response.read()
     if len(data) > 0 and data[0:1] == b"{":
         doc = json.loads(data.decode("UTF-8"))
         return doc
     return data
Beispiel #16
0
 def url_prefix(self):
     return openretro_url_prefix()
Beispiel #17
0
 def url_prefix(self):
     return openretro_url_prefix()
 def get_url(self):
     variant_uuid = LauncherConfig.get("variant_uuid", "")
     if not variant_uuid:
         return
     return "{0}/game/{1}".format(openretro_url_prefix(), variant_uuid)