source: main/waeup.sirp/trunk/src/waeup/sirp/applicants/jambtables/jambtables.py @ 5758

Last change on this file since 5758 was 5753, checked in by uli, 14 years ago

Move main applicant interfaces to applicants package and try to fix first imports.

File size: 3.2 KB
Line 
1##
2## jambtables.py
3## Login : <uli@pu.smp.net>
4## Started on  Tue Jun 22 06:31:42 2010 Uli Fouquet
5## $Id$
6##
7## Copyright (C) 2010 Uli Fouquet
8## This program is free software; you can redistribute it and/or modify
9## it under the terms of the GNU General Public License as published by
10## the Free Software Foundation; either version 2 of the License, or
11## (at your option) any later version.
12##
13## This program is distributed in the hope that it will be useful,
14## but WITHOUT ANY WARRANTY; without even the implied warranty of
15## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16## GNU General Public License for more details.
17##
18## You should have received a copy of the GNU General Public License
19## along with this program; if not, write to the Free Software
20## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21##
22"""WAeUP SIRP support for JAMB tables.
23
24JAMB tables are datasets delivered by JAMB.
25"""
26import csv
27import os
28import shutil
29import tempfile
30import grok
31
32from datetime import datetime
33from BTrees.OOBTree import OOBTree
34from BTrees.Length import Length
35
36from waeup.sirp.interfaces import IWAeUPSIRPPluggable
37from waeup.sirp.applicants.jambtables.interfaces import (
38    IJAMBDataRoot
39    )
40
41class JAMBDataRoot(grok.Container):
42    grok.implements(IJAMBDataRoot)
43   
44class JAMBDataPlugin(grok.GlobalUtility):
45    """A WAeUPSIRPPlugin that creates a JAMB data root in portal.
46
47    This plugin should be called by a typical
48    `waeup.sirp.app.Universtiy` instance on creation time. The
49    :meth:`update` method normally can also be triggered manually over
50    the main site configuration.
51
52    Implements :class:`waeup.sirp.interfaces.IWAeUPSIRPPluggable`
53    """
54    grok.name('jambdata')
55    grok.implements(IWAeUPSIRPPluggable)
56    log_prefix = 'JAMBDataPlugin'
57
58    def setup(self, site, name, logger):
59        """Create a new :class:`ApplicantsRoot` instance in `site`.
60        """
61        site['jambdata'] = JAMBDataRoot()
62        logger.info(
63            '%s: Installed JAMB data root.' % (self.log_prefix,)
64            )
65        return
66
67    def update(self, site, name, logger):
68        """Update site wide ``jambdata`` root.
69
70        If the site already contains a suitable ``jambdata`` root,
71        leave it that way. If not create one and delete the old one if
72        appropriate.
73        """
74        jamb_folder = site.get('jambdata', None)
75        site_name = getattr(site, '__name__', '<Unnamed Site>')
76        if IJAMBDataRoot.providedBy(jamb_folder):
77            # JAMB data storage up to date. Return.
78            logger.info(
79                '%s: Updating site at %s: Nothing to do.' % (
80                    self.log_prefix, site_name,)
81                )
82            return
83        elif jamb_folder is not None:
84            # JAMB data storage needs update. Remove old instance.
85            logger.warn(
86                '%s: Outdated JAMB data folder detected at site %s.'
87                'Removing it.' % (self.log_prefix, site_name)
88                    )
89            del site['jambdata']
90        # Add new applicants.
91        logger.info(
92            '%s: Updating site at %s. Installing '
93            'JAMB data folder.' % (self.log_prefix, site_name,)
94            )
95        self.setup(site, name, logger)
96        return
Note: See TracBrowser for help on using the repository browser.