## ## jambtables.py ## Login : ## Started on Tue Jun 22 06:31:42 2010 Uli Fouquet ## $Id$ ## ## Copyright (C) 2010 Uli Fouquet ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## """WAeUP SIRP support for JAMB tables. JAMB tables are datasets delivered by JAMB. """ import csv import os import shutil import tempfile import grok from datetime import datetime from BTrees.OOBTree import OOBTree from BTrees.Length import Length from waeup.sirp.interfaces import IWAeUPSIRPPluggable from waeup.sirp.applicants.jambtables.interfaces import ( IJAMBDataRoot ) class JAMBDataRoot(grok.Container): grok.implements(IJAMBDataRoot) class JAMBDataPlugin(grok.GlobalUtility): """A WAeUPSIRPPlugin that creates a JAMB data root in portal. This plugin should be called by a typical `waeup.sirp.app.Universtiy` instance on creation time. The :meth:`update` method normally can also be triggered manually over the main site configuration. Implements :class:`waeup.sirp.interfaces.IWAeUPSIRPPluggable` """ grok.name('jambdata') grok.implements(IWAeUPSIRPPluggable) log_prefix = 'JAMBDataPlugin' def setup(self, site, name, logger): """Create a new :class:`ApplicantsRoot` instance in `site`. """ site['jambdata'] = JAMBDataRoot() logger.info( '%s: Installed JAMB data root.' % (self.log_prefix,) ) return def update(self, site, name, logger): """Update site wide ``jambdata`` root. If the site already contains a suitable ``jambdata`` root, leave it that way. If not create one and delete the old one if appropriate. """ jamb_folder = site.get('jambdata', None) site_name = getattr(site, '__name__', '') if IJAMBDataRoot.providedBy(jamb_folder): # JAMB data storage up to date. Return. logger.info( '%s: Updating site at %s: Nothing to do.' % ( self.log_prefix, site_name,) ) return elif jamb_folder is not None: # JAMB data storage needs update. Remove old instance. logger.warn( '%s: Outdated JAMB data folder detected at site %s.' 'Removing it.' % (self.log_prefix, site_name) ) del site['jambdata'] # Add new applicants. logger.info( '%s: Updating site at %s. Installing ' 'JAMB data folder.' % (self.log_prefix, site_name,) ) self.setup(site, name, logger) return