2012-06-21 04:54:49 +00:00
|
|
|
import logging, pprint, cStringIO
|
2012-07-23 04:18:47 +00:00
|
|
|
from flask import Flask, jsonify, render_template, request, abort
|
2012-06-21 04:54:49 +00:00
|
|
|
import version, rparse
|
2012-06-21 04:25:27 +00:00
|
|
|
|
|
|
|
logging.basicConfig(level="DEBUG")
|
2012-06-19 04:57:57 +00:00
|
|
|
app = Flask(__name__)
|
2012-06-19 01:23:07 +00:00
|
|
|
|
2012-06-19 04:57:57 +00:00
|
|
|
@app.route('/api/info')
|
|
|
|
def api_info():
|
|
|
|
return jsonify(
|
|
|
|
version = version.IVERSION
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2012-06-21 03:39:40 +00:00
|
|
|
@app.route('/api/log')
|
|
|
|
def api_log():
|
|
|
|
return jsonify(
|
2012-06-23 23:14:54 +00:00
|
|
|
log = app.config["pathod"].get_log()
|
2012-06-21 03:39:40 +00:00
|
|
|
)
|
2012-06-19 01:23:07 +00:00
|
|
|
|
|
|
|
|
2012-06-21 03:39:40 +00:00
|
|
|
@app.route('/api/clear_log')
|
|
|
|
def api_clear_log():
|
2012-06-23 23:14:54 +00:00
|
|
|
app.config["pathod"].clear_log()
|
2012-06-21 03:39:40 +00:00
|
|
|
return "OK"
|
2012-06-19 01:23:07 +00:00
|
|
|
|
|
|
|
|
2012-06-21 04:25:27 +00:00
|
|
|
@app.route('/')
|
|
|
|
@app.route('/index.html')
|
|
|
|
def index():
|
2012-06-21 04:54:49 +00:00
|
|
|
return render_template("index.html", section="main")
|
|
|
|
|
|
|
|
|
2012-06-28 23:53:59 +00:00
|
|
|
@app.route('/docs/pathod')
|
|
|
|
def docs_pathod():
|
|
|
|
return render_template("docs_pathod.html", section="docs")
|
|
|
|
|
|
|
|
|
2012-07-22 10:24:16 +00:00
|
|
|
@app.route('/docs/language')
|
|
|
|
def docs_language():
|
|
|
|
return render_template("docs_lang.html", section="docs")
|
|
|
|
|
|
|
|
|
2012-06-28 23:53:59 +00:00
|
|
|
@app.route('/docs/pathoc')
|
|
|
|
def docs_pathoc():
|
|
|
|
return render_template("docs_pathoc.html", section="docs")
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/docs/test')
|
|
|
|
def docs_test():
|
|
|
|
return render_template("docs_test.html", section="docs")
|
2012-06-23 23:14:54 +00:00
|
|
|
|
2012-06-21 04:54:49 +00:00
|
|
|
|
|
|
|
@app.route('/log')
|
|
|
|
def log():
|
|
|
|
return render_template("log.html", section="log", log=app.config["pathod"].get_log())
|
2012-06-23 23:14:54 +00:00
|
|
|
|
2012-06-21 04:25:27 +00:00
|
|
|
|
2012-06-21 04:54:49 +00:00
|
|
|
@app.route('/log/<int:lid>')
|
|
|
|
def onelog(lid):
|
2012-07-23 04:18:47 +00:00
|
|
|
item = app.config["pathod"].log_by_id(int(lid))
|
|
|
|
if not item:
|
|
|
|
abort(404)
|
|
|
|
l = pprint.pformat(item)
|
2012-06-21 04:54:49 +00:00
|
|
|
return render_template("onelog.html", section="log", alog=l, lid=lid)
|
2012-06-21 04:25:27 +00:00
|
|
|
|
2012-06-21 04:54:49 +00:00
|
|
|
|
|
|
|
@app.route('/preview')
|
|
|
|
def preview():
|
|
|
|
spec = request.args["spec"]
|
|
|
|
args = dict(
|
|
|
|
spec = spec,
|
|
|
|
section = "main",
|
|
|
|
syntaxerror = None,
|
|
|
|
error = None
|
|
|
|
)
|
|
|
|
try:
|
2012-06-26 03:09:05 +00:00
|
|
|
r = rparse.parse_response(app.config["pathod"].request_settings, spec)
|
2012-06-21 04:54:49 +00:00
|
|
|
except rparse.ParseException, v:
|
|
|
|
args["syntaxerror"] = str(v)
|
|
|
|
args["marked"] = v.marked()
|
|
|
|
return render_template("preview.html", **args)
|
2012-07-23 03:38:06 +00:00
|
|
|
|
|
|
|
s = cStringIO.StringIO()
|
|
|
|
r.serve(s, check=app.config["pathod"].check_size)
|
|
|
|
args["output"] = s.getvalue()
|
2012-06-21 04:54:49 +00:00
|
|
|
return render_template("preview.html", **args)
|