Changeset 5670 for main


Ignore:
Timestamp:
25 Jan 2011, 01:10:00 (14 years ago)
Author:
uli
Message:

Add the new applications plugin that installs an ApplicationsRoot on
site creation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/applications/root.py

    r5648 r5670  
    2424"""
    2525import grok
     26from waeup.sirp.interfaces import IWAeUPSIRPPluggable
    2627from waeup.sirp.applications.interfaces import IApplicationsRoot
    2728
     
    3031    """
    3132    grok.implements(IApplicationsRoot)
    32    
     33
    3334    def addApplicationContainer(self, container, name=None):
    3435        """Add an application container.
     
    3738        under the name `name`.
    3839
    39         `container` the container instance to be added. Should
     40        `container`
     41          the container instance to be added. Should
    4042          implement :class:`IApplicationContainer`.
    4143
     
    4951        self[name] = container
    5052        return
     53
     54class ApplicationsPlugin(grok.GlobalUtility):
     55    """A WAeUPSIRPPlugin that creates an applications root in portal.
     56
     57    This plugin should be called by a typical
     58    `waeup.sirp.app.Universtiy` instance on creation time. The
     59    :meth:`update` method normally can also be triggered manually over
     60    the main site configuration.
     61
     62    Implements :class:`waeup.sirp.interfaces.IWAeUPSIRPPluggable`
     63    """
     64    grok.name('applications')
     65    grok.implements(IWAeUPSIRPPluggable)
     66    log_prefix = 'ApplicationsPlugin'
     67
     68    def setup(self, site, name, logger):
     69        """Create a new :class:`ApplicationsRoot` instance in `site`.
     70        """
     71        site['applications'] = ApplicationsRoot()
     72        logger.info(
     73            '%s: Installed applications root.' % (self.log_prefix,)
     74            )
     75        return
     76
     77    def update(self, site, name, logger):
     78        """Update site wide ``applications`` root.
     79
     80        If the site already contains a suitable ``applications`` root,
     81        leave it that way. If not create one and delete the old one if
     82        appropriate.
     83        """
     84        app_folder = site.get('applications', None)
     85        site_name = getattr(site, '__name__', 'Unnamed Site?')
     86        if IApplicationsRoot.providedBy(app_folder):
     87            # Applications up to date. Return.
     88            logger.info(
     89                '%s: Updating site at %s: Nothing to do.' % (
     90                    self.log_prefix, site_name,)
     91                )
     92            return
     93        elif app_folder is not None:
     94            # Applications need update. Remove old instance.
     95            logger.warn(
     96                '%s: Outdated applications folder detected at site %s.'
     97                'Removing it.' % (self.log_prefix, site_name)
     98                    )
     99            del site['applications']
     100        # Add new applications.
     101        logger.info(
     102            '%s: Updating site at %s. Installing '
     103            'applications.' % (self.log_prefix, site_name,)
     104            )
     105        self.setup(site, name, logger)
     106        return
Note: See TracChangeset for help on using the changeset viewer.