예제 #1
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
 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 convert_uri(self, uri, prefer_path=False):
     if uri.startswith("sha1://"):
         return self.open_sha1_uri(uri)
     elif uri.startswith("db://"):
         # old name for sha1://
         return self.open_sha1_uri(uri)
     elif is_http_url(uri):
         return self.open_url(uri)
     elif uri.startswith("locker://"):
         return open_locker_uri(
             uri, opener_cache_dict=self.opener_cache_dict)
     else:
         if prefer_path and os.path.exists(uri):
             # return helper object so isinstance does not match with str
             return File(uri)
         return Archive(uri).open(uri)
예제 #4
0
 def convert_uri(self, uri, prefer_path=False):
     if uri.startswith("sha1://"):
         return self.open_sha1_uri(uri)
     elif uri.startswith("db://"):
         # old name for sha1://
         return self.open_sha1_uri(uri)
     elif is_http_url(uri):
         return self.open_url(uri)
     elif uri.startswith("locker://"):
         return open_locker_uri(uri,
                                opener_cache_dict=self.opener_cache_dict)
     else:
         if prefer_path and os.path.exists(uri):
             # return helper object so isinstance does not match with str
             return File(uri)
         return Archive(uri).open(uri)
예제 #5
0
    def prepare_hard_drives(self):
        print("LaunchHandler.prepare_hard_drives")
        current_task.set_progress(gettext("Preparing hard drives..."))
        # self.on_progress(gettext("Preparing hard drives..."))

        for i in range(0, 10):
            key = "hard_drive_{0}".format(i)
            src = self.config.get(key, "")
            dummy, ext = os.path.splitext(src)
            ext = ext.lower()

            if is_http_url(src):
                name = src.rsplit("/", 1)[-1]
                name = urllib.parse.unquote(name)
                self.on_progress(gettext("Downloading {0}...".format(name)))
                dest = os.path.join(self.temp_dir, name)
                Downloader.install_file_from_url(src, dest)
                src = dest
            elif src.startswith("hd://game/"):
                self.unpack_game_hard_drive(i, src)
                self.disable_save_states()
                return
            elif src.startswith("hd://template/workbench/"):
                self.prepare_workbench_hard_drive(i, src)
                self.disable_save_states()
                return
            elif src.startswith("hd://template/empty/"):
                self.prepare_empty_hard_drive(i, src)
                self.disable_save_states()
                return

            if ext in Archive.extensions:
                print("zipped hard drive", src)
                self.unpack_hard_drive(i, src)
                self.disable_save_states()

            elif src.endswith("HardDrive"):
                print("XML-described hard drive", src)
                self.unpack_hard_drive(i, src)
                self.disable_save_states()
            else:
                src = Paths.expand_path(src)
                self.config[key] = src
예제 #6
0
    def fetch_data_attempt(self, url, accept_gzip_encoding=False):
        if not is_http_url(url):
            url = "{0}{1}".format(self.url_prefix(), url)
        print(url)
        request = Request(url)
        if accept_gzip_encoding:
            request.add_header("Accept-Encoding", "gzip")
        response = self.opener().open(request)
        # print(response.headers)
        data = response.read()

        try:
            getheader = response.headers.getheader
        except AttributeError:
            getheader = response.getheader
        content_encoding = getheader("content-encoding", "").lower()
        if content_encoding == "gzip":
            fake_stream = StringIO(data)
            data = GzipFile(fileobj=fake_stream).read()
        return data
예제 #7
0
    def fetch_data_attempt(self, url, accept_gzip_encoding=False):
        if not is_http_url(url):
            url = "{0}{1}".format(self.url_prefix(), url)
        print(url)
        request = Request(url)
        if accept_gzip_encoding:
            request.add_header("Accept-Encoding", "gzip")
        response = self.opener().open(request)
        # print(response.headers)
        data = response.read()

        try:
            getheader = response.headers.getheader
        except AttributeError:
            getheader = response.getheader
        content_encoding = getheader("content-encoding", "").lower()
        if content_encoding == "gzip":
            fake_stream = StringIO(data)
            data = GzipFile(fileobj=fake_stream).read()
        return data
예제 #8
0
 def url(self, url):
     if not is_http_url(url):
         url = "{0}{1}".format(self.url_prefix(), url)
     if USE_REQUESTS:
         url = url.replace("http:", "https:")
     return url
예제 #9
0
 def url(self, url):
     if not is_http_url(url):
         url = "{0}{1}".format(self.url_prefix(), url)
     return url
예제 #10
0
 def url(self, url):
     if not is_http_url(url):
         url = "{0}{1}".format(self.url_prefix(), url)
     if USE_REQUESTS:
         url = url.replace("http:", "https:")
     return url