1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
#!/usr/bin/python2.7
from bottle import route, run, post, request, static_file
import sys
sys.path.append("./lib")
#FIXME probably can get away with import * here
from Pb.Break import PbBreak
from Pb.Generate import PbGenerate
from Pb.Gradient import PbGradient
from Pb.Grid import PbGrid
from Pb.Landscape import PbLandscape
from Pb.Pattern import PbPattern
from Config import AWS_SECRET_ACCESS_KEY, AWS_ACCESS_KEY_ID, BUCKET_NAME, BIN_IDENTIFY
from Pb import Pb
from Db import Db
import os
import sys
import sha
from subprocess import call, Popen, PIPE
import simplejson as json
from boto.s3.connection import S3Connection
from boto.s3.key import Key
#
try:
db = Db();
except Exception as e:
sys.stderr.write("Could not connect to db:\n{}".format(e))
sys.exit(1);
BASE_URL = "http://i.asdf.us"
def s3move(filename,objectname):
try:
conn = S3Connection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, is_secure=False)
b = conn.get_bucket(BUCKET_NAME)
k = Key(b)
k.key = objectname
k.set_contents_from_filename(filename)
k.set_acl('public-read')
k.storage_class = 'REDUCED_REDUNDANCY'
except Exception as e:
sys.stderr.write(str(e));
raise(e)
def return_image(im, insert_url="NULL"):
return format_im_data(im, insert_url)
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 return_image(im)
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/<filename>')
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/<filename>')
def server_static(filename):
return static_file(filename, root='frontend/css/')
@route('/js/<filename>')
def server_static(filename):
return static_file(filename, root='frontend/js/')
@route('/img/<filename>')
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)
|