Changeset 9:69d5a3b74c6a in mailjam for postman
- Timestamp:
- May 19, 2012, 10:14:00 AM (13 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- postman
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
postman/config.py
r2 r9 2 2 3 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 4 45 5 46 # The default path for storage files -
postman/daemon.py
r7 r9 12 12 13 13 def __init__(self, configfile=None): 14 if not configfile: 15 # FIXME: This is not used right now, we are getting the stuff 16 # from postman.config, but we will move configurations to a 17 # external ini-style config file soon 18 configfile = os.path.join(os.path.dirname(__file__), 19 '../conf/postman.conf') 20 self.configfile = configfile 14 self.storage_config = config.get_config_parameters('storage', 15 configfile) 16 self.archive_config = config.get_config_parameters('archive', 17 configfile) 21 18 22 19 # lists were the currently managed mailing lists information is going … … 27 24 # the files were internal information (like active mailing lists, 28 25 # members, etc) is saved 29 self.dbs = {'mailings': Storage(os.path.join(config.storage_path, 30 'mailings.json')), 31 'members': Storage(os.path.join(config.storage_path, 32 'members.json'))} 26 self.dbs = {'mailings': Storage(self.storage_config['lists_db']), 27 'members': Storage(self.storage_config['members_db'])} 33 28 34 29 def save(self): … … 178 173 def add(self, member_addr=None, list_addr=None): 179 174 self.postman.add_mailing_member(member_addr, list_addr) 180 181 175 176 177 182 178 class PostmanDaemon(): 183 179 def __init__(self, configfile=None): 184 if not configfile: 185 # FIXME: This is not used right now, we are getting the stuff 186 # from postman.config, but we will move configurations to a 187 # external ini-style config file soon 188 configfile = os.path.join(os.path.dirname(__file__), 189 '../conf/postman.conf') 190 self.configfile = configfile 180 self.config = config.get_config_parameters('xmlrpc_server', configfile) 191 181 192 182 # FIXME: These should be loaded from a config file 193 self.address='localhost' 194 self.port = 9000 195 196 self.logfile = os.path.join(os.path.dirname(__file__), 'server.log') 183 self.address = self.config.get('address', 'localhost') 184 self.port = int(self.config.get('port', 9876)) 185 self.logfile = self.config.get('logfile', 186 os.path.join(os.path.dirname(__file__), 187 'server.log')) 197 188 logging.basicConfig(filename=self.logfile, level=logging.DEBUG) 198 189 -
postman/tests/daemon.py
r7 r9 186 186 p.terminate() 187 187 188
Note:
See TracChangeset
for help on using the changeset viewer.