Skip to content

Commit

Permalink
added routeloader, changed bootstrap to be global, added multiple tem…
Browse files Browse the repository at this point in the history
…plate dir lookup support
  • Loading branch information
mdennebaum committed Nov 11, 2011
1 parent 3569a4f commit 7956581
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 29 deletions.
5 changes: 3 additions & 2 deletions whirlwind/conf/app_template/main.py
@@ -1,7 +1,8 @@
#!/usr/bin/env python

from bootstrap import Bootstrap
from whirlwind.core.bootstrap import Bootstrap
import os

#main app entry point
if __name__ == "__main__":
Bootstrap.run()
Bootstrap.run(os.path.dirname(__file__))
Expand Up @@ -4,6 +4,7 @@
class Bootstrap():
def __init__(self):
self.application = None
self.init_path()

'''
make sure the python path is set for this app
Expand All @@ -22,15 +23,15 @@ def init_logging(self,log):
else:
Log.create('FILE',log)

def main(self):
def main(self,path):
#import tornado stuff
import tornado.web, tornado.httpserver, tornado.ioloop, tornado.options
from tornado.options import options
from config import options_setup
from whirlwind.db.mongo import Mongo

#parse the app config
tornado.options.parse_config_file(os.path.join(os.path.dirname(__file__),'config/settings.py'))
tornado.options.parse_config_file(os.path.join(path,'config/settings.py'))
#parse the command line args
tornado.options.parse_command_line()

Expand Down Expand Up @@ -66,28 +67,9 @@ def main(self):
tornado.ioloop.IOLoop.instance().start()

def init_routes(self):
import pkgutil,sys,inspect
import application.controllers
from whirlwind.view.decorators import route
from config.routes import route_list

#import all the controllers so the route decorators will run
package = application.controllers
prefix = package.__name__ + "."

for importer, modname, ispkg in pkgutil.iter_modules(package.__path__, prefix):
module = __import__(modname)

#grab the routes defined via the route decorator
url_routes = route.get_routes()

#add the routes from our route file
url_routes.extend(route_list)

return url_routes
from whirlwind.core.routes import RouteLoader
return RouteLoader.load('application.controllers')

@staticmethod
def run():
bootstrap = Bootstrap()
bootstrap.init_path()
bootstrap.main()
def run(path):
(Bootstrap()).main(path)
8 changes: 7 additions & 1 deletion whirlwind/core/request.py
Expand Up @@ -58,8 +58,14 @@ def _get_template_lookup(self,extra_imports=None) :
if extra_imports:
filter_imports.extend(extra_imports)


if isinstance(options.template_dir,(list,tuple)):
directory_paths = options.template_dir
else:
directory_paths = [options.template_dir]

return TemplateLookup(
directories=[options.template_dir],
directories=directory_paths,
module_directory=options.mako_modules_dir,
output_encoding='utf-8',
encoding_errors='replace',
Expand Down
29 changes: 29 additions & 0 deletions whirlwind/core/routes.py
@@ -0,0 +1,29 @@
class RouteLoader(object):

@staticmethod
def load(package_name,include_routes_file=True):
loader = RouteLoader()
return loader.init_routes(package_name,include_routes_file)

def init_routes(self,package_name,include_routes_file=True):
import pkgutil,sys,inspect
from whirlwind.view.decorators import route

package = __import__(package_name)
controllers_module = sys.modules[package_name]

prefix = controllers_module.__name__ + "."

for importer, modname, ispkg in pkgutil.iter_modules(controllers_module.__path__, prefix):
module = __import__(modname)

#grab the routes defined via the route decorator
url_routes = route.get_routes()

#add the routes from our route file
if include_routes_file:
from config.routes import route_list
url_routes.extend(route_list)


return url_routes
16 changes: 15 additions & 1 deletion whirlwind/db/memcache_interface.py
Expand Up @@ -16,4 +16,18 @@ def create(**kwargs):
print mc

Memcache.db = mc
print Memcache.db
print Memcache.db

@staticmethod
def get(key):
if Memcache.db == None:
return None
else:
return Memcache.db.get(key)

@staticmethod
def set(key,val):
if Memcache.db == None:
return False
else:
return Memcache.db.set(key,val)

0 comments on commit 7956581

Please sign in to comment.