diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2013-04-11 01:14:49 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2013-04-11 01:14:49 +0200 |
commit | 0567318344330295512176569a84afc9748d79c5 (patch) | |
tree | b2ccd2e5ba3e254a945143060f31bdd4d42c921c /index.py | |
parent | 5bf8a03dae494f1625d3d5eeee5ffd6396b730fa (diff) | |
download | kosten-0567318344330295512176569a84afc9748d79c5.tar.gz kosten-0567318344330295512176569a84afc9748d79c5.tar.bz2 kosten-0567318344330295512176569a84afc9748d79c5.zip |
First part of the transition to flask
Diffstat (limited to 'index.py')
-rwxr-xr-x | index.py | 75 |
1 files changed, 11 insertions, 64 deletions
@@ -1,69 +1,16 @@ #!/usr/bin/python +import sys -import web -import controller -import model +from app import app, db -# -# URL Mappings -# -urls = ( - "/add/?", controller.Add, - "/edit/(\d+)", controller.Edit, - "/const/?", controller.Const, - "/const/(\d+)", controller.Const, - "/const/add/?", controller.ConstAdd, - "/const/add/from/(\d+)", controller.ConstAdd, - "/const/edit/(\d+)", controller.ConstEdit, - "/categories", controller.Cat, - "/(\d\d\d\d)/(\d\d?)/?", controller.Show, - "/", controller.Show, - "/(.*)", controller.FourOhFour - ) -# -# ORM -# -def handle_sql(handler): - web.ctx.orm = model.Session() +try: + cmd = sys.argv[1] +except IndexError: + cmd = None - try: - try: - h = handler() - except web.HTTPError: - web.ctx.orm.commit() - raise - except: - web.ctx.orm.rollback() - raise - else: - web.ctx.orm.commit() - return h - finally: - model.Session.remove() - -# -# Check for mobile (at least somewhat) -# -mobile_checks = ["J2ME", "Opera Mini"] -def handle_mobile(): - ua = web.ctx.env.get("HTTP_USER_AGENT", "") - - web.ctx.is_mobile = any((x in ua) for x in mobile_checks) - -# -# The App -# -app = web.application(urls, globals()) -app.notfound = controller.FourOhFour.catch - -# add processors -app.add_processor(handle_sql) -app.add_processor(web.loadhook(handle_mobile)) - -# debug for the moment -web.config.debug = True - -# -# And go! -if __name__ == "__main__": +if cmd == "create": + db.create_all() +elif cmd == "drop": + db.drop_all() +else: app.run() |