parser = argparse.ArgumentParser() subparsers = parser.add_subparsers() def _run_debug_server(args): logging.basicConfig(level="DEBUG", stream=sys.stderr) app.run(debug=True) main_parser = subparsers.add_parser("debug", help="Run debug server") main_parser.set_defaults(func=_run_debug_server) def _run_scgi(args): from flup.server.scgi import WSGIServer WSGIServer(app, bindAddress=args.socket).run() scgi_parser = subparsers.add_parser("scgi", help="Run scgi server") scgi_parser.add_argument("-s", "--socket") scgi_parser.set_defaults(func=_run_scgi) app.config["DATA_DIR"] = "/var/www/tracebacks" app.config["ACCESS_CONTROL_ALLOW_ANY_ORIGIN"] = True if __name__ == "__main__": args = parser.parse_args() sys.exit(args.func(args))
def post_helpdesk(): desc = request.form["desc"] captcha = request.form["hmm"] if captcha == "scrop": status = "success" if send_email(request.form) else "fail" else: status = "fail" # should we bother restoring other fields beside desc? return redirect("/helpdesk?status={}&desc={}".format(status, desc)) if __name__ == "__main__": app.config["DEBUG"] = True # tension between this and cfg function... conf = ConfigFactory.parse_file("cfg.conf") logfile = conf.get("logfile", "/tmp/cgi.log") logging.basicConfig(filename=logfile, level=logging.DEBUG) app.config["DATA_DIR"] = conf["guestbook_dir"] app.config["TRELLO_EMAIL"] = conf["trello_email"] app.config["MAILGUN_URL"] = conf["mailgun_url"] app.config["MAILGUN_KEY"] = conf["mailgun_key"] logging.debug("Running with data_dir=", app.config["DATA_DIR"]) logging.debug(app.config) app.run()