[8057] | 1 | ## $Id: zcml.py 8057 2012-04-06 21:56:22Z henrik $ |
---|
[7576] | 2 | ## |
---|
[8057] | 3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
[7576] | 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. |
---|
[8057] | 8 | ## |
---|
[7576] | 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. |
---|
[8057] | 13 | ## |
---|
[7576] | 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 | ## |
---|
| 18 | from zope.component.zcml import handler |
---|
[7811] | 19 | from waeup.kofa.interfaces import IDataCenterConfig |
---|
[7576] | 20 | |
---|
| 21 | def data_center_conf(context, path): |
---|
| 22 | """Handler for ZCML ``datacenter`` directive. |
---|
| 23 | |
---|
| 24 | Registers a global utility under IDataCenterConfig and containing |
---|
| 25 | a dictionary with (currently) only one entry: `path`. |
---|
| 26 | |
---|
| 27 | The directive can be put into site.zcml like this: |
---|
| 28 | |
---|
| 29 | - Add to the header: |
---|
[7811] | 30 | ``xmlns:kofa="http://namespaces.waeup.org/kofa"`` |
---|
[7576] | 31 | |
---|
[7811] | 32 | - Then, after including waeup.kofa: |
---|
| 33 | ``<kofa:datacenter path="some/existing/file/path" />`` |
---|
[7576] | 34 | |
---|
| 35 | In a running instance (where some directive like above was |
---|
| 36 | processed during startup), one can then ask for the |
---|
| 37 | IDataCenterConfig utility: |
---|
| 38 | |
---|
[7811] | 39 | >>> from waeup.kofa.interfaces import IDataCenterConfig |
---|
[7576] | 40 | >>> from zope.component import getUtility |
---|
| 41 | >>> getUtility(IDataCenterConfig) |
---|
| 42 | {'path': 'some/existing/file/path'} |
---|
| 43 | |
---|
| 44 | """ |
---|
| 45 | context.action( |
---|
| 46 | discriminator = ('utility', IDataCenterConfig, ''), |
---|
| 47 | callable = handler, |
---|
| 48 | args = ('registerUtility', |
---|
| 49 | {'path':path}, IDataCenterConfig, '') |
---|
| 50 | ) |
---|