def init_gamelist(self): self.games = games.Games(self.log) self.games_lock = threading.Lock() print("loading games",self.config["games"]) self.games.load(self.config["games"],self.config["local"]) sync.download() self.gamelist = [] self.update_gamelist_widget()
def games_revision(user): user = User(user) if not user.is_ready(): return {"server_revision": None} try: gdbm = games.Games() gdbm.load_games(filename=user.game_path) except: traceback.print_exc() return {"error": "Error loading game database"} return {"server_revision": gdbm.revision}
def bump_revision(user): user = User(user) if not user.is_ready(): return {"error": "user not initialized"} try: gdbm = games.Games() gdbm.load_games(filename=user.game_path) gdbm.revision += 1 gdbm.save(user.game_path) except: traceback.print_exc() return {"error": "Error loading game database"} return {"server_revision": gdbm.revision}
def game_database(body, user, input=raw): user = User(user) user.make_ready() try: data = body.read() gdbmu = games.Games() gdbmu.load_games(filedata=data) except: traceback.print_exc() return {"error": "Not a valid game database"} try: gdbms = games.Games() gdbms.load_games(filename=user.game_path) if gdbms.revision > gdbmu.revision: return { "error": "server has newer revision", "client_revision": gdbmu.revision, "server_revision": gdbms.revision } except: pass with open(user.game_path, "wb") as gamef: gamef.write(data) return {"msg": "success", "size": len(data)}
def refresh_games(): print("REFRESHING GAMES") game_file = app.config["games"] gamedb = app.games downloading = game_file + ".d" downloaded = games.Games() downloaded.load(downloading) #force update all games from server into games for g in downloaded.games.values(): gamedb.force_update_game(g.gameid, g) #Delete games that are gone on server for gameid in list(gamedb.games.keys()): if gameid in gamedb.games and gameid not in downloaded.games: print("DELETING", gamedb.games[gameid]) del gamedb.games[gameid] #Update local revision to match server gamedb.revision = downloaded.revision
def sync_downloadgames(self): games = downloadrequest() self.games = games.Games(self.log) self.games.translate_json(games) self.save() self.update_gamelist_widget()