#!/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)
cfg.error("Could not upload variable name file!") else: return names 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: