first working version
[yourule] / ruler_web.py
diff --git a/ruler_web.py b/ruler_web.py
deleted file mode 100755 (executable)
index 2738f8f..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-#!/usr/bin/env python
-
-from __future__ import division
-import web
-import sys, os, re
-from storm.locals import *
-from ruler import RulerImage
-
-# the url map for the application
-urls = ( '/', 'index',
-         '/ruler_([0-9\.]+)px_([0-9\.]+)([A-Za-z]+).(svg|png|jpg)', 'ruler_img',
-         '/show/(.*(svg|png|jpg))', 'ruler',
-         '/gallery(.*)', 'gallery',
-         '/delete/(\d+)', 'delete',
-         '/undelete/(\d+)', 'undelete')
-
-database = create_database("sqlite:ruler_web.db")
-store = Store(database)
-
-class SavedRuler(object):
-    __storm_table__ = "gallery"
-    id = Int(primary=True)
-    pixel_width = Float()
-    unit_width = Float()
-    model = Unicode()
-    units = Unicode()
-    show = Int()
-
-    def __init__(self, **kw):
-        self.pixel_width = kw['pixel_width']
-        self.unit_width = kw['unit_width']
-        self.units = kw['units']
-        self.model = kw['model']
-
-    def cm_width(self):
-        if self.units == 'centimeters':
-            return self.unit_width
-        elif self.units == 'inches':
-            return(self.unit_width * 2.54)
-
-    def in_width(self):
-        if self.units == 'inches':
-            return self.unit_width
-        elif self.units == 'centimeters':
-            return(self.unit_width * 0.3937)
-
-
-class index:
-    def GET(self):
-        web.header("Content-Type","text/html; charset=utf-8")
-        web.render('index.tmpl')
-
-    def POST(self):
-        input = web.input()
-
-        pixel_width = input['pixel_width']
-        unit_width = input['unit_width']
-        units = input['units']
-        ruler_url = 'ruler_%spx_%s%s.png' % (pixel_width, unit_width, units)
-        web.redirect('/show/%s' % ruler_url)
-
-class ruler:
-    def GET(self, ruler_url, ext):
-        web.debug('test test')
-        if web.input().has_key('fromgallery'):
-            fromgallery = True
-        else:
-            fromgallery = False
-
-        other_unit, other_unit_url = get_other_units(ruler_url)
-
-        web.header("Content-Type","text/html; charset=utf-8")
-        web.render('show_ruler.tmpl')
-
-
-class ruler_img:
-    def GET(self, pixel_width=None, unit_width=None, units=None, ext=None):
-
-        # TODO check to see if it's a format that we support
-
-        # set ruler height to be 200 px always
-        pixel_width = float(pixel_width)
-        unit_width = float(unit_width)
-
-        ruler_height = 200
-
-        scale = pixel_width / unit_width
-        ruler_length = int(unit_width)
-
-        ruler = Ruler(scale, units, ruler_height, ruler_length)
-
-        # print the header
-        if ext == 'svg': ext = 'svg+xml'
-        web.header("Content-Type", "image/%s" % ext)
-
-        if ext == 'svg+xml':
-            sys.stdout.write(ruler.output())
-        else:
-            pin, pout = os.popen2('convert -size %sx%s - %s:-' % \
-                                  (pixel_width, ruler_height, ext))
-
-            pin.write(ruler.output())
-            pin.close()
-            sys.stdout.write(pout.read())
-
-class gallery:
-    def GET(self, ruler_url):
-
-        if ruler_url:
-            pixel_width, unit_width, units = process_ruler_url(ruler_url)[0:3]
-
-        rulers = store.find(SavedRuler, SavedRuler.show == 1)
-        rulers.order_by(SavedRuler.model)
-
-        web.render('gallery.tmpl')
-
-    def POST(self):
-        input = web.input()
-
-        new_ruler = SavedRuler(pixel_width=float(input['pixel_width']),
-                               unit_width=float(input['unit_width']),
-                               units=unicode(input['units']),
-                               model=unicode(input['model']))
-
-        store.add(new_ruler)
-        store.commit()
-
-        web.redirect('gallery')
-
-class delete:
-    def GET(self, id):
-        ruler = store.get(SavedRuler, int(id))
-        ruler.show = 0
-        store.commit()
-        web.redirect('/gallery')
-
-
-class undelete:
-    def GET(self, id):
-        ruler = store.get(SavedRuler, int(id))
-        ruler.show = 1
-        store.commit()
-        web.redirect('/gallery')
-
-def get_other_units(url):
-    pixel_width, unit_width, units = process_ruler_url(url)[0:3]
-    ruler = SavedRuler(pixel_width=float(pixel_width),
-                       unit_width=float(unit_width),
-                       units=unicode(units),
-                       model=unicode(model))
-
-def process_ruler_url(url):
-    url = re.sub(r'^/?(ruler.*)$', r'\1', url)
-    return(re.match( r'ruler_([\d\.]+)px_([\d\.]+)(\w+).(png|svg|jpg)',
-           url).groups())
-
-# render the site template here so that i can use it later
-web.render('site.tmpl', None, True, 'site')
-
-web.webapi.internalerror = web.debugerror
-if __name__ == "__main__":
-    web.run(urls, globals(), web.reloader)
-

Benjamin Mako Hill || Want to submit a patch?