X-Git-Url: https://projects.mako.cc/source/yourule/blobdiff_plain/e9647b2143c8c4ec343d66ad3083aabd77659b14..92f1711470719d788b2230d0e50dcef0a0816b39:/yourule.py diff --git a/yourule.py b/yourule.py index 2e4022b..0d8adbc 100755 --- a/yourule.py +++ b/yourule.py @@ -1,5 +1,24 @@ #!/usr/bin/env python +# YouRule: Onscreen Ruler Generator +# +# Copyright (C) 2007 Benjamin Mako Hill +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the Affero General Public License as published +# by the Free Software Foundation, either version 1 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the Affero General Public License +# along with this program. If not, see +# . + + from __future__ import division import web import sys, os, re @@ -22,7 +41,7 @@ def render(filename, vars={}): tmpl = jinja_env.get_template(filename + '.tmpl') vars['homepath'] = web.ctx.homepath vars['ctx'] = web.ctx - print tmpl.render(vars) + return tmpl.render(vars) # the url map for the application urls = ( '/?', 'index', @@ -75,7 +94,7 @@ class Ruler(object): class index: def GET(self): - render('index', locals()) + return render('index', locals()) def POST(self): input = web.input() @@ -86,7 +105,7 @@ class index: pixel_width = input['pixel_width'] unit_width = input['unit_width'] units = input['units'] - render('index', locals()) + return render('index', locals()) else: ruler = Ruler(pixel_width = input['pixel_width'], unit_width = input['unit_width'], @@ -103,7 +122,7 @@ class show_ruler: other_unit, other_unit_url = get_other_unit(ruler_url) - render('show_ruler', locals()) + return render('show_ruler', locals()) class ruler_img: def GET(self, pixel_width=None, unit_width=None, units=None, ext=None): @@ -126,14 +145,14 @@ class ruler_img: web.header("Content-Type", "image/%s" % ext) if ext == 'svg+xml': - sys.stdout.write(ruler.getxml()) + return(ruler.getxml()) else: pin, pout = os.popen2('convert -size %sx%s - %s:-' % \ (pixel_width, ruler_height, ext)) pin.write(ruler.getxml()) pin.close() - sys.stdout.write(pout.read()) + return(pout.read()) class gallery: def GET(self, ruler_url): @@ -149,7 +168,7 @@ class gallery: #rulers = map(lambda x: x, rulers) - render('gallery', locals()) + return render('gallery', locals()) def POST(self, ruler_url): input = web.input() @@ -174,7 +193,7 @@ class gallery: rulers = store.find(Ruler, Ruler.visible == 1) #rulers.order_by(Ruler.model) - render('gallery', locals()) + return render('gallery', locals()) class delete: def GET(self, id): @@ -193,7 +212,7 @@ class undelete: class css: def GET(self): - render('style.css') + return render('style.css') def get_other_unit(url): pixel_width, unit_width, units = process_ruler_url(url)[0:3] @@ -239,5 +258,6 @@ web.webapi.internalerror = web.debugerror if __name__ == "__main__": web.run(urls, globals(), web.reloader) -application = web.wsgifunc(web.webpyfunc(urls, globals())) +app = web.application(urls, globals(), autoreload=False) +application = app.wsgifunc()