diff -r b06ff4c05d42 -r a86a25a9f75b lib/site.py --- a/lib/site.py Sat Feb 07 06:05:10 2009 +0200 +++ b/lib/site.py Sat Feb 07 06:54:52 2009 +0200 @@ -2,6 +2,8 @@ Per-site stuff """ +import imp + SITE_DIR = "sites" class Site (object) : @@ -9,6 +11,46 @@ A site is a website and its configuration """ - pass + def __init__ (self, name) : + """ + The given name must be like a valid hostname, e.g. 'www.qmsk.net' + """ + # store + self.name = name + # load the site + self._load() + + def _load (self) : + """ + Loads this site, as a python module (i.e. dir with __init__.py) + """ + + # first, we need to find it + file, pathname, description = imp.find_module(self.name, [SITE_DIR]) + + # then, we can load it + self.module = imp.load_module(self.name, file, pathname, description) + + # create our mapper + self.mapper = self.module.build_mapper() + + def get_mapper (self) : + """ + Return the Mapper for this site + """ + + return self.mapper + +def lookup (request) : + """ + Lookup and return a Site object for the given request + """ + + # request hostnmae + hostname = request.env.get('HTTP_POST') + + # XXX: hardcoded for now + return Site("www.qmsk.net") +