summaryrefslogtreecommitdiffstats
path: root/gamechestcli/gamechest/cliactions/remove.py
blob: 6573aff1f4ae7b6c4cbeccbe7661e4dc9561584d (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
33
34
35
36
37
38
import contextlib
import functools
import selectors

from rich import print
from rich.progress import Progress as RichProgress

from .. import gamedb, processor
from ..gameconfig import config
from ..runners.remove import Remove
from ..statusdb import StatusDB


def remove_game(status_db, game_info):
    remote_basedir = config.get_remote_basedir()
    path = (
        config.get_games_install_basedir()
        / game_info['id']
    )
    title = 'Removing game...'
    task = functools.partial(Remove, path)
    processor.process_task(title, task)
    status_db.set_uninstalled(game_info)


def remove(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):
        remove_game(status_db, game_info)
    else:
        print('Game not installed')


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