1 | # -*- coding: utf-8 -*-
|
---|
2 |
|
---|
3 | import os
|
---|
4 | from ConfigParser import SafeConfigParser
|
---|
5 |
|
---|
6 | def get_config_parameters(section=None, configfile=None):
|
---|
7 | if not configfile:
|
---|
8 | # If there is no config file defined, try with the usual places
|
---|
9 | # for config files, if there is no config file there, try to load
|
---|
10 | # the one provided with postman sources
|
---|
11 | default_paths = ['/usr/local/etc/postman/postman.conf',
|
---|
12 | '/usr/local/etc/postman.conf',
|
---|
13 | '/etc/postman/postman.conf',
|
---|
14 | '/etc/postman.conf',
|
---|
15 | os.path.join(os.path.dirname(__file__),
|
---|
16 | '../conf/postman.conf')]
|
---|
17 | for path in default_paths:
|
---|
18 | if os.path.exists(path):
|
---|
19 | configfile = path
|
---|
20 | break
|
---|
21 |
|
---|
22 | # if there is no config file now, raise an exception, as we need one
|
---|
23 | if not configfile:
|
---|
24 | raise IOError('ERROR - Can not find postman.conf in your environment')
|
---|
25 |
|
---|
26 | available_sections = ['xmlrpc_server', 'storage', 'archive',
|
---|
27 | 'mailing_lists', 'members']
|
---|
28 |
|
---|
29 | config = {}
|
---|
30 |
|
---|
31 | parser = SafeConfigParser()
|
---|
32 | # FIXME: we should check here if the config file has been read correctly,
|
---|
33 | # instead of letting an exception to pass through
|
---|
34 | parser.read(configfile)
|
---|
35 |
|
---|
36 | if section in available_sections:
|
---|
37 | for name, value in parser.items(section):
|
---|
38 | config[name] = value
|
---|
39 | return config
|
---|
40 |
|
---|
41 | # if no section (or an invalid section) is provided, return an empty config
|
---|
42 | # set
|
---|
43 | return config
|
---|
44 |
|
---|
45 |
|
---|
46 | # The default path for storage files
|
---|
47 | storage_path = os.path.join(os.path.dirname(__file__), 'storage')
|
---|
48 |
|
---|
49 | # The default path for the archives
|
---|
50 | archive_path = os.path.join(os.path.dirname(__file__), 'archives')
|
---|
51 |
|
---|
52 | # Set to True to set that, by default, only emails from members
|
---|
53 | # will go into the list
|
---|
54 | private_mailing = True
|
---|