from zope.app.component.hooks import setSite
from zope.app import zapi
from zope.component import getUtility

from Products.CMFCore.interfaces import ISiteRoot

from Acquisition import aq_parent
from OFS.Application import Application

from Products.listen.interfaces import IListLookup
from Products.listen.utilities.list_lookup import ListLookup

def importVarious(context):
    """
    Import various settings.
    
    Provisional handler that does initialization that is not yet taken
    care of by exising generic setup handlers.
    """
    
    # Force listen to be installed at the portal root
    site = getUtility(ISiteRoot)
    if not site:
        raise ValueError, "Site root missing"

    logger = context.getLogger("listen")

    # If the utility is not yet registered, then register it.
    if zapi.queryUtility(IListLookup, default=None) is None:
        sm = site.getSiteManager()
        if not sm.queryUtility(IListLookup):
            sm.registerUtility(component=ListLookup('list_lookup'),
                               provided=IListLookup)
            logger.info('IListLookup Utility registered at %s.%s' % (site, sm.getId()))
        else:
            logger.info('IListLookup Utility already registered at %s.%s' % (site, sm.getId()))
    else:
        logger.info('Nothing to import.')
