Everyone stop panicking, I have killed the shitty property

This commit is contained in:
Mathieu Comandon 2024-04-08 13:57:44 -07:00
parent e841fd7b57
commit 6b622b37f8
3 changed files with 4 additions and 32 deletions

View file

@ -132,20 +132,6 @@ class Game(GObject.Object):
game.service = service.id if service else None
return game
@property
def as_library_item(self):
"""Return a representation of the game suitable for the remote library"""
return {
"name": self.name,
"slug": self.slug,
"runner": self.runner_name,
"platform": self.platform,
"playtime": self.playtime,
"lastplayed": self.lastplayed,
"service": self.service,
"service_id": self.appid,
}
def __repr__(self):
return self.__str__()

View file

@ -6,7 +6,7 @@ from typing import Callable, Iterable, List
from gi.repository import GObject, Gtk
from lutris import settings
from lutris.database.games import get_games
from lutris.database.games import get_game_by_field, get_games
from lutris.game import Game
from lutris.gui.dialogs import QuestionDialog
from lutris.gui.widgets.gi_composites import GtkTemplate
@ -283,7 +283,7 @@ class UninstallDialog(Gtk.Dialog):
library_syncer = LibrarySyncer()
for row in rows:
if row.remove_from_library:
games_removed_from_library.append(row.game.as_library_item)
games_removed_from_library.append(get_game_by_field(row.game._id, "id"))
if games_removed_from_library:
library_syncer.sync_local_library()

View file

@ -125,11 +125,7 @@ class LibrarySyncer:
def _db_game_to_api(self, db_game):
"""Serialize DB game entry to a payload compatible with the API"""
try:
categories = [self.categories[cat_id] for cat_id in self.games_categories.get(db_game["id"], [])]
except KeyError:
self.panic_at_the_key_error(db_game, "id")
return
categories = [self.categories[cat_id] for cat_id in self.games_categories.get(db_game["id"], [])]
return {
"name": db_game["name"],
"slug": db_game["slug"],
@ -142,22 +138,12 @@ class LibrarySyncer:
"categories": categories,
}
def panic_at_the_key_error(self, db_game, key):
logger.error((("!" * 120) + "\n") * 240)
logger.exception("No installed_at key in db_game. CORRUPTED OBJECT!!!!!")
logger.exception("OBJECT CONTENT %s", db_game)
logger.error((("!" * 120) + "\n") * 24)
sys.exit(-999)
def _db_games_to_api(self, db_games, since=None):
"""Serialize a collection of games to API format, optionally filtering by date"""
payload = []
for db_game in db_games:
lastplayed = db_game["lastplayed"] or 0
try:
installed_at = db_game["installed_at"] or 0
except KeyError:
self.panic_at_the_key_error(db_game, "installed_at")
installed_at = db_game["installed_at"] or 0
if since and lastplayed < since and installed_at < since:
continue