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

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

Be more verbose.

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