diff options
| -rwxr-xr-x | gamechestcli/src/gamechest/__main__.py | 39 | ||||
| -rw-r--r-- | gamechestcli/src/gamechest/statusdb.py | 14 |
2 files changed, 45 insertions, 8 deletions
diff --git a/gamechestcli/src/gamechest/__main__.py b/gamechestcli/src/gamechest/__main__.py index 30f277c..6a20425 100755 --- a/gamechestcli/src/gamechest/__main__.py +++ b/gamechestcli/src/gamechest/__main__.py @@ -2,16 +2,17 @@ ''' 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=<PATH>] [--gamesaves_path=<PATH>] +Usage: gamechest install GAME_ID ... + gamechest remove GAME_ID ... + gamechest update [GAME_ID ...] + gamechest run [--profile_id=PROFILE_ID] GAME_ID + gamechest set [--profile_id=PROFILE_ID] [--remote_basedir=PATH] [--gamesaves_path=PATH] gamechest list [--installed|--not-installed] gamechest showconfig Options: - --profile_id=<PROFILE_ID>, -p <PROFILE_ID> - use profile <PROFILE_ID> instead of the default one. + --profile_id=PROFILE_ID, -p PROFILE_ID + use profile PROFILE_ID instead of the default one. ''' import sys @@ -29,9 +30,31 @@ def main(): #print(args); raise SystemExit(0) if args['install']: - install.install(args['<GAME_ID>']) + for gameid in args['GAME_ID']: + install.install(gameid) elif args['remove']: - remove.remove(args['<GAME_ID>']) + for gameid in args['GAME_ID']: + remove.remove(gameid) + elif args['update']: + game_db = GameDB() + status_db = StatusDB() + game_ids = args['GAME_ID'] or game_db.get_ids() + update_count = 0 + game_count = 0 + for gameid in game_ids: + game_count += 1 # don't do len() as game_ids can be a generator + game_info = game_db.get_info(gameid) + if status_db.is_up_to_date(game_info): + continue + print(f'Updating {gameid}') + remove.remove(gameid) + install.install(gameid) + update_count += 1 + if not update_count: + print('{} already up to date.'.format( + 'All' if game_count > 0 else 'Game')) + else: + print(f'{update_count}/{game_count} games updated.') elif args['run']: profile_id = args['--profile_id'] or config.get_profile_id() if not profile_id: diff --git a/gamechestcli/src/gamechest/statusdb.py b/gamechestcli/src/gamechest/statusdb.py index 3f2af31..0999f6b 100644 --- a/gamechestcli/src/gamechest/statusdb.py +++ b/gamechestcli/src/gamechest/statusdb.py @@ -95,6 +95,20 @@ class StatusDB: def set_uninstalled(self, game_info): return self.set_installed(game_info, installed=False) + def get_version(self, game_info): + row = ( + self.conn + .execute('SELECT version_installed FROM status WHERE game_id = ?', + (game_info['id'], )) + .fetchone() + ) + if row is None: + return False + return row[0] + + def is_up_to_date(self, game_info): + return int(game_info['version']) <= int(self.get_version(game_info)) + def __enter__(self): return self |
