summaryrefslogtreecommitdiffstats
path: root/gamechestcli/gamechest/cliactions/install.py
blob: 508dd48481ae8440bd77b03b38ab63f0817b9a69 (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
32
import functools

from .. import gamedb, processor
from ..gameconfig import config
from ..runners.install import Install
from ..statusdb import StatusDB


def install_game(status_db, game_info):
    remote_basedir = config.get_remote_basedir()
    source = f'{remote_basedir}/{game_info["package_name"]}'
    dest = config.get_games_install_basedir() / game_info['id']
    dest.mkdir(parents=True, exist_ok=True)
    title = 'Installing game...'
    task = functools.partial(Install, source, dest)
    processor.process_task(title, task)
    status_db.set_installed(game_info)


def install(game_id):
    game_db = gamedb.GameDB()
    game_info = game_db.get_game_info(game_id)
    status_db = StatusDB()
    if status_db.is_installed(game_info):
        # games is already installed
        return
    install_game(status_db, game_info)


if __name__ == "__main__":
    import sys
    install(sys.argv[1])