From f02ba5ad748b9cbad129274aecb5b26d3ce3a2ba Mon Sep 17 00:00:00 2001 From: vg Date: Sat, 17 Sep 2022 22:36:09 +0200 Subject: git-sync on seele --- gamechestcli/gamechest/cliactions/install.py | 3 ++- gamechestcli/gamechest/cliactions/remove.py | 3 ++- gamechestcli/gamechest/gamedb.py | 19 ++++++++++--------- gamechestcli/gamechest/statusdb.py | 6 +++--- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/gamechestcli/gamechest/cliactions/install.py b/gamechestcli/gamechest/cliactions/install.py index 9d55883..ed2437f 100644 --- a/gamechestcli/gamechest/cliactions/install.py +++ b/gamechestcli/gamechest/cliactions/install.py @@ -16,7 +16,8 @@ def install_game(status_db, game_info): def install(game_id): - game_info = gamedb.get_game_info(game_id) + game_db = gamdb.GameDB() + game_info = game_db.get_game_info(game_id) status_db = StatusDB() if status_db.is_installed(game_info): # games is already installed diff --git a/gamechestcli/gamechest/cliactions/remove.py b/gamechestcli/gamechest/cliactions/remove.py index 2024b4b..1668e63 100644 --- a/gamechestcli/gamechest/cliactions/remove.py +++ b/gamechestcli/gamechest/cliactions/remove.py @@ -23,7 +23,8 @@ def remove_game(status_db, game_info): def remove(game_id): - game_info = gamedb.get_game_info(game_id) + game_db = gamdb.GameDB() + game_info = game_db.get_game_info(game_id) status_db = StatusDB() if status_db.is_installed(game_info): remove_game(status_db, game_info) diff --git a/gamechestcli/gamechest/gamedb.py b/gamechestcli/gamechest/gamedb.py index 1e3967c..d932438 100644 --- a/gamechestcli/gamechest/gamedb.py +++ b/gamechestcli/gamechest/gamedb.py @@ -3,14 +3,15 @@ import yaml from . import paths -def load_games_database(): - database_path = paths.get_games_database_path() - with open(database_path, 'rb') as fdin: - return yaml.safe_load(fdin) +class GameDB: + def __init__(self): + database_path = paths.get_games_database_path() + with open(database_path, 'rb') as fdin: + self.db = yaml.safe_load(fdin) -def get_game_info(game_id): - db = load_games_database() - return next(game_info - for game_info in db['games'] - if game_info['id'] == game_id) + + def get_game_info(self, game_id): + return next(game_info + for game_info in self.db['games'] + if game_info['id'] == game_id) diff --git a/gamechestcli/gamechest/statusdb.py b/gamechestcli/gamechest/statusdb.py index a010206..a41fe32 100644 --- a/gamechestcli/gamechest/statusdb.py +++ b/gamechestcli/gamechest/statusdb.py @@ -43,7 +43,7 @@ class StatusDB: (game_info['id'], )) .fetchone() ) - with cursor: + with self.conn: if row is None: cursor.execute(''' INSERT INTO status @@ -77,9 +77,9 @@ class StatusDB: #return False raise ValueError('Game not found') version_installed = row[0] - return f'{game_id}_v{version}' + return f'{game_id}_v{version_installed}' - def unset_installed(self, game_info): + def set_uninstalled(self, game_info): return self.set_installed(game_info, installed=False) def __enter__(self): -- cgit v1.2.3