def run(self, source): set_classes(self.options) # If this is the first real node inside a graph figure, put the SVG # directly inside parent = self.state.parent if _is_graph_figure(parent): svg = dot2svg.dot2svg(source, attribs=' class="{}"'.format(' '.join(['m-graph'] + self.options.get('classes', [])))) node = nodes.raw('', svg, format='html') return [node] # Otherwise wrap it in a <div class="m-graph"> svg = dot2svg.dot2svg(source) container = nodes.container(**self.options) container['classes'] = ['m-graph'] + container['classes'] node = nodes.raw('', svg, format='html') container.append(node) return [container]
def do_POST(self): global rootnode if 1: ctype, pdict = cgi.parse_header(self.headers.getheader('content-type')) if ctype == 'multipart/form-data': postvars = cgi.parse_multipart(self.rfile, pdict) elif ctype == 'application/x-www-form-urlencoded': length = int(self.headers.getheader('content-length')) postvars = cgi.parse_qs(self.rfile.read(length), keep_blank_values=1) else: postvars = {} self.end_headers() dot_graph = postvars['dot_graph'][0] print "dot graph: ", dot_graph svg_graph = dot2svg.dot2svg(dot_graph) svg_graph = svg_graph[svg_graph.find('<svg'):] print "svg graph: ", svg_graph self.wfile.write(svg_graph)
def do_POST(self): """ Function executing some requests """ # get the variables sent to the server ctype, pdict = cgi.parse_header(self.headers.getheader("content-type")) if ctype == "multipart/form-data": postvars = cgi.parse_multipart(self.rfile, pdict) elif ctype == "application/x-www-form-urlencoded": length = int(self.headers.getheader("content-length")) postvars = cgi.parse_qs(self.rfile.read(length), keep_blank_values=1) else: postvars = {} self.end_headers() path = urlparse.urlparse(self.path).path print path if path == "/plasm/graph": # get the SVG of a given graph (sent as JSON) if PLASM_MANAGER._sched: PLASM_MANAGER._sched.stop() json_plasm = postvars["json_plasm"][0] # convert the plasm to SVG and send it back to the GUI if postvars.has_key("width") and postvars.has_key("height"): svg_graph = dot2svg.dot2svg( ecto_json.JsonToDot( json_plasm, round(float(postvars["width"][0]), 0), round(float(postvars["height"][0]), 0) ) ) else: svg_graph = dot2svg.dot2svg(ecto_json.JsonToDot(json_plasm)) svg_graph = svg_graph[svg_graph.find("<svg") :] self.wfile.write(svg_graph) elif path == "/plasm/load": # get the SVG of a given graph (sent as JSON) if PLASM_MANAGER._sched: PLASM_MANAGER._sched.stop() # load a specific plasm in a given file and send it back to the GUI file_path = postvars["file_path"][0] plasm_name = postvars["plasm_name"][0] try: import imp module_file = open(file_path) uploaded_module = imp.load_source("uploaded_module", file_path) plasm = uploaded_module.__dict__[plasm_name] except Exception as inst: print "Error in loading the module path: " print inst return # convert the plasm to JSON json_plasm = ecto_json.PlasmToJson(plasm) self.wfile.write(json_plasm) elif path == "/plasm/run": # run a specific graph (sent as JSON) PLASM_MANAGER._is_running = True # get the plasm as JSON and execute it PLASM_MANAGER._plasm = ecto_json.JsonToPlasm(postvars["json_plasm"][0]) # Execute the plasm in a different thread if PLASM_MANAGER._sched: PLASM_MANAGER._sched.stop() PLASM_MANAGER._plasm.execute(0) elif path == "/plasm/pause": # stop any running plasm if PLASM_MANAGER._sched: PLASM_MANAGER._sched.stop() PLASM_MANAGER._is_running = False elif path == "/plasm/update": # update the parameters of the running plasm if not PLASM_MANAGER._plasm: return # get the parameter values that got updated json_parameter = json.loads(postvars["json_parameter"][0], object_hook=ecto_json._decode_dict) name = json_parameter["name"] value = json_parameter["value"] cell_id = json_parameter["cell_id"] # update the parameter of the corresponding cell for cell in PLASM_MANAGER._plasm.cells(): if (not hasattr(cell, "id")) or (cell.id != cell_id): continue for param in cell.params: if param.key() != name: continue tendril = param.data() t = type(tendril.val) try: tendril.set(t(value)) except ValueError, e: print e break break