source: main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/zcml.py @ 17672

Last change on this file since 17672 was 17242, checked in by Henrik Bettermann, 2 years ago

Merge with uli-paypal branch r17241.

File size: 2.3 KB
Line 
1## $Id$
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 os
19from zope.component.zcml import handler
20from zope.configuration.exceptions import ConfigurationError
21from kofacustom.nigeria.paypal.interfaces import IPaypalConfig
22from kofacustom.nigeria.paypal.config import parse_paypal_config
23
24
25def paypal_handler(path):
26    """ZCML handler that registers paypal configuration.
27
28    We expect paypal credentials written down in a config file. The
29    path to this config file can be set with the ZCML `paypalconf`
30    directive, which is handled here and looks like this::
31
32      <kofacustomng:paypalconf path='/some/path/to/paypal.conf' />
33
34    This handler requires the given path to exist and to be a file.
35
36    If the file exists and is readable, a dict with ``path`` and other
37    values read from the configuration file is registered as a global
38    unnamed utility for the `IPaypalConfig` interface.
39    """
40    if not os.path.exists(path):
41        raise ConfigurationError("No such file: %s" % path)
42    if not os.path.isfile(path):
43        raise ConfigurationError("Not a regular file: %s" % path)
44    config_dict = parse_paypal_config(path)
45    config_dict["path"] = path
46    return handler(
47        'registerUtility', config_dict, IPaypalConfig, '')
48
49
50def paypal_conf(context, path):
51    """Handler for ZCML paypalconf directive.
52
53    This handler registers the `paypal_handler` above to perform the
54    real configuration action.
55    """
56    context.action(
57        discriminator=('utility', IPaypalConfig, ''),
58        callable=paypal_handler,
59        args=(path, )
60        )
Note: See TracBrowser for help on using the repository browser.