summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvg <vgm+dev@devys.org>2024-05-24 16:25:40 +0200
committervg <vgm+dev@devys.org>2024-05-24 16:25:40 +0200
commitba9cb6210b1900f24c940c5b579168dd6fd1a7f5 (patch)
treeb86992be4790e1c08960ab640004f9c0e4cf40d3
parent34345e1ced10f1da6461e428acd04f3f6f1b0622 (diff)
downloadgamechest-ba9cb6210b1900f24c940c5b579168dd6fd1a7f5.tar.gz
gamechest-ba9cb6210b1900f24c940c5b579168dd6fd1a7f5.tar.bz2
gamechest-ba9cb6210b1900f24c940c5b579168dd6fd1a7f5.zip
git-sync on seele
-rw-r--r--gamechestcli/gamechest/cliactions/run.py30
-rw-r--r--gamechestcli/gamechest/gamedb.py18
2 files changed, 35 insertions, 13 deletions
diff --git a/gamechestcli/gamechest/cliactions/run.py b/gamechestcli/gamechest/cliactions/run.py
index d6791d0..cf5ac43 100644
--- a/gamechestcli/gamechest/cliactions/run.py
+++ b/gamechestcli/gamechest/cliactions/run.py
@@ -1,18 +1,46 @@
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('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('INFO: {profile_lockdir} removed')
def run(game_id, profile_id):
diff --git a/gamechestcli/gamechest/gamedb.py b/gamechestcli/gamechest/gamedb.py
index bec90d3..d372089 100644
--- a/gamechestcli/gamechest/gamedb.py
+++ b/gamechestcli/gamechest/gamedb.py
@@ -27,24 +27,18 @@ 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 = [
*[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'])],
]
-
return command
def get_ids(self):