def handle_names(): names = form.getfirst("names") if names == "FILE": namefn = sfn("vns.raw") if fileup.save(form, 'vnfile', namefn): return namefn else: cfg.error("Could not upload variable name file!") else: return names
def run_file(filename, environment=None): if environment is None: environment = Program(repl=False) try: with open(filename) as f: code = f.read() except FileNotFoundError: cfg.error("could not find", filename) return except PermissionError: cfg.error("insufficient permissions to read", filename) return except IOError: cfg.error("could not read", filename) return # If file read was successful, execute the code run_program(code, environment)
def run_program(code, environment=None): if environment is None: environment = Program(repl=False) try: environment.execute(code) except cfg.UserQuit: # Encountered (quit) in one of the files return except KeyboardInterrupt: cfg.error("calculation interrupted by user.") return except RecursionError: cfg.error("recursion depth exceeded.", "How could you forget to use tail calls?!") return except Exception as err: # Miscellaneous exception, probably indicates a bug in # the interpreter cfg.error(err) return # If code execution was successful, begin event loop builtin_events.event_loop(environment)
def repl(environment=None): print("Appleseed", version.VERSION) print("Type (help) for information") if environment is None: environment = Program(repl=True, max_list_items=20) instruction = input_instruction() while True: try: last_value = environment.execute(instruction) environment.global_names["_"] = last_value except KeyboardInterrupt: cfg.error("calculation interrupted by user.") except RecursionError: cfg.error("recursion depth exceeded.", "How could you forget to use tail calls?!") except cfg.UserQuit: break except Exception as err: # Miscellaneous exception, probably indicates a bug in # the interpreter cfg.error(err) break instruction = input_instruction() print("Bye!")
#!/usr/bin/python2.4 import cgi import cfg, fileup, pydida.varcmd import cgitb cgitb.enable() form = cgi.FieldStorage() sid, sdir, sfn, wfn, cfn, sx = cfg.create_session() # Update Syntax for k in "rng_mark sep_mark var_cmd_sep cmd_sep".split(): v = form.getfirst(k, '').strip() sx[k] = v and v or sx[k] # Not good - fail hard cfg.set_syntax(sdir, sx) cmds = pydida.varcmd.build_cmds(sx=sx) cfg.save_cmds(cfn, cmds.replace(sx['cmd_sep'], "\n")) # Upload data file if not fileup.save(form, "datafile", sfn("dat.org")): cfg.error("Empty file recieved!", sid) template, tproc = cfg.tmpl("din.tmpl", sid) tproc.set('cmd_file', file(cfn).read()) print "Content-Type: text/html\n" print tproc.process(template)
fcmds = file(cfn).read() pvcmds = pervar.commands(sfn("pervar"), sx).replace(sx['cmd_sep'], "\n") file(sfn("cmd"), "w").write("".join(map(eolify, (fcmds, pvcmds)))) ## Call dout pargs = " ".join((sfn("vds"), sfn("dzd"), sdir)) cmd = "python2.4 pydida/dout.py %s %s" % (pargs, cfg.optcat(*opts)) #raise cmd to_cmd, from_cmd, cmderr = os.popen3(cmd) err = cmderr.read() ## Build options if not err: optlines = "".join( file(sfn(dxx)).read().replace(sdir, "res_dir") for dxx in ("din.cmd", "diz.cmd", "dout.cmd")) file(sfn("opt"), "w").write(optlines) ######################### FORM OUTPUT ########################## if err: cfg.error(err, sid) else: template, tproc = cfg.tmpl("results", sid) print "Content-Type: text/html\n" print tproc.process(template)
opts.append(("--delim", form.getfirst("delim"))) opts.append(("--names", handle_names())) opts.append(("--start", form.getfirst("start"))) opts.append(("--miss", form.getfirst('missmark'))) opts.append(("--rowise", form.getfirst("rowise") == "yes")) opts.append(("--cmd-file", cfn)) opts.extend(cfg.sx_options(sx)) ############################ ACTION ########################## cfg.save_cmds(cfn, form.getfirst("cmd_file")) pargs = " ".join((sfn("dat.org"), sdir)) cmd = "python2.4 pydida/din.py %s %s" % (pargs, cfg.optcat(*opts)) # raise cmd to_cmd, from_cmd, cmderr = os.popen3(cmd) err = cmderr.read() ok = (not err) and int(from_cmd.readline()) ######################### FORM OUTPUT ########################## if ok: pervar.create_cmds(len(cfg.vars(sdir)), sfn("pervar")).close() print "Location: /cgi-bin/anas.py?sid=%s&action=First\n" % sid else: if err: cfg.error(err, sid) else: cfg.error(from_cmd.read(), sid)
names = form.getfirst("names", "ROW") if names == "ROW": # args['names'] = "1" # Hmm pass elif names== "GEN": args['names'] = "GEN" try: args['start'] = int(form.getfirst("start", "0")) except: raise else: args['names'] = sfn("vns.raw") if not fileup.save(form, 'vnfile', args['names']): cfg.error("Could not upload variable name file!") ### MISSING ### missmark = form.getfirst('missmark','').strip() if missmark: args['missmark'] = missmark ### ROWISE ### args['rowise'] = form.getfirst("rowise", "no") == "yes" ### Variable processing commands ### cfg.save_cmds(cfn, form.getfirst("cmd_file", "")) args['cmd_file'] = cfn