from servicelib.process import Process def mapd(context, inputFile, outputFormat, options): inp = context.get_data(inputFile) out = context.create_result(outputFormat) plan_file = context.create_temp_file() class p(Process): max_output_size = 10 * 1024 * 1024 # extend default of 10 KB of stdout def __init__(self): cmd = [ "/usr/local/bin/mir", str(inp), str(out.path), "--dump-plan-file={}".format(plan_file), ] for k, v in options.items(): if not isinstance(v, list): v = [v] cmd.append("--{}={}".format(k, "/".join([str(x) for x in v]))) env = {"MIR_DEBUG": "1", "MIR_CACHE_PATH": "/tmp/cache/mir"} super(p, self).__init__("mapd", cmd, env) def results(self): with open(plan_file, "rt") as f: out["plan"] = f.read() return out return context.spawn_process(p()) def main(): from servicelib import service service.start_services( {"name": "mapd", "execute": mapd,} )