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

Last change on this file since 5774 was 5773, checked in by uli, 14 years ago

Remove unneeded imports.

File size: 3.9 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, normally as CSV files.
25"""
26import grok
27from waeup.sirp.interfaces import IWAeUPSIRPPluggable
28from waeup.sirp.applicants.jambtables.interfaces import (
29    IJAMBDataRoot
30    )
31
32class JAMBDataRoot(grok.Container):
33    """A root folder for JAMB data.
34
35    JAMB data is normally imported as a set of
36    :class:`waeup.sirp.applicants.applicants.Applicant` instances, but
37    this depends on the importer used which is not part of the
38    container itself.
39
40    The :class:`JAMBDataRoot` makes no special assumptions about how
41    data is stored inside, while we should keep in mind that regular
42    strings are the most effective way to store/retrieve data inside a
43    :class:`grok.Container`.
44
45    In a regular 'waeup.sirp' site we normally provide a
46    `JAMBDataRoot` instance named ``jambdata`` in the site
47    root. I.e. when you create a :class:`waeup.sirp` university
48    instance, a `JAMBDataRoot` is created automatically (by
49    :class:`JAMBDataPlugin`) under the name ``jambdata``.
50   
51    .. seealso:: waeup.sirp.applicant.jambdata.batching.JAMBDataImporter
52    """
53    grok.implements(IJAMBDataRoot)
54   
55class JAMBDataPlugin(grok.GlobalUtility):
56    """A WAeUPSIRPPlugin that creates a JAMB data root in portal.
57
58    This plugin should be called by a typical
59    `waeup.sirp.app.Universtiy` instance on creation time. The
60    :meth:`update` method normally can also be triggered manually over
61    the main site configuration.
62
63    Implements :class:`waeup.sirp.interfaces.IWAeUPSIRPPluggable`
64    """
65    grok.name('jambdata')
66    grok.implements(IWAeUPSIRPPluggable)
67    log_prefix = 'JAMBDataPlugin'
68
69    def setup(self, site, name, logger):
70        """Create a new :class:`ApplicantsRoot` instance in `site`.
71        """
72        site['jambdata'] = JAMBDataRoot()
73        logger.info(
74            '%s: Installed JAMB data root.' % (self.log_prefix,)
75            )
76        return
77
78    def update(self, site, name, logger):
79        """Update site wide ``jambdata`` root.
80
81        If the site already contains a suitable ``jambdata`` root,
82        leave it that way. If not create one and delete the old one if
83        appropriate.
84        """
85        jamb_folder = site.get('jambdata', None)
86        site_name = getattr(site, '__name__', '<Unnamed Site>')
87        if IJAMBDataRoot.providedBy(jamb_folder):
88            # JAMB data storage up to date. Return.
89            logger.info(
90                '%s: Updating site at %s: Nothing to do.' % (
91                    self.log_prefix, site_name,)
92                )
93            return
94        elif jamb_folder is not None:
95            # JAMB data storage needs update. Remove old instance.
96            logger.warn(
97                '%s: Outdated JAMB data folder detected at site %s.'
98                'Removing it.' % (self.log_prefix, site_name)
99                    )
100            del site['jambdata']
101        # Add new applicants.
102        logger.info(
103            '%s: Updating site at %s. Installing '
104            'JAMB data folder.' % (self.log_prefix, site_name,)
105            )
106        self.setup(site, name, logger)
107        return
Note: See TracBrowser for help on using the repository browser.