lib/site.py
author Tero Marttila <terom@fixme.fi>
Sat, 07 Feb 2009 06:54:52 +0200
branchsites
changeset 30 a86a25a9f75b
parent 29 b06ff4c05d42
child 31 107062ebb6f9
permissions -rw-r--r--
route requests through sites/www.qmsk.net, although still hardcoded
"""
    Per-site stuff
"""

import imp

SITE_DIR = "sites"

class Site (object) :
    """
        A site is a website and its configuration
    """

    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")