#!/usr/bin/env python3 import sys import os p = os.path.join pUp = os.path.dirname s = False if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'): s = os.path.realpath(sys.executable) else: s = os.path.realpath(__file__) sp = pUp(s) # script start import toml import subprocess def addressStr(addr): return addr[0] + ":" + str(addr[1]) def addressSslStr(addr): return addr[0] + ":" + str(addr[1] + 1) def perr(rtn,cmd = None,op = None): if rtn == 0: return if cmd == None: cmd = [] exc = subprocess.CalledProcessError(rtn,cmd,op) raise exc def pcallStr(*args,**kwargs): proc = subprocess.Popen(*args,**kwargs, stdout=subprocess.PIPE) response = proc.stdout.read().decode("utf-8").strip("\n") rtn = proc.wait() perr(rtn,args[0]) return response def main(): print("* Parsing config ...") configFiles = ["watch.toml"] if len(sys.argv) > 1: configFiles = sys.argv[1:] length = len(configFiles) index = 0 while index < length: configFiles[index] = p(sp,"config",configFiles[index]) index += 1 config = toml.load(configFiles) for key in config["args"]: os.environ["fstream_arg_" + key] = str(config["args"][key]) length = len(config["decoder"]) index = 0 while index < length: if "values" in config: for key in config["values"]: config["decoder"][index] = config["decoder"][index].replace("$val:" +key+ "$",str(config["values"][key])) for key in os.environ: config["decoder"][index] = config["decoder"][index].replace("$env:" +key+ "$",os.environ[key]) index += 1 aes = False if "aespass" in config: if not "bufsize" in config["args"]: print("aespass is set, but args.bufsize is not.") sys.exit(1) os.environ["fstream_aespass"] = config["aespass"] os.environ["fstream_aesbuffer"] = str(config["args"]["bufsize"] - 16) aes = True address = config["address"].rsplit(":",1) address[1] = int(address[1]) procClient = subprocess.Popen([ sys.executable, p(sp,"fstream.py"), addressStr(address), "watch" ],stdout=subprocess.PIPE) if aes == True: procDecoder = subprocess.Popen(config["decoder"],stdin=subprocess.PIPE) procAes = subprocess.Popen([ sys.executable, p(sp,"util","fstream-util-aes_to_pipe.py"), addressStr(address), "watch" ],stdin=procClient.stdout,stdout=procDecoder.stdin) else: procDecoder = subprocess.Popen(config["encoder"],stdin=procClient.stdout) procDecoder.wait() main()