#!/usr/bin/python2.7 from bottle import route, run, post, request, static_file sys.path.append("./lib") from Pb import * import sys, os from subprocess import call, Popen, PIPE #FIXME add def return_jsonp(im, insert_url="NULL"): return "{}({})".format(im.get("callback"), format_im_data(im, insert_url)) def _pb_post(pb_class, request): try: im = pb_class(**(dict(request.forms))) im.create(); return im.file_json(); except Exception as e: sys.stderr.write("%s failure" % pb_class.__name__) sys.stderr.write("params:\n") for i in request.forms: sys.stderr.write("{}:{}\n".format(i, request.forms[i])) raise; return json.dumps({ 'error' : 'Request could not be processed' }) @post('/im/api/imgradient') def gradient(): _pb_post(PbGradient, request) @post('/im/api/imgrid') def imgrid(): _pb_post(PbLandscape, request) @post('/im/api/generate') def generate(): _pb_post(PbGenerate, request) @post('/im/api/imbreak') _pb_post(PbBreak, request) @post('/im/api/impattern') def pattern(): _pb_post(PbPattern, request) @post('/im/api/imlandscape') def imlandscape(): _pb_post(Imlandscape, request) #static routes #{{{ @route('/im/') def server_static(filename): return static_file(filename, root='frontend/im/') @route('/im') def server_static(): return static_file("index.html", root='frontend/im/') @route('/imgrid') def server_static(): return static_file("index.html", root='frontend/imgrid/') @route('/imgradient') def server_static(): return static_file("index.html", root='frontend/imgradient/') @route('/imlandscape') def server_static(): return static_file("index.html", root='frontend/imlandscape/') @route('/impattern') def server_static(): return static_file("index.html", root='frontend/impattern/') @route('/imbreak') def server_static(): return static_file("index.html", root='frontend/imbreak/') @route('/') def server_static(): return static_file("index.html", root='frontend/im/') @route('/css/') def server_static(filename): return static_file(filename, root='frontend/css/') @route('/js/') def server_static(filename): return static_file(filename, root='frontend/js/') @route('/img/') def server_static(filename): return static_file(filename, root='frontend/img/') #}}} run(host='0.0.0.0', server='flup', port=8999, debug=True) #run(host='0.0.0.0', port=8999, debug=True)