source: mailjam/postman/config.py@ 13:f1f11159dbed

Last change on this file since 13:f1f11159dbed was 11:078c7b030cee, checked in by Borja Lopez <borja@…>, 12 years ago

Removed legacy configs from the config module

Added some headers to the sources (setting author, email, website
and references to the LICENSE)

File size: 1.8 KB
Line 
1# -*- coding: utf-8 -*-
2
3"""
4The postman project - config.py
5
6This file is released under the BSD license, see LICENSE for
7more information.
8
9Francisco de Borja Lopez Rio - <borja@codigo23.net>
10Soluciones Informaticas Codigo23 S.L.U. - http://codigo23.net
11"""
12
13import os
14from ConfigParser import SafeConfigParser
15
16def get_config_parameters(section=None, configfile=None):
17 if not configfile:
18 # If there is no config file defined, try with the usual places
19 # for config files, if there is no config file there, try to load
20 # the one provided with postman sources
21 default_paths = ['/usr/local/etc/postman/postman.conf',
22 '/usr/local/etc/postman.conf',
23 '/etc/postman/postman.conf',
24 '/etc/postman.conf',
25 os.path.join(os.path.dirname(__file__),
26 '../conf/postman.conf')]
27 for path in default_paths:
28 if os.path.exists(path):
29 configfile = path
30 break
31
32 # if there is no config file now, raise an exception, as we need one
33 if not configfile:
34 raise IOError('ERROR - Can not find postman.conf in your environment')
35
36 available_sections = ['xmlrpc_server', 'storage', 'archive',
37 'mailing_lists', 'members']
38
39 config = {}
40
41 parser = SafeConfigParser()
42 # FIXME: we should check here if the config file has been read correctly,
43 # instead of letting an exception to pass through
44 parser.read(configfile)
45
46 if section in available_sections:
47 for name, value in parser.items(section):
48 config[name] = value
49 return config
50
51 # if no section (or an invalid section) is provided, return an empty config
52 # set
53 return config
54
Note: See TracBrowser for help on using the repository browser.