Commit 04418fc7 authored by dylan grafmyre's avatar dylan grafmyre
Browse files

epoll-wait for resuming from lua handoff

parent 17181d75
......@@ -5,6 +5,8 @@ PROJECT_DIR?=C:\\hammer\ttt_terrorcon
PYTHON_BIN?=./env/scripts/python
SHLEX_BIN?=./contrib/shlex
SHLEX_FLAGS?=
EPOLL_THEN_BIN?=$(PYTHON_BIN) ./contrib/epoll-then
EPOLL_THEN_FLAGS?=
#SHELL=C:\\Program\ Files\\Git\\bin\\bash.exe
#.SHELLFLAGS=-c
......@@ -176,8 +178,10 @@ maps/%.bsp: %.bsp
ln -f lua/nav_generate.lua "$(MOD_DIR)/lua/autorun/runme.lua"
$(SHLEX_BIN) $(SHLEX_FLAGS) $(SHLEX_HL2LOG_FLAGS) \
"'$(GAME_DIR)$(GAME)'" -allowdebug $(VBIN_FLAGS) $(GAME_FLAGS) $(GAME_TTT_FLAGS) \
+sv_cheats 1 +nav_edit 1 +map navgen
# todo: check "$(MOD_DIR)/data/runme.txt" for content "ng_f", to trigger kill hl2.exe
+sv_cheats 1 +nav_edit 1 +map navgen || true
$(SHLEX_BIN) $(SHLEX_FLAGS) $(EPOLL_THEN_BIN) $(EPOLL_THEN_FLAGS) --literal ng_2 --file "'$(MOD_DIR)/data/runme.txt'" -- \
echo TIME TO DO THINGS &
# todo: check "$(MOD_DIR)/data/runme.txt" for content "ng_f", to trigger kill hl2.exe
cp -v "$(MOD_DIR)/maps/navgen.nav" $@
rm -v \
"$(MOD_DIR)/lua/autorun/runme.lua" \
......
#!/usr/bin/env python3
"""
epool-then - poll a file for a specific document, on match run a command
"""
import subprocess
import logging
import os
import sys
import argparse
import time
LOGGER = logging.getLogger(os.path.basename(__file__))
ARGP = argparse.ArgumentParser()
ARGP.add_argument('remainder', nargs=argparse.REMAINDER)
ARGP.add_argument('--file', required=True)
ARGP.add_argument('--literal', required=True)
ARGP.add_argument('--poll-sec', type=float, default=2)
def main(argp=None, argv=None):
if argp is None:
argp = ARGP.parse_args(argv)
if argp.remainder and argp.remainder[0] == '--':
argp.remainder = argp.remainder[1:]
logging.basicConfig(
level=logging.INFO,
)
while True:
with open(argp.file) as fh:
dat = fh.read()
match = dat == argp.literal
LOGGER.info('status: match=%s %s=%r', (match, argp.literal), argp.file, dat)
if match:
break
time.sleep(argp.poll_sec)
if argp.remainder:
execve = argp.remainder
LOGGER.info('execve=%r', execve)
return subprocess.run(execve).returncode
return 0
if __name__ == '__main__':
exit(main())
......@@ -9,6 +9,7 @@ import os
import sys
import argparse
import shutil
import re
LOGGER = logging.getLogger(os.path.basename(__file__))
......@@ -19,6 +20,8 @@ ARGP.add_argument('--tail-bin')
ARGP.add_argument('--tail', help="follow a file while supervising a subprocess")
ARGP.add_argument('remainder', nargs=argparse.REMAINDER)
RE_GITBASH_STYLE = re.compile('^/(\w)/')
def main(argp=None, argv=None):
if argp is None:
argp = ARGP.parse_args(argv)
......@@ -26,12 +29,19 @@ def main(argp=None, argv=None):
level=(logging.INFO if argp.verbose else logging.WARNING),
)
if argp.remainder and argp.remainder[0] == '--':
argp.remainder = argp.remainder[1:]
LOGGER.info('execve_orig: %r', argp.remainder)
execve = shlex.split(' '.join(argp.remainder)) # + ['&', 'exit'] windows hack to get returncode?
LOGGER.info('execve_shlex: %r', execve)
execve_sub = [
[orig, os.path.normpath(RE_GITBASH_STYLE.subn('\\1:\\\\', orig, count=1)[0])]
for orig in execve
]
execve = [
(os.path.normpath(i) if os.path.isfile(i) else i)
for i in execve
(i[1] if os.path.isfile(i[1]) else i[0])
for i in execve_sub
]
LOGGER.info('execve_shlex_normpath: %r', execve)
......@@ -54,7 +64,12 @@ def main(argp=None, argv=None):
if 'CPROGRAMFILES' in argp.tail_bin:
argp.tail_bin = argp.tail_bin.replace('CPROGRAMFILES', 'C:\\program files')
tail_popen = subprocess.Popen([argp.tail_bin, '-fn0', argp.tail], stdout=sys.stderr.buffer)
cproc = subprocess.run(execve, shell=argp.subprocess_shell)
cproc = None
try:
cproc = subprocess.run(execve, shell=argp.subprocess_shell)
except OSError as err:
LOGGER.error('%s:%s\nprogram: %r', err.__class__.__name__, err, execve[0])
return 2
if tail_popen:
tail_popen.kill()
LOGGER.info('execve_rc: %r', cproc.returncode)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment