From 4d5d8940cb1afcd8b2989b2deab414d73bce35df Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Sat, 27 Sep 2025 12:00:50 +0200 Subject: [PATCH] remove custom commands --- gamiki/support/commands.py | 80 +++++++++++++++---------------- gamiki/support/custom_commands.py | 49 ------------------- 2 files changed, 38 insertions(+), 91 deletions(-) delete mode 100644 gamiki/support/custom_commands.py diff --git a/gamiki/support/commands.py b/gamiki/support/commands.py index 56ddf56..262e6b7 100644 --- a/gamiki/support/commands.py +++ b/gamiki/support/commands.py @@ -3,30 +3,33 @@ from shutil import which from os import environ from pathlib import PurePath -import gamiki.support.custom_commands as custom +__programs__: dict = { } + +def program(program: str) -> str: + global __programs__ + + if (program not in __programs__): + __programs__[program] = which(program) + + return __programs__[program] def video(file: PurePath) -> int: - cmd, env = custom.video(file) - if (not cmd): - prog = custom.program("mpv") - if (prog): - cmd = [ prog, "--fullscreen" ] - else: - raise RuntimeError("Video player not found") - - cmd.append(file.as_posix()) + cmd = None + if (program("mpv")): + cmd = [ "mpv", "--fullscreen", file.as_posix() ] + elif (program("mplayer")): + cmd = [ "mplayer", "-fs", file.as_posix() ] + else: + raise RuntimeError("Video player (mpv or mplayer) not found") - return run(cmd, env=env).returncode + return run(cmd).returncode def dosbox(dir: PurePath, link: PurePath, opt: str = None) -> int: - - cmd, env = custom.cmd("dosbox", link, None) - if (not cmd): - prog = custom.program("dosbox") - if (prog): - cmd = [ prog ] - else: - raise RuntimeError("DosBox not found") + prog = program("dosbox") + if (prog): + cmd = [ prog ] + else: + raise RuntimeError("DosBox not found") base = dir.joinpath("base.conf") if (base.exists()): @@ -47,7 +50,6 @@ def dosbox(dir: PurePath, link: PurePath, opt: str = None) -> int: return run(cmd, cwd=dir, env=env).returncode def wine(dir: PurePath, link: PurePath, opt: str = None) -> int: - if (opt): wine_bat = dir.joinpath(f"wine-{opt}.bat") else: @@ -55,14 +57,13 @@ def wine(dir: PurePath, link: PurePath, opt: str = None) -> int: wine_prefix = dir.joinpath("wine.prefix") - cmd, env = custom.cmd("wine", wine_bat, link, wine_prefix) - if (not cmd): - prog = custom.program("wine") - if (prog): - cmd = [ prog, wine_bat.as_posix() ] - env["WINEPREFIX"] = wine_prefix.as_posix() - else: - raise RuntimeError("wine not found") + prog = program("wine") + env = environ.copy() + if (prog): + cmd = [ prog, wine_bat.as_posix() ] + env["WINEPREFIX"] = wine_prefix.as_posix() + else: + raise RuntimeError("wine not found") return run(cmd, cwd=dir, env=env).returncode @@ -76,22 +77,17 @@ def qemu(dir: PurePath, link: PurePath, opt: str = None) -> int: if (not qemu_conf.exists()): return 404; - cmd, env = custom.cmd("qemu", qemu_conf, link) - if (not cmd): - prog = custom.program("qemu") - if (prog): - # TODO: port qemu.sh in python? - cmd = [ "qemu.sh", qemu_conf.as_posix() ]; - else: - raise RuntimeError("qemu not found") + # TODO: port qemu.sh in python? + prog = program("qemu.sh") + if (prog): + cmd = [ "qemu.sh", qemu_conf.as_posix() ]; + else: + raise RuntimeError("qemu.sh not found") - return run(cmd, cwd=dir, env=env).returncode + return run(cmd, cwd=dir).returncode def start_sh(start: PurePath) -> int: + cmd = [ start.as_posix() ] - cmd, env = custom.cmd("start_sh", start, None) - if (not cmd): - cmd = [ start.as_posix() ] - - return run(cmd, cwd=start.parent, env=env).returncode + return run(cmd, cwd=start.parent).returncode diff --git a/gamiki/support/custom_commands.py b/gamiki/support/custom_commands.py deleted file mode 100644 index d08d236..0000000 --- a/gamiki/support/custom_commands.py +++ /dev/null @@ -1,49 +0,0 @@ -from subprocess import run -from shutil import which -from os import environ -from pathlib import PurePath - -__programs__: dict = { } - -def program(program: str) -> str: - global __programs__ - - if (program not in __programs__): - __programs__[program] = which(program) - - return __programs__[program] - -def video(file: PurePath) -> (list, dict): - cmd = None - env = environ.copy() - if (program("local.sh")): - cmd = [ "local.sh", "mpv", "--fullscreen", file.as_posix() ] - - return cmd, env - -def cmd(prog:str, t:PurePath, lnk:PurePath, pre:PurePath=None) -> (list, dict): - # t: the target to start - # lnk: link to library directory - # pre: the WINEPREFIX (wine only) - - cmd = None - env = environ.copy() - - # All the custom procedures requires app.sh - if (not program("app.sh")): - return cmd, env - - if (prog == "dosbox"): - cmd = [ program("app.sh"),"--wait", "dosbox", "--ddlink", t.as_posix() ] - elif (prog == "wine"): - cmd = [ - program("app.sh"), "--wait", "wine", "--ddlink", t.as_posix(), - "--prefix", pre.as_posix() - ] - elif (prog == "qemu"): - cmd = [ program("app.sh"), "--wait", "qemu", "--ddlink", t.as_posix() ] - elif (prog == "start_sh"): - cmd = [ program("app.sh"), "games", "--dlink", t.as_posix() ] - - return cmd, env - -- 2.27.0