Mercurial > libervia-backend
comparison src/tools/config.py @ 1859:ac2ac7fe8a9b
core (memory, config): moved parseMainConf to tools/config so it can be used by frontends too
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 29 Feb 2016 16:13:47 +0100 |
parents | 5b8a859d5bb4 |
children | d1615f79dfe8 |
comparison
equal
deleted
inserted
replaced
1858:06e13ae616cf | 1859:ac2ac7fe8a9b |
---|---|
41 @param section (str): the config section | 41 @param section (str): the config section |
42 @param option (str): the config option | 42 @param option (str): the config option |
43 @param value (str): the new value | 43 @param value (str): the new value |
44 @param silent (boolean): toggle logging output (must be True when called from sat.sh) | 44 @param silent (boolean): toggle logging output (must be True when called from sat.sh) |
45 """ | 45 """ |
46 config = SafeConfigParser() | 46 config = SafeConfigParser(defaults=C.DEFAULT_CONFIG) |
47 target_file = None | 47 target_file = None |
48 for file_ in C.CONFIG_FILES[::-1]: | 48 for file_ in C.CONFIG_FILES[::-1]: |
49 # we will eventually update the existing file with the highest priority, if it's a user personal file... | 49 # we will eventually update the existing file with the highest priority, if it's a user personal file... |
50 if not silent: | 50 if not silent: |
51 log.debug(_(u"Testing file %s") % file_) | 51 log.debug(_(u"Testing file %s") % file_) |
66 if option in ('passphrase',): # list here the options storing a password | 66 if option in ('passphrase',): # list here the options storing a password |
67 value = '******' | 67 value = '******' |
68 log.warning(_(u"Config auto-update: %(option)s set to %(value)s in the file %(config_file)s") % | 68 log.warning(_(u"Config auto-update: %(option)s set to %(value)s in the file %(config_file)s") % |
69 {'option': option, 'value': value, 'config_file': target_file}) | 69 {'option': option, 'value': value, 'config_file': target_file}) |
70 | 70 |
71 def parseMainConf(): | |
72 """look for main .ini configuration file, and parse it""" | |
73 config = SafeConfigParser(defaults=C.DEFAULT_CONFIG) | |
74 try: | |
75 config.read(C.CONFIG_FILES) | |
76 except: | |
77 log.error(_("Can't read main config !")) | |
78 return config | |
71 | 79 |
72 def getConfig(config, section, name, default=None): | 80 def getConfig(config, section, name, default=None): |
73 """Get a configuration option | 81 """Get a configuration option |
74 | 82 |
75 @param config (SafeConfigParser): the configuration instance | 83 @param config (SafeConfigParser): the configuration instance |