diff options
| -rw-r--r-- | config.py | 5 | ||||
| -rw-r--r-- | examples/break.py | 2 | ||||
| -rw-r--r-- | examples/grid.sh | 1 | ||||
| -rw-r--r-- | lib/server.py | 21 | ||||
| -rw-r--r-- | run_server.py | 8 |
5 files changed, 34 insertions, 3 deletions
@@ -18,6 +18,11 @@ OUTPUT_IMAGE_TYPES = ["png", "jpg", "gif" ] #mounted on tmpfs WORKING_DIR = "/var/www/cache" + +#server +SERVER_HOST='0.0.0.0' +SERVER_PORT=8889 + #s3 AWS_ACCESS_KEY_ID = 'AKIAIR53VPBXKJMXZIBA' AWS_SECRET_ACCESS_KEY = 'Dzlzh77U6n2BgQmOPldlR/dRDiO16DMUrQAXYhYc' diff --git a/examples/break.py b/examples/break.py index 6f0c710..91d888d 100644 --- a/examples/break.py +++ b/examples/break.py @@ -1,7 +1,7 @@ #!/usr/bin/python2.7 import requests, sys import simplejson as json -URL_BASE = "http://127.0.0.1:5000" +URL_BASE = "http://127.0.0.1:8080" example_params = { "url" : "http://i.asdf.us/im/de/HolyMountain2_1322275112_seamonkey.gif", diff --git a/examples/grid.sh b/examples/grid.sh new file mode 100644 index 0000000..da5fe41 --- /dev/null +++ b/examples/grid.sh @@ -0,0 +1 @@ +curl localhost:8889/imgrid -H 'Cookie: imname=pepper' -H 'Origin: http://asdf.us' -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: en-US,en;q=0.8' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: */*' -H 'Referer: http://asdf.us/imgrid/' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' --data 'width=700&height=500&linethickness=1&opacity=1&linecolor=MISTYROSE4&spacing=10&vlines=false&hlines=false&shadow=false&bgimage=&bgcolor=transparent&imageinstead=&planebgcolor=transparent&skycolor=none&planebgimage=&transition=background&swing=0&tilt=0&roll=0&zoom=0&trim=false&format=&username=pepper' --compressed diff --git a/lib/server.py b/lib/server.py index 00bae9f..e0f3140 100644 --- a/lib/server.py +++ b/lib/server.py @@ -1,8 +1,10 @@ from flask import Flask from flask import abort, redirect, url_for, request, jsonify +from cherrypy import wsgiserver import sys, os sys.path.append("./lib") -from Pb import * +from pb import * +from config import SERVER_HOST, SERVER_PORT class InvalidUsage(Exception): status_code = 400 @@ -22,6 +24,10 @@ class InvalidUsage(Exception): class Server(object): def __init__(self): self.app = Flask(__name__) + self._wsgi_server = None + @self.app.route('/test', methods=['GET']) + def test(): + return "HELLO WORLD!" @self.app.route('/<pb_classname>', methods=['POST']) def pb(pb_classname): return self._response_post(pb_classname, request.form.to_dict()) @@ -71,3 +77,16 @@ class Server(object): def run(self): self.app.run() + def run_wsgi(self, server_port=SERVER_PORT, host=SERVER_HOST): + d = wsgiserver.WSGIPathInfoDispatcher({'/': self.app}) + sys.stderr.write("Starting a wsgi server on %s port %s\n" % (host, server_port)) + self._wsgi_server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', server_port), d) + self._wsgi_server.start() + + def stop(self): + if self._wsgi_server: + self._wsgi_server.stop() + self._wsgi_server = None + return + else: + return diff --git a/run_server.py b/run_server.py index 3d759ed..eaf3e0b 100644 --- a/run_server.py +++ b/run_server.py @@ -3,4 +3,10 @@ import sys sys.path.append("./lib") from server import Server server = Server() -server.run() + +if __name__ == "__main__": + try: + server.run_wsgi() + except KeyboardInterrupt: + server.stop() + |
