summaryrefslogtreecommitdiffstats
path: root/gamechestcli/gamechest/cliactions/run.py
blob: b5369aa66f39d27bc83df7fe19423d3799b11d3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import subprocess
import sys

from .. import paths
from ..gamedb import GameDB
from ..statusdb import StatusDB


def run_game(game_db, profile_id, game_info):
    command = game_db.get_game_command(profile_id, game_info['id'])
    #tools_bin_path = paths.get_games_saves_tools_bin_path()
    #new_env = dict(os.environ)
    #new_env['PATH'] = f'{tools_bin_path}:{new_env["PATH"]}'
    # path to mod/run scripts are already prepended by get_game_command, no
    # need to modify the path environment variable.
    subprocess.run(command)


def run(game_id, profile_id):
    game_db = GameDB()
    status_db = StatusDB()
    game_info = game_db.get_game_info(game_id)
    if not status_db.is_installed(game_info):
        # games is already installed
        print('Game', game_id, 'is not installed, aborting.', file=sys.stderr)
        return
    run_game(game_db, profile_id, game_info)


if __name__ == "__main__":
    run(*sys.argv[1:])