Beispiel #1
0
 def check_sha1(self, sha1):
     database = FileDatabase.instance()
     result = database.check_sha1(sha1)
     if not result and is_locker_enabled():
         database = LockerDatabase.instance()
         result = database.check_sha1(sha1)
         # print("check sha1", sha1, "in locker database - result", result)
     # if not result:
     #     result = self.context.get_game_database().find_file_by_sha1(sha1)
     return result
Beispiel #2
0
 def update_file_database_timestamps(self):
     # This isn't very elegant, but in order to force the game scanner to
     # refresh the game list based on files, we update the stamps in the
     # file database. Also, since we haven't keep track of additions /
     # deletions, we set both stamps for now...
     file_database = FileDatabase.instance()
     file_database.last_file_insert = time.time()
     file_database.last_file_delete = time.time()
     file_database.update_last_event_stamps()
     file_database.commit()
 def check_sha1(self, sha1):
     database = FileDatabase.instance()
     result = database.check_sha1(sha1)
     if not result and is_locker_enabled():
         database = LockerDatabase.instance()
         result = database.check_sha1(sha1)
         # print("check sha1", sha1, "in locker database - result", result)
     # if not result:
     #     result = self.context.get_game_database().find_file_by_sha1(sha1)
     return result
Beispiel #4
0
 def update_file_database_timestamps(self):
     # This isn't very elegant, but in order to force the game scanner to
     # refresh the game list based on files, we update the stamps in the
     # file database. Also, since we haven't keep track of additions /
     # deletions, we set both stamps for now...
     file_database = FileDatabase.instance()
     file_database.last_file_insert = time.time()
     file_database.last_file_delete = time.time()
     file_database.update_last_event_stamps()
     file_database.commit()
Beispiel #5
0
    def upload_check(self, prefix):
        self.progressed(
            gettext("Finding files eligible for OAGD.net Locker")
            + " ({:0.0%})".format((prefix / 16.0))
        )
        file_database = FileDatabase.instance()
        cursor = file_database.cursor()
        # FIXME: prefix
        p = "0123456789ABCDEF"[prefix]
        cursor.execute(
            "SELECT DISTINCT sha1 FROM file " "WHERE hex(sha1) LIKE ?",
            (p + "%",),
        )
        string_io = StringIO()
        for row in cursor:
            string_io.write(row[0])
        # print(prefix, len(string_io.getvalue()))
        self.stop_check()

        retry_seconds = 1
        while True:
            try:
                result = self.client.post(
                    "/api/locker-upload-check", data=string_io.getvalue()
                )
            except OGDClient.ForbiddenError:
                raise Task.Failure(
                    gettext(
                        "OAGD.net Locker is not enabled for your user. "
                        "It may be available only to a few select beta "
                        "users."
                    )
                )
            except OGDClient.NonRetryableHTTPError as e:
                raise e
            except Exception:
                traceback.print_exc()
                self.progressed(
                    gettext("Re-trying in {0} seconds...").format(
                        retry_seconds
                    )
                )
                for _ in range(retry_seconds):
                    self.stop_check()
                    time.sleep(1.0)
                retry_seconds = min(retry_seconds * 2, 60 * 10)
            else:
                return result
Beispiel #6
0
 def find_by_sha1(self, sha1):
     database = FileDatabase.instance()
     result = database.find_file(sha1=sha1)["path"]
     if not result:
         path = Downloader.get_cache_path(sha1)
         if os.path.exists(path):
             result = path
     #    result = self.context.get_game_database().find_file_by_sha1(sha1)
     # print("find by sha1", sha1, "in file database - result", result)
     if not result and is_locker_enabled():
         database = LockerDatabase.instance()
         if database.check_sha1(sha1):
             result = "locker://" + sha1
         # print("find by sha1", sha1, "in locker database - result",
         # result)
     return result
 def find_by_sha1(self, sha1):
     database = FileDatabase.instance()
     result = database.find_file(sha1=sha1)["path"]
     if not result:
         path = Downloader.get_cache_path(sha1)
         if os.path.exists(path):
             result = path
     #    result = self.context.get_game_database().find_file_by_sha1(sha1)
     # print("find by sha1", sha1, "in file database - result", result)
     if not result and is_locker_enabled():
         database = LockerDatabase.instance()
         if database.check_sha1(sha1):
             result = "locker://" + sha1
         # print("find by sha1", sha1, "in locker database - result",
         # result)
     return result
Beispiel #8
0
    def upload_check(self, prefix):
        self.progressed(
            gettext("Finding files eligible for OpenRetro Locker") +
            " ({:0.0%})".format((prefix / 16.0)))
        file_database = FileDatabase.instance()
        cursor = file_database.cursor()
        # FIXME: prefix
        p = "0123456789ABCDEF"[prefix]
        cursor.execute(
            "SELECT DISTINCT sha1 FROM file "
            "WHERE hex(sha1) LIKE ?",
            (p + "%", ),
        )
        string_io = StringIO()
        for row in cursor:
            string_io.write(row[0])
        # print(prefix, len(string_io.getvalue()))
        self.stop_check()

        retry_seconds = 1
        while True:
            try:
                result = self.client.post("/api/locker-upload-check",
                                          data=string_io.getvalue())
            except OGDClient.ForbiddenError:
                raise Task.Failure(
                    gettext("OpenRetro Locker is not enabled for your user. "
                            "It may be available only to a few select beta "
                            "users."))
            except OGDClient.NonRetryableHTTPError as e:
                raise e
            except Exception:
                traceback.print_exc()
                self.progressed(
                    gettext("Re-trying in {0} seconds...").format(
                        retry_seconds))
                for _ in range(retry_seconds):
                    self.stop_check()
                    time.sleep(1.0)
                retry_seconds = min(retry_seconds * 2, 60 * 10)
            else:
                return result