class ProvisionWorkflowForm(Form): # print # "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++",Form filename = "abc" dir = path_expand( cm_config_server().get("cloudmesh.server.workflows.path")) # not so nice cludge, ask for location of statcic instead web_pwd = Shell.pwd().strip() basename = "/static/{0}/{1}".format(dir, filename) print "BBBB", basename try: with open("{2}/{0}.{1}".format(basename, "diag", web_pwd), "r") as f: data = f.readlines()[1:-1] default = "".join(data) except: print "Error: diagram not found" default = "" default = default.split("//graph") filename = TextField("Filename", default=filename) # properties = TextAreaField("Workflow", default=default[0]) # workflow = TextAreaField("Workflow", default=default[1]) properties = TextAreaField("Workflow", default="fake") workflow = TextAreaField("Workflow", default="fake")
def display_provision_workflow_form(): form = ProvisionWorkflowForm(csrf=False) dir = path_expand( cm_config_server().get("cloudmesh.server.workflows.path")) filename = "abc" web_pwd = Shell.pwd().strip() print "PWD", web_pwd basename = "/static/{0}/{1}".format(dir, filename,) # if form.validate_on_submit(): # print "SKIP" try: with open("{2}/{0}.{1}".format(basename, "diag", web_pwd), "w") as f: # print "########################################################################################" # print "aaaaaa"+form.workflow.data+"bbb" f.write("blockdiag {\n") if form.workflow.data == "": form.work.data = f.work.default if form.properties.data == "": form.properties.data = form.properties.default f.write(form.properties.data) f.write("//graph\n") f.write(form.workflow.data) f.write("\n}") # print # "########################################################################################" print form.workflow except: print "file does not exists" print "{0}.{1}".format(basename, diagram_format) print "OOOO", basename Shell.blockdiag("--ignore-pil", "-Tsvg", "-o", "{2}/{0}.{1}".format(basename, diagram_format, web_pwd), "{2}/{0}.{1}".format(basename, "diag", web_pwd)) # Shell.blockdiag("-Tpng", # "-o", "." + dir + filename + ".png", # "." + dir + filename + ".diag") # else: # flash("Wrong submission") inventory.refresh() return render_template("provision_workflow.html", workflow=form.workflow.data, form=form, pwd=pwd, diagram="{0}.{1}".format(basename, diagram_format), inventory=inventory)