Compare commits

...

2 commits

Author SHA1 Message Date
d585c1529d Merge pull request 'Use os.execv instead of subprocess.run when no further action is taken.' (#11) from iss10 into trunk
Reviewed-on: #11
2025-12-24 23:20:33 +00:00
edbf4f2a0e Use os.execv instead of subprocess.run when no further action is taken.
This prevents the underlying file from being marked busy while a
long-running action is happening (e.g. eureka is open).
2025-12-24 18:09:49 -05:00
7 changed files with 23 additions and 25 deletions

View file

@ -1,6 +1,6 @@
import dcc.doom_base
import dcc.config
import subprocess
import os
class Eureka(dcc.doom_base.WadMap):
@ -24,7 +24,7 @@ class Eureka(dcc.doom_base.WadMap):
if complevel == "11" or complevel == "21":
port = "mbf"
subprocess.run(
os.execvp("eureka",
["eureka"] + ["-iwad", iwad] + ["-w", parsed_args.map]
+ ["-p", port] + [mw]
)

View file

@ -1,8 +1,8 @@
import contextlib
import dcc.config
import dcc.doom_base
import os
import shutil
import subprocess
import tempfile
@ -18,7 +18,7 @@ class Fabricate(dcc.doom_base.WadMap):
command = [self.dsda]
if not parsed_args.fg and shutil.which("xvfb-run") is not None:
command = ["xvfb-run"] + command
subprocess.run(
os.execvp(command[0],
command + self.dsda_preamble()
+ ["-timedemo", self.demo_in_path()]
+ ["-viddump", self.video_path()]

View file

@ -1,8 +1,8 @@
import dcc.config
import dcc.doom_base
import subprocess
import os
class PB(dcc.doom_base.WadMap):
def take_action(self, parsed_args):
subprocess.run(["ffplay", self.video_path()])
os.execvp("ffplay", ["ffplay", self.video_path()])

View file

@ -1,8 +1,8 @@
import dcc.config
import dcc.doom_base
import subprocess
import os
class Play(dcc.doom_base.WadMap):
def take_action(self, parsed_args):
subprocess.run([self.dsda] + self.dsda_preamble())
os.execv(self.dsda, [self.dsda] + self.dsda_preamble())

View file

@ -1,11 +1,11 @@
import dcc.config
import dcc.doom_base
import subprocess
import os
class Record(dcc.doom_base.WadMap):
def take_action(self, parsed_args):
subprocess.run(
os.execv(self.dsda,
[self.dsda] + self.dsda_preamble() +
["-record", self.demo_out_path()]
)

View file

@ -1,7 +1,6 @@
import dcc.doom_base
import pathlib
import os
import subprocess
import time
@ -42,7 +41,7 @@ class RIB(dcc.doom_base.WadMap):
+ f"and map {parsed_args.map} (tried to look in {demodir})"
)
subprocess.run(
os.execv(self.dsda,
[self.dsda] + self.dsda_preamble(warp=False)
+ ["-playdemo", demo]
+ ["-skiptic", str(-35 * parsed_args.secs_before)]

View file

@ -1,16 +1,16 @@
import cliff.app
import dcc.play
import logging
import os
import mockito.matchers
import pathlib
import subprocess
import tempfile
logger = logging.getLogger(__name__)
def test_play(when):
def test_play(expect):
with tempfile.TemporaryDirectory() as td:
tdp = pathlib.Path(td)
tdp.joinpath("config.toml").write_text(
@ -26,9 +26,14 @@ def test_play(when):
scp.mkdir()
scp.joinpath("config.toml").touch()
scp.joinpath("scythe.wad").touch()
zero = subprocess.CompletedProcess
zero.returncode = 0
when(subprocess).run(
dcc.play.Play.__init__ = lambda self: None
dcc.play.Play.get_epilog = lambda self: ""
rig = dcc.play.Play()
rig._hooks = []
parser = rig.get_parser("test_play")
parsed_args = parser.parse_args(args=["--doom", td, "scythe", "01"])
with expect(os, times=1).execv(
tdp.joinpath("dsda-doom").joinpath("exe"),
[
tdp.joinpath("dsda-doom").joinpath("exe"),
"-iwad",
@ -42,11 +47,5 @@ def test_play(when):
"-warp",
"01",
]
).thenReturn(zero)
dcc.play.Play.__init__ = lambda self: None
dcc.play.Play.get_epilog = lambda self: ""
rig = dcc.play.Play()
rig._hooks = []
parser = rig.get_parser("test_play")
parsed_args = parser.parse_args(args=["--doom", td, "scythe", "01"])
assert rig.run(parsed_args) == 0
).thenReturn(None):
assert rig.run(parsed_args) is None