Commit 0b04b538 authored by dylan grafmyre's avatar dylan grafmyre
Browse files

make supervisor

parent f5d50f8c
......@@ -4,8 +4,10 @@ PYTHON_BIN?=./env/scripts/python
GARYSMOD_DIR?=D:\\Steam\\steamapps\\common\\GarrysMod\\
VBIN_DIR?=$(GARYSMOD_DIR)bin\\
MOD_DIR?=$(GARYSMOD_DIR)garrysmod\\
MOUNT_DIR?=.\\
VBIN_FLAGS?=-game $(MOD_DIR)
SUPERVISE_V_BIN?=./contrib/supervise-v
BSP_BIN?=$(VBIN_DIR)vbsp.exe
BSP_FLAGS?=$(VBIN_FLAGS)
VIS_BIN?=$(VBIN_DIR)vvis.exe
......@@ -17,10 +19,13 @@ BSPZIP_BIN?=$(VBIN_DIR)bspzip.exe
BSPZIP_FLAGS?=
%.bsp: %.vmf
$(BSP_BIN) $(BSP_FLAGS) $(basename $^) # writes bsp
$(VIS_BIN) $(VIS_FLAGS) $(basename $^) # depends on .prt, r/w bsp
$(RAD_BIN) $(RAD_FLAGS) $(basename $^) # reads lights.rad, r/w bsp
cp $@ $(MOD_DIR)maps\\$(notdir $@)
# vbsp: writes bsp
# vvis: depends on .prt, r/w bsp
# vrad: reads lights.rad, r/w bsp
$(SUPERVISE_V_BIN) $(BSP_BIN) $(BSP_FLAGS) $(basename $^)
$(SUPERVISE_V_BIN) $(VIS_BIN) $(VIS_FLAGS) $(basename $^)
$(SUPERVISE_V_BIN) $(RAD_BIN) $(RAD_FLAGS) $(basename $^)
cp $@ $(MOUNT_DIR)maps\\$(notdir $@)
%.prt: %.bsp
@test -f $@ || rm -f $(basename $@).bsp
......@@ -44,6 +49,3 @@ install: ttt_terrorcon_v2_p.bsp
$(PYTHON_BIN) ./contrib/bspzip-lint $^ 2> $@
.PHONY: lint
lint: ttt_terrorcon_v2.lint
$(PYTHON_BIN) ./contrib/vmt-lint 2> $@
#!/usr/bin/env python3
"""
supervise-v - host a vavle bsp modifying process, and return exitcode 2
if the bsp file did not change
arguments given in form
<prog> <args> <mapname>
"""
import sys
import os
import hashlib
import subprocess
import logging
import collections
def hashfile(file_, bufsize=None, hashfunc=hashlib.sha1):
if bufsize is None:
bufsize = 1<<16
obj = hashfunc()
while True:
data = file_.read(bufsize)
if not data:
break
obj.update(data)
return obj
class FileFingerprint:
def __init__(self, name):
self.name = name
self.stat = os.stat(name)
self.hash = self.hashfile()
def hashfile(self):
logging.info('%r: hashing ...', self.name)
with open(self.name, 'rb') as fh:
hash_ = hashfile(fh)
logging.info('%r: hashing ... done: %r', self.name, hash_.hexdigest())
return hash_
def __eq__(self, other):
if other.stat.st_size != self.stat.st_size:
return False
return other.hash.digest() == self.hash.digest()
class Argset:
vmf_hash = None
bsp_hash = None
def __init__(self, argv=None):
if argv is None:
argv = sys.argv
self.prog = os.path.basename(argv[0])
self.bin = argv[1]
self.file = argv[-1]
self.vargs = argv[2:-1]
self.has_vmf = os.path.isfile(self.vmf)
self.has_bsp = os.path.isfile(self.bsp)
def __repr__(self):
return '<{s.__class__.__name__} {t}>'.format(
s=self,
t=self.__dict__
)
@property
def vmf(self):
return '{}.vmf'.format(self.file)
@property
def bsp(self):
return '{}.bsp'.format(self.file)
@property
def name(self):
return os.path.basename(self.bin)
BELOW_NORMAL_PRIORITY_CLASS = 0x00004000
def main():
logging.basicConfig(level=logging.INFO)
argset = Argset(sys.argv)
fp = collections.defaultdict(lambda:[None, None])
#if argset.has_vmf:
# fp['vmf'][0] = FileFingerprint(argset.vmf)
if argset.has_bsp:
fp['bsp'][0] = FileFingerprint(argset.bsp)
execve = [argset.bin] + argset.vargs + [argset.file]
logging.info('execve: %r', execve)
popen = subprocess.run(
execve,
creationflags=BELOW_NORMAL_PRIORITY_CLASS
)
#if argset.has_vmf:
# fp['vmf'][1] = FileFingerprint(argset.vmf)
if argset.has_bsp:
fp['bsp'][1] = FileFingerprint(argset.bsp)
bsp_changed = (fp['bsp'][0] == fp['bsp'][1])
exit(bsp_changed)
if __name__ == '__main__':
main()
Supports Markdown
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