summaryrefslogtreecommitdiffstats
path: root/gamechestcli
diff options
context:
space:
mode:
Diffstat (limited to 'gamechestcli')
-rwxr-xr-xgamechestcli/__main__.py3
-rw-r--r--gamechestcli/gamechest/cliactions/run.py31
-rw-r--r--gamechestcli/gamechest/gameconfig.py5
-rw-r--r--gamechestcli/gamechest/gamedb.py29
-rw-r--r--gamechestcli/gamechest/runners/extract.py4
5 files changed, 53 insertions, 19 deletions
diff --git a/gamechestcli/__main__.py b/gamechestcli/__main__.py
index 73d5bab..8452b99 100755
--- a/gamechestcli/__main__.py
+++ b/gamechestcli/__main__.py
@@ -9,6 +9,9 @@ Usage: gamechest install <GAME_ID>
gamechest list [--installed|--not-installed]
gamechest showconfig
+Options:
+ --profile_id=<PROFILE_ID>, -p <PROFILE_ID>
+ use profile <PROFILE_ID> instead of the default one.
'''
import sys
diff --git a/gamechestcli/gamechest/cliactions/run.py b/gamechestcli/gamechest/cliactions/run.py
index d6791d0..1c55cc4 100644
--- a/gamechestcli/gamechest/cliactions/run.py
+++ b/gamechestcli/gamechest/cliactions/run.py
@@ -1,18 +1,47 @@
+import os
import subprocess
import sys
+from pathlib import Path
+from ..gameconfig import config
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'])
+ profile_dir = Path(config.get_profile_dir(profile_id))
+ profile_game_dir = profile_dir / game_info['id']
+ game_dir = config.get_games_install_basedir() / game_info['id']
+ # note: glob('*/') globs regular files too, thus I filter on is_dir.
+ game_dir = list(item
+ for item in game_dir.glob('*') if item.is_dir())[-1]
+ game_dir = Path(game_dir)
#tools_bin_path = config.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)
+ profile_lockdir = profile_dir / '.lock'
+ try:
+ profile_lockdir.mkdir(parents=True, exist_ok=False)
+ except FileExistsError:
+ print(f'ERROR: profile is already locked, {profile_lockdir}',
+ file=sys.stderr)
+ sys.exit(1)
+ try:
+ subprocess.run(
+ command,
+ env={
+ **os.environ,
+ 'PROFILE_DIR': str(profile_game_dir),
+ 'GAME_DIR': str(game_dir),
+ 'GAME_ID': game_info['id'],
+ },
+ )
+ finally:
+ profile_lockdir.rmdir()
+ print(f'INFO: {profile_lockdir} removed')
def run(game_id, profile_id):
diff --git a/gamechestcli/gamechest/gameconfig.py b/gamechestcli/gamechest/gameconfig.py
index 5e46efa..0b3d855 100644
--- a/gamechestcli/gamechest/gameconfig.py
+++ b/gamechestcli/gamechest/gameconfig.py
@@ -34,11 +34,14 @@ class GameConfig:
game_config_path.mkdir(parents=True, exist_ok=True)
game_config_filepath = game_config_path / 'config.yaml'
self.game_config_filepath = game_config_filepath
+ self.config = {}
with contextlib.ExitStack() as stack:
stack.enter_context(contextlib.suppress(FileNotFoundError))
fdin = stack.enter_context(open(game_config_filepath, 'r',
encoding='utf8'))
- self.config = yaml.safe_load(fdin)
+ # in case yaml file is empty, None will be returned, in this case
+ # fallback to empty dict.
+ self.config = yaml.safe_load(fdin) or {}
self.config = {
**DEFAULT_CONFIG_DICT,
**self.config,
diff --git a/gamechestcli/gamechest/gamedb.py b/gamechestcli/gamechest/gamedb.py
index bec90d3..1f9e8d8 100644
--- a/gamechestcli/gamechest/gamedb.py
+++ b/gamechestcli/gamechest/gamedb.py
@@ -27,24 +27,25 @@ class GameDB:
def get_game_command(self, profile_id, game_id=None):
game_info = self.get_game_info(game_id)
game_mods = game_info.get('mods', [])
- game_mods += ['locked-run-profiledir']
-
- game_dir = config.get_games_install_basedir() / game_info['id']
- # note: glob('*/') globs regular files too, thus I filter on is_dir.
- game_dir = list(item
- for item in game_dir.glob('*') if item.is_dir())[-1]
-
+ #game_mods += ['locked-run-profiledir']
+ #game_dir = config.get_games_install_basedir() / game_info['id']
+ ## note: glob('*/') globs regular files too, thus I filter on is_dir.
+ #game_dir = list(item
+ # for item in game_dir.glob('*') if item.is_dir())[-1]
tools_bin_path = config.get_games_saves_tools_bin_path()
- profile_dir = config.get_profile_dir(profile_id)
-
+ #profile_dir = config.get_profile_dir(profile_id)
+ command_from_game_info = [
+ f'{tools_bin_path}/runners/{game_info["command"][0]}',
+ *game_info['command'][1:],
+ ] if game_info.get('command') else [
+ f'{tools_bin_path}/runners/run-{game_info["id"]}',
+ ]
command = [
+ # mods
*[f'{tools_bin_path}/mod-{item}' for item in game_mods],
- profile_dir,
- game_dir,
- *[item if index > 0 else f'{tools_bin_path}/runners/{item}'
- for index, item in enumerate(game_info['command'])],
+ # runner
+ *command_from_game_info,
]
-
return command
def get_ids(self):
diff --git a/gamechestcli/gamechest/runners/extract.py b/gamechestcli/gamechest/runners/extract.py
index 6f13d89..4e538ef 100644
--- a/gamechestcli/gamechest/runners/extract.py
+++ b/gamechestcli/gamechest/runners/extract.py
@@ -14,8 +14,6 @@ class Extract(RunnerBase):
_progress_re = re.compile(r'^\s*(\S+)\s+\[([^]]+)/s\]\s+ETA\s+(\S+)\s*$')
def __init__(self, src, dst):
- import sys
- print('src', src, 'dst', dst, file=sys.stderr)
common_parameters = dict(
encoding='utf8',
env={**os.environ,
@@ -43,7 +41,7 @@ class Extract(RunnerBase):
if first_word_magic == 0x4c5a4950: # lzip magic
if os.path.exists(plzip_command):
uncompress_command_to_use = [plzip_command, '--decompress']
- elif first_word_magic == 0x28B52FFD:
+ elif first_word_magic == 0x28B52FFD: # zstd magic
uncompress_command_to_use = ['zstd', '-T0', '-d', '--stdout']
self.zip_proc = subprocess.Popen(
uncompress_command_to_use,