diff --git a/lutris/util/library_sync.py b/lutris/util/library_sync.py index 7940cb26c..a2dbe7f3e 100644 --- a/lutris/util/library_sync.py +++ b/lutris/util/library_sync.py @@ -1,4 +1,5 @@ import json +import sys import time from typing import List, Optional @@ -124,7 +125,11 @@ class LibrarySyncer: def _db_game_to_api(self, db_game): """Serialize DB game entry to a payload compatible with the API""" - categories = [self.categories[cat_id] for cat_id in self.games_categories.get(db_game["id"], [])] + 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 return { "name": db_game["name"], "slug": db_game["slug"], @@ -137,12 +142,23 @@ 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 - installed_at = db_game["installed_at"] or 0 + try: + installed_at = db_game["installed_at"] or 0 + except KeyError: + self.panic_at_the_key_error(db_game, "installed_at") + if since and lastplayed < since and installed_at < since: continue payload.append(self._db_game_to_api(db_game)) diff --git a/utils/cleanup_prefix.py b/utils/cleanup_prefix.py index cd7c2d070..40ed04c9a 100644 --- a/utils/cleanup_prefix.py +++ b/utils/cleanup_prefix.py @@ -113,6 +113,7 @@ def delete_known_dirs(prefix_path): continue os.remove(regfile) + def remove_empty_dirs(dirname): empty_folders = [] for root, dirs, files in os.walk(dirname, topdown=True):