Ignore:
Timestamp:
12 Feb 2011, 11:52:56 (14 years ago)
Author:
uli
Message:
  • Add a jambdata plugin that creates jambdata folder on creation/updates of a waeup.sirp site.
  • Implement some basic root for jambdata.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/applicants/jambtables/jambtables.py

    r5689 r5722  
    3434from BTrees.Length import Length
    3535
    36 from waeup.sirp.applicants.jambtables.interfaces import IJAMBDataTable
     36from waeup.sirp.interfaces import IWAeUPSIRPPluggable
     37from waeup.sirp.applicants.jambtables.interfaces import (
     38    IJAMBDataTable, IJAMBDataRoot
     39    )
    3740
    3841#: The header fields required for a valid JAMB table CSV file.
     
    180183            os.mkdir(jambtable_storage)
    181184        return os.path.abspath(jambtable_storage)
     185
     186class JAMBDataRoot(grok.Container):
     187    grok.implements(IJAMBDataRoot)
     188   
     189class JAMBDataPlugin(grok.GlobalUtility):
     190    """A WAeUPSIRPPlugin that creates a JAMB data root in portal.
     191
     192    This plugin should be called by a typical
     193    `waeup.sirp.app.Universtiy` instance on creation time. The
     194    :meth:`update` method normally can also be triggered manually over
     195    the main site configuration.
     196
     197    Implements :class:`waeup.sirp.interfaces.IWAeUPSIRPPluggable`
     198    """
     199    grok.name('jambdata')
     200    grok.implements(IWAeUPSIRPPluggable)
     201    log_prefix = 'JAMBDataPlugin'
     202
     203    def setup(self, site, name, logger):
     204        """Create a new :class:`ApplicantsRoot` instance in `site`.
     205        """
     206        site['jambdata'] = JAMBDataRoot()
     207        logger.info(
     208            '%s: Installed JAMB data root.' % (self.log_prefix,)
     209            )
     210        return
     211
     212    def update(self, site, name, logger):
     213        """Update site wide ``jambdata`` root.
     214
     215        If the site already contains a suitable ``jambdata`` root,
     216        leave it that way. If not create one and delete the old one if
     217        appropriate.
     218        """
     219        jamb_folder = site.get('jambdata', None)
     220        site_name = getattr(site, '__name__', '<Unnamed Site>')
     221        if IJAMBDataRoot.providedBy(jamb_folder):
     222            # JAMB data storage up to date. Return.
     223            logger.info(
     224                '%s: Updating site at %s: Nothing to do.' % (
     225                    self.log_prefix, site_name,)
     226                )
     227            return
     228        elif jamb_folder is not None:
     229            # JAMB data storage needs update. Remove old instance.
     230            logger.warn(
     231                '%s: Outdated JAMB data folder detected at site %s.'
     232                'Removing it.' % (self.log_prefix, site_name)
     233                    )
     234            del site['jambdata']
     235        # Add new applicants.
     236        logger.info(
     237            '%s: Updating site at %s. Installing '
     238            'JAMB data folder.' % (self.log_prefix, site_name,)
     239            )
     240        self.setup(site, name, logger)
     241        return
Note: See TracChangeset for help on using the changeset viewer.