import sys sys.path.append("interface/HUTN") from hutn_compiler.compiler import main as do_compile address = "http://127.0.0.1:8001" def get_model_constructor(code): # First change multiple spaces to a tab code_fragments = code.split("\n") code_fragments = [i for i in code_fragments if i.strip() != ""] code_fragments = [i.replace(" ", "\t") for i in code_fragments] initial_tabs = min([len(i) - len(i.lstrip("\t")) for i in code_fragments]) code_fragments = [i[initial_tabs:] for i in code_fragments] code_fragments.append("") code = "\n".join(code_fragments) with open("__model.mvc", "w") as f: f.write(code) f.flush() return get_model_constructor_2("__model.mvc") def get_model_constructor_2(f): return do_compile(f, "interface/HUTN/grammars/modelling.g", "M") + ["exit"] commands = [ "root", "root", "root", "model_add", "SimpleClassDiagrams", "CausalBlockDiagrams", ] + get_model_constructor(open("integration/code/cbd_design.mvc", "r").read()) + [ "model_add", "SimpleClassDiagrams", "MM_rendered_graphical", ] + get_model_constructor(open("models/MM_rendered_graphical.mvc", "r").read()) + [ "model_add", "CausalBlockDiagrams", "my_CBD", ] + get_model_constructor(open("integration/code/my_cbd.mvc", "r").read()) + [ "model_list", "transformation_add_MT_language", "CausalBlockDiagrams", "MM_rendered_graphical", "", "CBD_RAM", "model_modify", "__merged_CBD_RAM", "instantiate", "Association", "TracabilityLink", "CausalBlockDiagrams/Block", "MM_rendered_graphical/Group", "exit", "transformation_RAMify", "__merged_CBD_RAM", "CBD_RAM", "transformation_add_MT", "CBD_RAM", "CausalBlockDiagrams", "MM_rendered_graphical", "", "CausalBlockDiagrams", "MM_rendered_graphical", "", "render_graphical_CBD", ] + get_model_constructor(open("models/CBD_mapper.mvc", "r").read()) + [ ] import urllib2 import urllib import json import random taskname = str(random.random()) INIT_TIMEOUT = 9999 urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": '"%s"' % taskname, "taskname": "task_manager"})), timeout=INIT_TIMEOUT).read() urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "data": json.dumps(commands), "taskname": taskname})), timeout=INIT_TIMEOUT).read()