summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xgamechestcli/__main__.py20
-rw-r--r--gamechestcli/gamechest/gameconfig.py10
-rw-r--r--gamechestcli/gamechest/gamedb.py4
-rw-r--r--gamechestcli/gamechest/statusdb.py18
4 files changed, 35 insertions, 17 deletions
diff --git a/gamechestcli/__main__.py b/gamechestcli/__main__.py
index 8fe912d..22749bd 100755
--- a/gamechestcli/__main__.py
+++ b/gamechestcli/__main__.py
@@ -5,16 +5,21 @@ Manage games. Install, remove, run them.
Usage: gamechest install <GAME_ID>
gamechest remove <GAME_ID>
gamechest run [--profile_id=<PROFILE_ID>] <GAME_ID>
- gamechest set [--profile_id=<PROFILE_ID>] [--remote_basedir=<BASEDIR>] [--gamesaves_path]
+ gamechest set [--profile_id=<PROFILE_ID>] [--remote_basedir=<PATH>] [--gamesaves_path=<PATH>]
+ gamechest list [--installed]
+ gamechest showconfig
'''
import sys
import docopt
+from rich import print
from gamechest.cliactions import install, remove, run
from gamechest.gameconfig import config
+from gamechest.statusdb import StatusDB
+from gamechest.gamedb import GameDB
def main():
@@ -35,9 +40,20 @@ def main():
config.set_profile_id(args['--profile_id'])
if args['--remote_basedir']:
config.set_remote_basedir(args['--remote_basedir'])
- if args['--gamesaves_path']
+ if args['--gamesaves_path']:
config.set_gamesaves_path(args['--gamesaves_path'])
config.save()
+ elif args['list']:
+ status_db = StatusDB()
+ if args['--installed']:
+ print(list(status_db.get_installed()))
+ else:
+ game_db = GameDB()
+ list_installed = list(status_db.get_installed())
+ for game_id in game_db.get_ids():
+ print(game_id, 'installed:', game_id in list_installed)
+ elif args['showconfig']:
+ config.print_config()
if __name__ == "__main__":
diff --git a/gamechestcli/gamechest/gameconfig.py b/gamechestcli/gamechest/gameconfig.py
index effacd0..91f13ff 100644
--- a/gamechestcli/gamechest/gameconfig.py
+++ b/gamechestcli/gamechest/gameconfig.py
@@ -2,7 +2,7 @@ import contextlib
from pathlib import Path
import yaml
-from xdg import xdg_data_home
+from xdg import xdg_data_home, xdg_config_home
from . import consts
@@ -36,7 +36,8 @@ class GameConfig:
self.game_config_filepath = game_config_filepath
with contextlib.ExitStack() as stack:
stack.enter_context(contextlib.suppress(FileNotFoundError))
- fdin = stack.enter_context(open(game_config_filepath, 'rb'))
+ fdin = stack.enter_context(open(game_config_filepath, 'r',
+ encoding='utf8'))
self.config = yaml.safe_load(fdin)
self.config = {
**DEFAULT_CONFIG_DICT,
@@ -74,7 +75,7 @@ class GameConfig:
self.config['gamesaves_path']
)
)
- with open(self.game_config_filepath, 'wb') as fdout:
+ with open(self.game_config_filepath, 'w', encoding='utf8') as fdout:
yaml.safe_dump(dict_transformed_for_save, fdout)
def set_profile_id(self, profile_id):
@@ -93,6 +94,9 @@ class GameConfig:
games_install_path.mkdir(parents=True, exist_ok=True)
return games_install_path
+ def print_config(self):
+ print(self.config)
+
# default instance of gameconfig, same instance intended to be shared through
# all modules which needs it.
diff --git a/gamechestcli/gamechest/gamedb.py b/gamechestcli/gamechest/gamedb.py
index 99d3c9a..98db2d9 100644
--- a/gamechestcli/gamechest/gamedb.py
+++ b/gamechestcli/gamechest/gamedb.py
@@ -41,3 +41,7 @@ class GameDB:
]
return command
+
+ def get_ids(self):
+ for game_info in self.db['games']:
+ yield game_info['id']
diff --git a/gamechestcli/gamechest/statusdb.py b/gamechestcli/gamechest/statusdb.py
index e343d8e..4c490a2 100644
--- a/gamechestcli/gamechest/statusdb.py
+++ b/gamechestcli/gamechest/statusdb.py
@@ -66,18 +66,12 @@ class StatusDB:
game_info['id'],
))
- #def get_installed_game_name(self, game_id):
- # row = (
- # self.conn
- # .execute('SELECT version_installed FROM status WHERE game_id = ?',
- # (game_id, ))
- # .fetchone()
- # )
- # if row is None:
- # #return False
- # raise ValueError('Game not found')
- # version_installed = row[0]
- # return f'{game_id}_v{version_installed}'
+ def get_installed(self):
+ for row in (
+ self.conn
+ .execute('SELECT game_id FROM status WHERE installed = 1')
+ ):
+ yield row[0]
def set_uninstalled(self, game_info):
return self.set_installed(game_info, installed=False)