source: main/waeup.kofa/branches/henrik-regista/src/waeup/ikoba/app.py @ 11950

Last change on this file since 11950 was 11949, checked in by Henrik Bettermann, 10 years ago

Change of name.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.6 KB
Line 
1## $Id: app.py 11949 2014-11-13 14:40:27Z henrik $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18import grok
19from zope.authentication.interfaces import IAuthentication
20from zope.component import getUtility, getUtilitiesFor
21from zope.component.interfaces import ObjectEvent
22from zope.pluggableauth import PluggableAuthentication
23from waeup.ikoba.authentication import setup_authentication
24from waeup.ikoba.datacenter import DataCenter
25from waeup.ikoba.mandates.container import MandatesContainer
26from waeup.ikoba.interfaces import (
27    IUniversity, IIkobaPluggable, IObjectUpgradeEvent, IJobManager,
28    VIRT_JOBS_CONTAINER_NAME)
29from waeup.ikoba.userscontainer import UsersContainer
30from waeup.ikoba.utils.logger import Logger
31from waeup.ikoba.utils.helpers import attrs_to_fields
32from waeup.ikoba.configuration import ConfigurationContainer
33
34class University(grok.Application, grok.Container, Logger):
35    """A university.
36    """
37    grok.implements(IUniversity)
38
39    # Setup authentication for this app. Note: this is only
40    # initialized, when a new instance of this app is created.
41    grok.local_utility(
42        PluggableAuthentication, provides = IAuthentication,
43        setup = setup_authentication,)
44
45    def __init__(self, *args, **kw):
46        super(University, self).__init__(*args, **kw)
47        self.setup()
48        return
49
50    def setup(self):
51        """Setup some hard-wired components.
52
53        Create local datacenter, containers for users and
54        the like.
55        """
56
57        self['users'] = UsersContainer()
58        self['datacenter'] = DataCenter()
59        self['configuration'] = ConfigurationContainer()
60        self['mandates'] = MandatesContainer()
61        self._createPlugins()
62
63    def _createPlugins(self):
64        """Create instances of all plugins defined somewhere.
65        """
66        for name, plugin in getUtilitiesFor(IIkobaPluggable):
67            plugin.setup(self, name, self.logger)
68        return
69
70    def traverse(self, name):
71        if name == VIRT_JOBS_CONTAINER_NAME:
72            return getUtility(IJobManager)
73        return None
74
75    def updatePlugins(self):
76        """Lookup all plugins and call their `update()` method.
77        """
78        name = getattr(self, '__name__', '<Unnamed>')
79        self.logger.info('Fire upgrade event for site %s' % name)
80        grok.notify(ObjectUpgradeEvent(self))
81        self.logger.info('Done.')
82        self.logger.info('Now upgrading any plugins.')
83        for name, plugin in getUtilitiesFor(IIkobaPluggable):
84            plugin.update(self, name, self.logger)
85        self.logger.info('Plugin update finished.')
86        return
87attrs_to_fields(University)
88
89class ObjectUpgradeEvent(ObjectEvent):
90    """An event fired, when datacenter storage moves.
91    """
92    grok.implements(IObjectUpgradeEvent)
93
94@grok.subscribe(University, grok.IObjectAddedEvent)
95def handle_university_added(app, event):
96    """If a university is added, a message is logged.
97    """
98    app.logger.info('University `%s` added.' % getattr(app, '__name__', None))
99    return
Note: See TracBrowser for help on using the repository browser.