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()):
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:
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
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
+++ /dev/null
-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
-