2014-10-05 16:25:31 +08:00
|
|
|
import sys
|
2014-12-08 19:22:02 +08:00
|
|
|
from inspect import isclass
|
2014-10-05 16:25:31 +08:00
|
|
|
|
2014-10-25 16:31:34 +08:00
|
|
|
from artiq.management import pyon
|
2014-12-08 19:22:02 +08:00
|
|
|
from artiq.management.file_import import file_import
|
|
|
|
from artiq.language.context import AutoContext
|
|
|
|
from artiq.management.dpdb import DeviceParamDB
|
|
|
|
|
|
|
|
|
|
|
|
def run(dpdb, file, unit, function):
|
|
|
|
module = file_import(file)
|
|
|
|
if unit is None:
|
|
|
|
units = [v for k, v in module.__dict__.items()
|
|
|
|
if k[0] != "_"
|
|
|
|
and isclass(v)
|
|
|
|
and issubclass(v, AutoContext)
|
|
|
|
and v is not AutoContext]
|
|
|
|
if len(units) != 1:
|
|
|
|
raise ValueError("Found {} units in module".format(len(units)))
|
|
|
|
unit = units[0]
|
|
|
|
else:
|
|
|
|
unit = getattr(module, unit)
|
|
|
|
unit_inst = unit(dpdb)
|
|
|
|
f = getattr(unit_inst, function)
|
|
|
|
f()
|
2014-10-05 16:25:31 +08:00
|
|
|
|
|
|
|
|
|
|
|
def put_object(obj):
|
2014-10-25 16:31:34 +08:00
|
|
|
ds = pyon.encode(obj)
|
2014-10-05 16:25:31 +08:00
|
|
|
sys.__stdout__.write(ds)
|
|
|
|
sys.__stdout__.write("\n")
|
|
|
|
sys.__stdout__.flush()
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
sys.stdout = sys.stderr
|
|
|
|
|
2014-12-08 19:22:02 +08:00
|
|
|
devices = pyon.load_file(sys.argv[1])
|
|
|
|
parameters = pyon.load_file(sys.argv[2])
|
|
|
|
dpdb = DeviceParamDB(devices, parameters)
|
|
|
|
|
2014-10-05 16:25:31 +08:00
|
|
|
while True:
|
|
|
|
line = sys.__stdin__.readline()
|
2014-10-25 16:31:34 +08:00
|
|
|
obj = pyon.decode(line)
|
2014-10-05 16:25:31 +08:00
|
|
|
put_object("ack")
|
|
|
|
|
|
|
|
try:
|
2014-12-08 19:22:02 +08:00
|
|
|
run(dpdb, **obj)
|
2014-10-05 16:25:31 +08:00
|
|
|
except Exception as e:
|
|
|
|
put_object({"status": "failed", "message": str(e)})
|
|
|
|
else:
|
|
|
|
put_object({"status": "ok"})
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|