[7576] | 1 | ## |
---|
| 2 | ## zcml.py |
---|
| 3 | ## Login : <uli@pu.smp.net> |
---|
| 4 | ## Started on Fri Feb 3 04:26:49 2012 Uli Fouquet |
---|
| 5 | ## $Id$ |
---|
| 6 | ## |
---|
| 7 | ## Copyright (C) 2012 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 | from zope.component.zcml import handler |
---|
| 23 | from waeup.sirp.interfaces import IDataCenterConfig |
---|
| 24 | |
---|
| 25 | def data_center_conf(context, path): |
---|
| 26 | """Handler for ZCML ``datacenter`` directive. |
---|
| 27 | |
---|
| 28 | Registers a global utility under IDataCenterConfig and containing |
---|
| 29 | a dictionary with (currently) only one entry: `path`. |
---|
| 30 | |
---|
| 31 | The directive can be put into site.zcml like this: |
---|
| 32 | |
---|
| 33 | - Add to the header: |
---|
| 34 | ``xmlns:sirp="http://namespaces.waeup.org/sirp"`` |
---|
| 35 | |
---|
| 36 | - Then, after including waeup.sirp: |
---|
| 37 | ``<sirp:datacenter path="some/existing/file/path" />`` |
---|
| 38 | |
---|
| 39 | In a running instance (where some directive like above was |
---|
| 40 | processed during startup), one can then ask for the |
---|
| 41 | IDataCenterConfig utility: |
---|
| 42 | |
---|
| 43 | >>> from waeup.sirp.interfaces import IDataCenterConfig |
---|
| 44 | >>> from zope.component import getUtility |
---|
| 45 | >>> getUtility(IDataCenterConfig) |
---|
| 46 | {'path': 'some/existing/file/path'} |
---|
| 47 | |
---|
| 48 | """ |
---|
| 49 | context.action( |
---|
| 50 | discriminator = ('utility', IDataCenterConfig, ''), |
---|
| 51 | callable = handler, |
---|
| 52 | args = ('registerUtility', |
---|
| 53 | {'path':path}, IDataCenterConfig, '') |
---|
| 54 | ) |
---|