Mercurial > libervia-backend
comparison sat/tools/config.py @ 2835:6aa22011bc6d
tools (config): log error message if config can't be read
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 03 Mar 2019 08:57:36 +0100 |
parents | 003b8b4b56a7 |
children | ad00f61fd9f5 |
comparison
equal
deleted
inserted
replaced
2834:6cd3549e8d67 | 2835:6aa22011bc6d |
---|---|
18 # You should have received a copy of the GNU Affero General Public License | 18 # You should have received a copy of the GNU Affero General Public License |
19 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 19 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | 20 |
21 """ Configuration related useful methods """ | 21 """ Configuration related useful methods """ |
22 | 22 |
23 import os | |
24 import csv | |
25 import json | |
26 from ConfigParser import SafeConfigParser, DEFAULTSECT, NoOptionError, NoSectionError | |
27 from xdg import BaseDirectory | |
23 from sat.core.log import getLogger | 28 from sat.core.log import getLogger |
24 | |
25 log = getLogger(__name__) | |
26 | |
27 from sat.core.constants import Const as C | 29 from sat.core.constants import Const as C |
28 from sat.core.i18n import _ | 30 from sat.core.i18n import _ |
29 from sat.core import exceptions | 31 from sat.core import exceptions |
30 | 32 |
31 from ConfigParser import SafeConfigParser, DEFAULTSECT, NoOptionError, NoSectionError | 33 log = getLogger(__name__) |
32 from xdg import BaseDirectory | |
33 import os | |
34 import csv | |
35 import json | |
36 | |
37 | 34 |
38 def fixConfigOption(section, option, value, silent=True): | 35 def fixConfigOption(section, option, value, silent=True): |
39 """Force a configuration option value, writing it in the first found user | 36 """Force a configuration option value, writing it in the first found user |
40 config file, eventually creating a new user config file if none is found. | 37 config file, eventually creating a new user config file if none is found. |
41 | 38 |
75 def parseMainConf(): | 72 def parseMainConf(): |
76 """look for main .ini configuration file, and parse it""" | 73 """look for main .ini configuration file, and parse it""" |
77 config = SafeConfigParser(defaults=C.DEFAULT_CONFIG) | 74 config = SafeConfigParser(defaults=C.DEFAULT_CONFIG) |
78 try: | 75 try: |
79 config.read(C.CONFIG_FILES) | 76 config.read(C.CONFIG_FILES) |
80 except: | 77 except Exception as e: |
81 log.error(_("Can't read main config !")) | 78 log.error(_(u"Can't read main config: {msg}").format(msg=e)) |
82 return config | 79 return config |
83 | 80 |
84 | 81 |
85 def getConfig(config, section, name, default=None): | 82 def getConfig(config, section, name, default=None): |
86 """Get a configuration option | 83 """Get a configuration option |