author | Tero Marttila <terom@fixme.fi> |
Mon, 26 Nov 2012 15:19:26 +0200 | |
changeset 21 | 945f5a8cfefb |
parent 20 | 3feaac71738a |
permissions | -rwxr-xr-x |
21
945f5a8cfefb
fixfix splitline + opts weirdness
Tero Marttila <terom@fixme.fi>
parents:
20
diff
changeset
|
1 |
#!/usr/bin/python |
18 | 2 |
# Copyright 2009 Tero Marttila |
3 |
# |
|
4 |
# This program is free software: you can redistribute it and/or modify |
|
5 |
# it under the terms of the GNU General Public License as published by |
|
6 |
# the Free Software Foundation, either version 3 of the License, or |
|
7 |
# (at your option) any later version. |
|
8 |
# |
|
9 |
# This program is distributed in the hope that it will be useful, |
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
# GNU General Public License for more details. |
|
13 |
# |
|
14 |
# You should have received a copy of the GNU General Public License |
|
15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 |
# |
|
17 |
||
3 | 18 |
import werkzeug |
19 |
from werkzeug.exceptions import HTTPException |
|
0 | 20 |
|
1
71c7382994c4
rename logo.py -> index.cgi, and implement blurring
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
21 |
from PIL import Image, ImageDraw, ImageFont, ImageEnhance |
0 | 22 |
from cStringIO import StringIO |
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
23 |
import random, itertools, time, os.path |
0 | 24 |
|
20 | 25 |
# monkeypatch 2.5 to add missing 2.6 features |
5
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
26 |
if not hasattr(itertools, 'izip_longest') : |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
27 |
def izip_longest(*args, **kwds): |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
28 |
# izip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D- |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
29 |
fillvalue = kwds.get('fillvalue') |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
30 |
def sentinel(counter = ([fillvalue]*(len(args)-1)).pop): |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
31 |
yield counter() # yields the fillvalue, or raises IndexError |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
32 |
fillers = itertools.repeat(fillvalue) |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
33 |
iters = [itertools.chain(it, sentinel(), fillers) for it in args] |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
34 |
try: |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
35 |
for tup in itertools.izip(*iters): |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
36 |
yield tup |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
37 |
except IndexError: |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
38 |
pass |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
39 |
|
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
40 |
itertools.izip_longest = izip_longest |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
41 |
|
3 | 42 |
class Defaults : |
20 | 43 |
""" |
44 |
Default values for parameters |
|
45 |
""" |
|
8 | 46 |
|
47 |
text_lang = 'en' |
|
0 | 48 |
|
7 | 49 |
chars = [ u'"', u'!', u'?' ] |
0 | 50 |
|
8 | 51 |
colors = [ |
3 | 52 |
"#0469af", |
53 |
"#fbc614", |
|
54 |
"#e1313b", |
|
55 |
] |
|
56 |
||
57 |
font_name = 'helvetica' |
|
58 |
font_size = 30 |
|
59 |
||
8 | 60 |
bg_color = "#ffffff" |
3 | 61 |
line_spacing = -10 |
62 |
sharpness = 0.6 |
|
0 | 63 |
|
7 | 64 |
img_format = 'png' |
65 |
||
8 | 66 |
TEXT_BY_LANG = dict( |
67 |
en = [ |
|
68 |
u"aalto", |
|
69 |
u"unive", |
|
70 |
u"rsity" |
|
71 |
], |
|
72 |
fi = [ |
|
73 |
u"aalto", |
|
74 |
u"yliop", |
|
75 |
u"isto" |
|
76 |
], |
|
77 |
se = [ |
|
78 |
u"aalto", |
|
79 |
u"univer", |
|
80 |
u"sitetet", |
|
81 |
], |
|
82 |
) |
|
83 |
||
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
84 |
STATIC_PATH = "static" |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
85 |
|
8 | 86 |
FONTS = { |
3 | 87 |
'dejavu-sans-bold': "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf", |
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
88 |
'helvetica': "fonts/HELR65W.TTF", |
3 | 89 |
} |
0 | 90 |
|
8 | 91 |
IMAGE_FORMATS = { |
92 |
'jpeg': 'jpeg', |
|
93 |
'png': 'png', |
|
94 |
'bmp': 'bmp' |
|
95 |
} |
|
96 |
||
6 | 97 |
FONT_SIZE_MAX = 1024 |
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
98 |
IMG_SIZE_MAX = 1024 |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
99 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
100 |
TILE_SIZE = (100, 100) |
3 | 101 |
|
18 | 102 |
SITE_URL = "http://qmsk.net/stuff/aaltologo/" |
103 |
SOURCE_URL = "http://hg.qmsk.net/aaltologotin" |
|
104 |
||
3 | 105 |
# enable debugging |
6 | 106 |
DEBUG = True |
107 |
||
0 | 108 |
|
109 |
def randomize (seq) : |
|
110 |
""" |
|
111 |
Returns the given sequence in random order as a list |
|
112 |
""" |
|
113 |
||
114 |
# copy |
|
115 |
l = list(seq) |
|
116 |
||
117 |
# rearrange |
|
118 |
random.shuffle(l) |
|
119 |
||
120 |
return l |
|
121 |
||
11 | 122 |
def randomize_str_char (str) : |
123 |
""" |
|
124 |
Randomize the given string by moving one char around |
|
125 |
""" |
|
126 |
||
127 |
l = list(str) |
|
128 |
||
129 |
c = l.pop(random.randint(0, len(l) - 1)) |
|
130 |
l.insert(random.randint(0, len(l)), c) |
|
131 |
||
132 |
return ''.join(l) |
|
133 |
||
134 |
def build_data (text, chars, line_colors, random_chars=True, random_text=False, random_text_char=False) : |
|
0 | 135 |
""" |
136 |
Returns a matrix of (text, color) tuples representing the data to render |
|
137 |
||
138 |
[ [ (str, str) ] ] |
|
139 |
||
140 |
text - list of lines |
|
141 |
chars - list of random chars to interpse |
|
142 |
line_colors - list of colors to draw the chars in |
|
11 | 143 |
random_chars - randomize the lines the chars go in |
144 |
random_text - randomize the chars in each line |
|
145 |
random_text_char - randomize each line by moving one char around |
|
0 | 146 |
""" |
147 |
||
148 |
data = [] |
|
16 | 149 |
|
150 |
# if no chars given, don't insert any |
|
151 |
if not chars : |
|
152 |
chars = [] |
|
153 |
||
154 |
# randomize char order across lines? |
|
9 | 155 |
if random_chars : |
156 |
chars = randomize(chars) |
|
0 | 157 |
|
5
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
158 |
for line, char, color in itertools.izip_longest(text, chars, line_colors, fillvalue=None) : |
15 | 159 |
if not line : |
160 |
continue |
|
161 |
||
0 | 162 |
# pick position to place char |
16 | 163 |
if len(line) >= 2 : |
164 |
pos = random.randint(1, len(line) - 1) |
|
165 |
else : |
|
166 |
pos = random.randint(0, 1) |
|
167 |
||
168 |
# default color |
|
5
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
169 |
if not color : |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
170 |
color = "#000000" |
16 | 171 |
|
172 |
# randomize text in some way? |
|
9 | 173 |
if random_text : |
174 |
line = ''.join(randomize(line)) |
|
11 | 175 |
|
176 |
if random_text_char : |
|
177 |
line = randomize_str_char(line) |
|
0 | 178 |
|
179 |
# split into three parts |
|
5
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
180 |
if char : |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
181 |
data.append([ |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
182 |
(line[:pos], "#000000"), |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
183 |
(char, color), |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
184 |
(line[pos:], "#000000"), |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
185 |
]) |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
186 |
else : |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
187 |
data.append([ |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
188 |
(line, "#000000"), |
6d0e03f2fef4
replace zip with itertools.izip_longest
Tero Marttila <terom@fixme.fi>
parents:
4
diff
changeset
|
189 |
]) |
0 | 190 |
|
191 |
return data |
|
192 |
||
193 |
def load_font (font_name, font_size) : |
|
194 |
""" |
|
195 |
Load a font by name |
|
196 |
""" |
|
197 |
||
198 |
# load font |
|
8 | 199 |
font_path = FONTS[font_name] |
0 | 200 |
font = ImageFont.truetype(font_path, font_size) |
201 |
||
202 |
return font |
|
203 |
||
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
204 |
def render_img (data, font, background_color="#ffffff", line_spacing=0, img_size=None) : |
0 | 205 |
""" |
206 |
Render the data (as from build_data) as an image, using the given PIL.ImageFont, and return the PIL Image object |
|
207 |
""" |
|
208 |
||
209 |
img_width = img_height = 0 |
|
210 |
||
211 |
img_data = [] |
|
212 |
||
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
213 |
# compute image/segment width/height |
0 | 214 |
for segments in data : |
215 |
line_width = line_height = 0 |
|
216 |
||
217 |
# build a new list of segments with additional info |
|
218 |
line_segments = [] |
|
219 |
||
220 |
for seg_text, seg_color in segments : |
|
221 |
# compute rendered text size |
|
222 |
seg_width, seg_height = font.getsize(seg_text) |
|
223 |
||
224 |
# update line_* |
|
225 |
line_width += seg_width |
|
226 |
line_height = max(line_height, seg_height) |
|
227 |
||
228 |
# build the new segments list |
|
229 |
line_segments.append((seg_text, seg_color, seg_width)) |
|
230 |
||
231 |
# update img_* |
|
232 |
img_width = max(img_width, line_width) |
|
233 |
img_height += line_height |
|
234 |
img_data.append((line_segments, line_height)) |
|
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
235 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
236 |
if img_size : |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
237 |
# override size |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
238 |
img_width, img_height = img_size |
0 | 239 |
|
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
240 |
else : |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
241 |
# calculate height needed for line spacing |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
242 |
img_height += (len(img_data) - 1) * line_spacing |
0 | 243 |
|
244 |
# create image |
|
245 |
img = Image.new("RGB", (img_width, img_height), background_color) |
|
246 |
draw = ImageDraw.Draw(img) |
|
247 |
||
248 |
# draw text |
|
249 |
img_y = 0 |
|
250 |
for segments, line_height in img_data : |
|
251 |
img_x = 0 |
|
252 |
||
253 |
# draw each segment build above, incremeing along img_x |
|
254 |
for seg_text, seg_color, seg_width in segments : |
|
255 |
draw.text((img_x, img_y), seg_text, font=font, fill=seg_color) |
|
256 |
||
257 |
img_x += seg_width |
|
258 |
||
259 |
img_y += line_height + line_spacing |
|
260 |
||
261 |
return img |
|
262 |
||
3 | 263 |
def effect_sharpness (img, factor) : |
1
71c7382994c4
rename logo.py -> index.cgi, and implement blurring
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
264 |
""" |
3 | 265 |
Sharpen the image by the given factor |
1
71c7382994c4
rename logo.py -> index.cgi, and implement blurring
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
266 |
""" |
71c7382994c4
rename logo.py -> index.cgi, and implement blurring
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
267 |
|
71c7382994c4
rename logo.py -> index.cgi, and implement blurring
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
268 |
return ImageEnhance.Sharpness(img).enhance(factor) |
71c7382994c4
rename logo.py -> index.cgi, and implement blurring
Tero Marttila <terom@fixme.fi>
parents:
0
diff
changeset
|
269 |
|
7 | 270 |
def build_img (img, format='png') : |
0 | 271 |
""" |
272 |
Write the given PIL.Image as a string, returning the raw binary data |
|
7 | 273 |
|
274 |
Format should be one of the PIL-supported image foarts |
|
0 | 275 |
""" |
276 |
||
277 |
# render PNG output |
|
278 |
buf = StringIO() |
|
7 | 279 |
img.save(buf, format) |
0 | 280 |
data = buf.getvalue() |
281 |
||
282 |
return data |
|
283 |
||
16 | 284 |
class OptionType (object) : |
285 |
def parse (self, val) : |
|
286 |
""" |
|
287 |
Unicode value -> object |
|
288 |
""" |
|
3 | 289 |
|
16 | 290 |
abstract |
3 | 291 |
|
16 | 292 |
def build (self, val) : |
293 |
""" |
|
294 |
object -> unicode value |
|
295 |
""" |
|
296 |
||
297 |
return unicode(val) |
|
298 |
||
299 |
def input (self, val) : |
|
300 |
""" |
|
301 |
HTML input item |
|
302 |
""" |
|
303 |
||
304 |
abstract |
|
305 |
||
306 |
class StringOption (OptionType) : |
|
307 |
def parse (self, val) : |
|
308 |
return unicode(val) |
|
309 |
||
310 |
def build (self, val) : |
|
311 |
if val is None : |
|
312 |
return "" |
|
313 |
||
314 |
else : |
|
315 |
return val |
|
316 |
||
317 |
def input (self, opt, val) : |
|
318 |
return """<input type="text" name="%(name)s" id="%(name)s" value="%(value)s" />""" % dict( |
|
319 |
name = opt.name, |
|
320 |
value = self.build(val), |
|
321 |
) |
|
322 |
||
323 |
def select (self, opt, val) : |
|
324 |
return """<select name="%(name)s"> |
|
325 |
%(options)s |
|
326 |
</select>""" % dict( |
|
327 |
name = opt.name, |
|
328 |
options = '\n'.join( |
|
329 |
"\t<option %(selected)s>%(value)s</option>" % dict( |
|
330 |
value = self.build(optval), |
|
331 |
selected = 'selected="selected"' if val == optval else "", |
|
332 |
) for optval in opt.range |
|
333 |
), |
|
334 |
) |
|
335 |
||
336 |
class BoolOption (OptionType) : |
|
337 |
def parse (self, val) : |
|
338 |
if val.lower() in ('true', 't', '1', 'yes', 'y') : |
|
339 |
return True |
|
340 |
||
341 |
elif val.lower() in ('false', 'f', '0', 'no', 'n') : |
|
342 |
return False |
|
343 |
||
344 |
else : |
|
345 |
raise ValueError(val) |
|
346 |
||
347 |
def input (self, opt, val) : |
|
348 |
return """<input type="checkbox" name="%(name)s" id="%(name)s" %(checked)s/>""" % dict( |
|
349 |
name = opt.name, |
|
350 |
checked = 'checked="checked"' if val else '', |
|
351 |
) |
|
352 |
||
353 |
class IntOption (StringOption) : |
|
354 |
def parse (self, val) : |
|
355 |
return int(val) |
|
356 |
||
357 |
class FloatOption (StringOption) : |
|
358 |
def parse (self, val) : |
|
359 |
return float(val) |
|
360 |
||
361 |
class ColorOption (StringOption) : |
|
362 |
def _parse (self, val) : |
|
363 |
if val.startswith('#') : |
|
364 |
int(val[1:], 16) |
|
365 |
||
366 |
return val |
|
367 |
else : |
|
368 |
raise ValueError(val) |
|
369 |
||
3 | 370 |
|
8 | 371 |
class Option (object) : |
372 |
def __init__ (self, name, is_list, type, default, range) : |
|
373 |
self.name = name |
|
374 |
self.is_list = is_list |
|
375 |
self.type = type |
|
376 |
self.default = default |
|
377 |
self.range = range |
|
3 | 378 |
|
16 | 379 |
def parse (self, args, force_bool=False) : |
8 | 380 |
if self.is_list : |
381 |
if self.name in args : |
|
16 | 382 |
l = args.getlist(self.name, self.type.parse) |
383 |
||
384 |
# special-case to handle a single param with a newline-separtated list |
|
385 |
if len(l) == 1 : |
|
386 |
if not l[0] : |
|
387 |
return None |
|
388 |
||
389 |
else : |
|
21
945f5a8cfefb
fixfix splitline + opts weirdness
Tero Marttila <terom@fixme.fi>
parents:
20
diff
changeset
|
390 |
return l[0].splitlines() # ('\r\n') |
16 | 391 |
|
392 |
else : |
|
393 |
return l |
|
394 |
||
8 | 395 |
else : |
396 |
return self.default |
|
16 | 397 |
|
8 | 398 |
else : |
16 | 399 |
if isinstance(self.type, BoolOption) and force_bool : |
400 |
return self.name in args |
|
401 |
||
402 |
elif isinstance(self.type, BoolOption) and not self.default and self.name in args : |
|
10
6add80d3993b
enable arg_bools by just giving an empty opt
Tero Marttila <terom@fixme.fi>
parents:
9
diff
changeset
|
403 |
return True |
6add80d3993b
enable arg_bools by just giving an empty opt
Tero Marttila <terom@fixme.fi>
parents:
9
diff
changeset
|
404 |
|
6add80d3993b
enable arg_bools by just giving an empty opt
Tero Marttila <terom@fixme.fi>
parents:
9
diff
changeset
|
405 |
else : |
16 | 406 |
return args.get(self.name, self.default, self.type.parse) |
407 |
||
408 |
def build_list (self, value) : |
|
409 |
if self.is_list and value : |
|
410 |
return [self.type.build(val) for val in value] |
|
411 |
||
412 |
else : |
|
413 |
return [self.type.build(value)] |
|
414 |
||
415 |
def _build_input (self, value) : |
|
416 |
if self.is_list : |
|
417 |
return """\ |
|
418 |
<textarea name="%(name)s" cols="30">\ |
|
419 |
%(data)s\ |
|
420 |
</textarea>""" % dict( |
|
421 |
name = self.name, |
|
422 |
data = '\n'.join(self.type.build(val) for val in value) if value else '', |
|
423 |
) |
|
424 |
||
425 |
elif self.range : |
|
426 |
return self.type.select(self, value) |
|
427 |
||
428 |
else : |
|
429 |
return self.type.input(self, value) |
|
430 |
||
431 |
def build_form (self, opts) : |
|
432 |
value = opts[self.name] |
|
433 |
||
434 |
return """\ |
|
435 |
<div class="param"><label for="%(name)s">%(title)s</label>%(input)s</div>\ |
|
436 |
""" % dict( |
|
437 |
name = self.name, |
|
438 |
title = self.name.title().replace('-', ' '), |
|
439 |
input = self._build_input(value) |
|
440 |
) |
|
3 | 441 |
|
8 | 442 |
class Options (object) : |
443 |
def __init__ (self, *options) : |
|
16 | 444 |
self.options = list(options) |
445 |
self.options_by_name = dict((opt.name, opt) for opt in options) |
|
6 | 446 |
|
16 | 447 |
def parse (self, args, **kwargs) : |
448 |
return dict((opt.name, opt.parse(args, **kwargs)) for opt in self.options) |
|
8 | 449 |
|
450 |
OPTIONS = Options( |
|
16 | 451 |
Option('lang', False, StringOption(), Defaults.text_lang, TEXT_BY_LANG.keys()), |
452 |
Option('text', True, StringOption(), None, None), |
|
453 |
Option('random-text', False, BoolOption(), False, None), |
|
454 |
Option('random-text-char',False,BoolOption(), False, None), |
|
455 |
Option('chars', True, StringOption(), Defaults.chars, None), |
|
456 |
Option('random-chars', False, BoolOption(), True, None), |
|
457 |
Option('colors', True, ColorOption(), Defaults.colors, None), |
|
458 |
Option('font', False, StringOption(), Defaults.font_name, FONTS.keys()), |
|
459 |
Option('font-size', False, IntOption(), Defaults.font_size, None), |
|
460 |
Option('bg-color', False, ColorOption(), Defaults.bg_color, None), |
|
461 |
Option('line-spacing', False, IntOption(), Defaults.line_spacing, None), |
|
462 |
Option('sharpness', False, FloatOption(), Defaults.sharpness, None), |
|
463 |
Option('image-format', False, StringOption(), Defaults.img_format, IMAGE_FORMATS.keys()), |
|
464 |
Option('seed', False, IntOption(), None, None), |
|
19 | 465 |
Option('img-width', False, IntOption(), None, None), |
466 |
Option('img-height', False, IntOption(), None, None), |
|
8 | 467 |
) |
468 |
||
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
469 |
def handle_generic (req, img_size=None) : |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
470 |
# parse options |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
471 |
opts = OPTIONS.parse(req.args) |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
472 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
473 |
# postprocess |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
474 |
if opts['text'] is None : |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
475 |
opts['text'] = TEXT_BY_LANG[opts['lang']] |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
476 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
477 |
if opts['font-size'] > FONT_SIZE_MAX : |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
478 |
raise ValueError(opts['font-size']) |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
479 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
480 |
if opts['seed'] is None : |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
481 |
opts['seed'] = time.time() |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
482 |
|
19 | 483 |
if opts['img-width'] and opts['img-height'] : |
484 |
img_size = (opts['img-width'], opts['img-height']) |
|
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
485 |
|
19 | 486 |
if opts['img-width'] > IMG_SIZE_MAX or opts['img-height'] > IMG_SIZE_MAX : |
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
487 |
raise ValueError(img_size) |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
488 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
489 |
# load/prep resources |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
490 |
random.seed(opts['seed']) |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
491 |
data = build_data(opts['text'], opts['chars'], opts['colors'], opts['random-chars'], opts['random-text'], opts['random-text-char']) |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
492 |
font = load_font(opts['font'], opts['font-size']) |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
493 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
494 |
# render the image |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
495 |
img = render_img(data, font, opts['bg-color'], opts['line-spacing'], img_size) |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
496 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
497 |
img = effect_sharpness(img, opts['sharpness']) |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
498 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
499 |
png_data = build_img(img, opts['image-format']) |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
500 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
501 |
# build the response |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
502 |
response = werkzeug.Response(png_data, mimetype='image/%s' % opts['image-format']) |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
503 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
504 |
return response |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
505 |
|
8 | 506 |
def handle_help (req) : |
507 |
return werkzeug.Response('\n'.join( |
|
508 |
"%-15s %4s %-10s %-20s %s" % data for data in [ |
|
509 |
("name", "", "type", "default", "range"), |
|
510 |
("", "", "", "", ""), |
|
511 |
] + [( |
|
512 |
opt.name, |
|
513 |
'list' if opt.is_list else 'item', |
|
514 |
opt.type.__name__, |
|
515 |
repr(opt.default), |
|
516 |
opt.range if opt.range else "" |
|
517 |
) for opt in OPTIONS.options] |
|
518 |
), mimetype='text/plain') |
|
519 |
||
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
520 |
def handle_logo (req) : |
8 | 521 |
if 'help' in req.args : |
522 |
return handle_help(req) |
|
12 | 523 |
|
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
524 |
return handle_generic(req) |
3 | 525 |
|
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
526 |
def handle_tile (req) : |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
527 |
return handle_generic(req, img_size=TILE_SIZE) |
3 | 528 |
|
16 | 529 |
def handle_index (options, req) : |
530 |
# parse options, force booleans if any form data was submitted, as checkboxes work that way |
|
531 |
opts = options.parse(req.values, force_bool=bool(req.form)) |
|
532 |
||
533 |
# build query string of req things |
|
534 |
qargs = [ |
|
21
945f5a8cfefb
fixfix splitline + opts weirdness
Tero Marttila <terom@fixme.fi>
parents:
20
diff
changeset
|
535 |
# XXX: eek, this is weird |
945f5a8cfefb
fixfix splitline + opts weirdness
Tero Marttila <terom@fixme.fi>
parents:
20
diff
changeset
|
536 |
(opt.name, val) |
945f5a8cfefb
fixfix splitline + opts weirdness
Tero Marttila <terom@fixme.fi>
parents:
20
diff
changeset
|
537 |
for opt, vals in ( |
945f5a8cfefb
fixfix splitline + opts weirdness
Tero Marttila <terom@fixme.fi>
parents:
20
diff
changeset
|
538 |
(options.options_by_name[opt_name], vals) for opt_name, vals in opts.iteritems() |
945f5a8cfefb
fixfix splitline + opts weirdness
Tero Marttila <terom@fixme.fi>
parents:
20
diff
changeset
|
539 |
) if vals != opt.default |
945f5a8cfefb
fixfix splitline + opts weirdness
Tero Marttila <terom@fixme.fi>
parents:
20
diff
changeset
|
540 |
|
945f5a8cfefb
fixfix splitline + opts weirdness
Tero Marttila <terom@fixme.fi>
parents:
20
diff
changeset
|
541 |
# unpack (a, [b, c]) -> (a, b), (a, c) |
945f5a8cfefb
fixfix splitline + opts weirdness
Tero Marttila <terom@fixme.fi>
parents:
20
diff
changeset
|
542 |
for val in opt.build_list(vals) |
16 | 543 |
] |
544 |
||
545 |
img_url = req.url_root + "logo" + ("?%s" % werkzeug.url_encode(qargs) if qargs else '') |
|
546 |
||
547 |
return werkzeug.Response("""\ |
|
548 |
<html> |
|
549 |
<head> |
|
550 |
<title>Aaltologotin</title> |
|
551 |
<style type="text/css"> |
|
552 |
div#logo { |
|
553 |
text-align: center; |
|
554 |
padding: 100px; |
|
555 |
} |
|
556 |
||
557 |
img { |
|
558 |
border: none; |
|
559 |
} |
|
560 |
||
561 |
div#info { |
|
562 |
font-size: small; |
|
563 |
padding-left: 25px; |
|
564 |
margin-top: 50px; |
|
565 |
color: grey; |
|
566 |
} |
|
567 |
||
568 |
label { |
|
569 |
display: block; |
|
570 |
float: left; |
|
571 |
||
572 |
width: 150px; |
|
573 |
} |
|
574 |
||
575 |
div.param { |
|
576 |
padding: 3px; |
|
577 |
} |
|
18 | 578 |
|
579 |
div#footer { |
|
580 |
text-align: center; |
|
581 |
font-size: x-small; |
|
582 |
font-style: italic; |
|
583 |
} |
|
16 | 584 |
</style> |
585 |
</head> |
|
586 |
<body> |
|
587 |
<div id='logo'> |
|
588 |
<a href="%(img_url)s"><img src="%(img_url)s" alt="Aaltologo" /></a> |
|
589 |
</div> |
|
590 |
<div id='info'> |
|
591 |
<h1>Aaltologotin</h1> |
|
20 | 592 |
<p>Aaltologotin pulauttaa sinulle uuden, sattumanvaraisesti valitun aalto-logon!</p> |
16 | 593 |
|
17 | 594 |
<form action="%(script_url)s" method="POST"> |
16 | 595 |
<fieldset> |
596 |
<legend>Aalto-parameterit</legend> |
|
597 |
%(form_fields)s |
|
598 |
<input type="submit" value="Logota!" /> |
|
599 |
</fieldset> |
|
600 |
</form> |
|
601 |
</div> |
|
18 | 602 |
<div id='footer'> |
603 |
<a href="%(site_url)s">Aaltologotin</a> © 2009 Tero Marttila :: GPL <a href="%(source_url)s">Source code</a> |
|
604 |
</div> |
|
16 | 605 |
</body> |
606 |
</html>""" % dict( |
|
607 |
img_url = img_url, |
|
17 | 608 |
script_url = req.url_root, |
16 | 609 |
form_fields = "\n".join( |
610 |
"\t%s" % opt.build_form(opts) for opt in options.options |
|
611 |
), |
|
18 | 612 |
site_url = SITE_URL, |
613 |
source_url = SOURCE_URL, |
|
16 | 614 |
), mimetype='text/html') |
615 |
||
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
616 |
def handle_request (req) : |
16 | 617 |
if req.path == '/' : |
618 |
return handle_index(OPTIONS, req) |
|
619 |
||
620 |
elif req.path.startswith('/logo') : |
|
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
621 |
return handle_logo(req) |
3 | 622 |
|
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
623 |
elif req.path == '/tile' : |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
624 |
return handle_tile(req) |
3 | 625 |
|
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
626 |
else : |
21
945f5a8cfefb
fixfix splitline + opts weirdness
Tero Marttila <terom@fixme.fi>
parents:
20
diff
changeset
|
627 |
raise ValueError(req.path) |
3 | 628 |
|
629 |
@werkzeug.Request.application |
|
630 |
def wsgi_application (request) : |
|
0 | 631 |
""" |
3 | 632 |
Our werkzeug WSGI handler |
0 | 633 |
""" |
634 |
||
3 | 635 |
try : |
636 |
# request -> response |
|
637 |
response = handle_request(request) |
|
0 | 638 |
|
3 | 639 |
return response |
640 |
||
641 |
except HTTPException, e : |
|
642 |
# return as HTTP response |
|
643 |
return e |
|
0 | 644 |
|
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
645 |
def build_app () : |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
646 |
""" |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
647 |
Build and return a WSGI application |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
648 |
""" |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
649 |
|
3 | 650 |
app = wsgi_application |
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
651 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
652 |
# add other middleware |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
653 |
app = werkzeug.SharedDataMiddleware(app, { |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
654 |
'/static': STATIC_PATH, |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
655 |
}) |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
656 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
657 |
|
6 | 658 |
if DEBUG : |
3 | 659 |
# enable debugging |
660 |
app = werkzeug.DebuggedApplication(app, evalex=False) |
|
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
661 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
662 |
return app |
0 | 663 |
|
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
664 |
def main_cgi (app) : |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
665 |
import wsgiref.handlers |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
666 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
667 |
handler = wsgiref.handlers.CGIHandler() |
3 | 668 |
handler.run(app) |
0 | 669 |
|
13
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
670 |
def main_fastcgi (app) : |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
671 |
import flup.server.fcgi |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
672 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
673 |
server = flup.server.fcgi.WSGIServer(app, |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
674 |
multithreaded = False, |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
675 |
multiprocess = False, |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
676 |
multiplexed = False, |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
677 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
678 |
bindAddress = None, |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
679 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
680 |
umask = None, |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
681 |
debug = True, |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
682 |
) |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
683 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
684 |
server.run() |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
685 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
686 |
def main () : |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
687 |
from sys import argv |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
688 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
689 |
# get our file extension |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
690 |
root, ext = os.path.splitext(argv[0]) |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
691 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
692 |
# get our handler |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
693 |
handler = { |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
694 |
'.cgi': main_cgi, |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
695 |
'.fcgi': main_fastcgi, |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
696 |
}[ext] |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
697 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
698 |
# get our app |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
699 |
app = build_app() |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
700 |
|
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
701 |
# run |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
702 |
handler(app) |
a0cb32f3de3d
add silly crap (FastCGI, tiles.*)
Tero Marttila <terom@fixme.fi>
parents:
12
diff
changeset
|
703 |
|
0 | 704 |
if __name__ == '__main__' : |
705 |
main() |
|
706 |