updated README to note that the project isn't working
[yourule] / yourule.py
index 2e4022b872c88c5aa4c2a6ae0d808f095e8d2768..ebd85cb99de42038d9897522511d93ab2d832d2c 100755 (executable)
@@ -1,6 +1,25 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
+
+# YouRule: Onscreen Ruler Generator
+#
+# Copyright (C) 2007 Benjamin Mako Hill <mako@atdot.cc>
+#
+# 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
+# <http://http://www.affero.org/oagpl.html>.
+
+
 
-from __future__ import division
 import web
 import sys, os, re
 from storm.locals import *
@@ -9,7 +28,7 @@ from storm.locals import *
 sys.path.append(os.path.dirname(__file__))
 from svgruler import SVGRuler
 
-from jinja import Environment, FileSystemLoader
+from jinja2 import Environment, FileSystemLoader
 jinja_env = Environment('<%', '%>', '<%=', '%>', '<%#', '%>', 
                         loader=FileSystemLoader(os.path.dirname(__file__) + "/templates/"))
 
@@ -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',
@@ -50,11 +69,11 @@ class Ruler(object):
     def __init__(self, **kw):
         self.pixel_width = float(kw['pixel_width'])
         self.unit_width = float(kw['unit_width'])
-        self.units = unicode(kw['units'])
-        if kw.has_key('model'):
-            self.model = unicode(kw['model'])
+        self.units = str(kw['units'])
+        if 'model' in kw:
+            self.model = str(kw['model'])
         else:
-            self.model = u''
+            self.model = ''
 
     def cm_width(self):
         if self.units == 'centimeters':
@@ -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'], 
@@ -96,14 +115,14 @@ class index:
 
 class show_ruler:
     def GET(self, ruler_url, ext):
-        if web.input().has_key('fromgallery'):
+        if 'fromgallery' in web.input():
             fromgallery = True
         else:
             fromgallery = False
 
         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()
 

Benjamin Mako Hill || Want to submit a patch?