doomcc/dcc/dsda.py

58 lines
1.9 KiB
Python
Raw Normal View History

2025-04-22 01:28:36 -04:00
import dcc.config
import dcc.doom_base
import os
import re
import shutil
2025-04-22 01:28:36 -04:00
import subprocess
import zipfile
class DSDA(dcc.doom_base.WadMap):
def get_parser(self, prog_name):
parser = super().get_parser(prog_name)
parser.add_argument("-s", "--single", action="store_true")
parser.add_argument("-a", "--abbreviation")
2025-04-22 01:28:36 -04:00
return parser
def take_action(self, parsed_args):
dip = dcc.config.DemoInPath(parsed_args.wad, parsed_args.map, parsed_args.name)
dtp = dcc.config.DsdaTextPath(parsed_args.wad, parsed_args.map, parsed_args.name)
2025-04-22 01:28:36 -04:00
if not dtp.exists():
command = [dcc.config.DSDA]
if shutil.which("xvfb-run") is not None:
command = ["xvfb-run"] + command
# TODO: negative tics should seek from the end, but this doesn't seem to work.
subprocess.run(command +
2025-04-22 01:28:36 -04:00
dcc.config.DsdaPreamble(parsed_args.wad, parsed_args.map) +
["-fastdemo", dip, "-nosound", "-skiptic", "999999999", "-export_text_file"])
2025-04-22 01:28:36 -04:00
editor = "nano"
if "EDITOR" in os.environ:
editor = os.environ["EDITOR"]
subprocess.run([editor, dtp])
if parsed_args.abbreviation:
fh1 = parsed_args.abbreviation
if not parsed_args.single:
fh1 += parsed_args.map
else:
fh1 = parsed_args.wad[0:2] + parsed_args.map
if parsed_args.single:
fh1 = parsed_args.wad[0:min(len(parsed_args.wad), 4)]
2025-04-22 01:28:36 -04:00
fh2 = ""
with open(dtp, mode="r") as f:
for line in f:
if line[0:4] == "Time":
m = re.search("[^0-9]*([0-9]*):([0-9]*).[0-9]*", line)
if m is None:
continue
fh2 = m[1]+m[2]
if len(fh2)%2==1:
fh2 = "0" + fh2
break
2025-04-22 01:28:36 -04:00
if not fh2:
sys.exit("Failed to match any line in {} against Time regex.".format(dtp))
# TODO: demo names other than uv-max.
fnf = fh1 + "-" + fh2 + ".zip"
with zipfile.ZipFile(dcc.config.DEMOS.joinpath(parsed_args.wad).joinpath(fnf), mode="w") as zf:
zf.write(dip, arcname=dip.name)
zf.write(dtp, arcname=dtp.name)