...
 
Commits (2)
...@@ -25,7 +25,6 @@ except ImportError: ...@@ -25,7 +25,6 @@ except ImportError:
from collections import OrderedDict from collections import OrderedDict
from decimal import Decimal from decimal import Decimal
import logging
import os import os
import io import io
import sys import sys
...@@ -33,6 +32,7 @@ import sys ...@@ -33,6 +32,7 @@ import sys
from weboob.tools.compat import basestring, unicode from weboob.tools.compat import basestring, unicode
from .iconfig import IConfig from .iconfig import IConfig
from .util import LOGGER
__all__ = ['INIConfig'] __all__ = ['INIConfig']
...@@ -50,7 +50,7 @@ class INIConfig(IConfig): ...@@ -50,7 +50,7 @@ class INIConfig(IConfig):
self.values = OrderedDict(default) self.values = OrderedDict(default)
if os.path.exists(self.path): if os.path.exists(self.path):
logging.debug(u'Loading application configuration file: %s.' % self.path) LOGGER.debug(u'Loading application configuration file: %s.' % self.path)
if sys.version_info.major < 3: if sys.version_info.major < 3:
self.config.readfp(io.open(self.path, "r", encoding='utf-8')) self.config.readfp(io.open(self.path, "r", encoding='utf-8'))
else: else:
...@@ -66,14 +66,14 @@ class INIConfig(IConfig): ...@@ -66,14 +66,14 @@ class INIConfig(IConfig):
first = True first = True
for key, value in self.config.items(DEFAULTSECT): for key, value in self.config.items(DEFAULTSECT):
if first: if first:
logging.warning('The configuration file "%s" uses an old-style' % self.path) LOGGER.warning('The configuration file "%s" uses an old-style' % self.path)
logging.warning('Please rename the %s section to %s' % (DEFAULTSECT, self.ROOTSECT)) LOGGER.warning('Please rename the %s section to %s' % (DEFAULTSECT, self.ROOTSECT))
first = False first = False
self.set(key, value) self.set(key, value)
logging.debug(u'Application configuration file loaded: %s.' % self.path) LOGGER.debug(u'Application configuration file loaded: %s.' % self.path)
else: else:
self.save() self.save()
logging.debug(u'Application configuration file created with default values: %s. ' LOGGER.debug(u'Application configuration file created with default values: %s. '
'Please customize it.' % self.path) 'Please customize it.' % self.path)
return self.values return self.values
......
...@@ -20,8 +20,12 @@ ...@@ -20,8 +20,12 @@
import os import os
from datetime import datetime from datetime import datetime
from weboob.tools.log import getLogger
__all__ = ['replace', 'time_buffer'] __all__ = ['LOGGER', 'replace', 'time_buffer']
LOGGER = getLogger('weboob.config')
try: try:
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # along with weboob. If not, see <http://www.gnu.org/licenses/>.
import logging
import os import os
import tempfile import tempfile
import sys import sys
...@@ -27,7 +26,7 @@ import weboob.tools.date ...@@ -27,7 +26,7 @@ import weboob.tools.date
import yaml import yaml
from .iconfig import ConfigError, IConfig from .iconfig import ConfigError, IConfig
from .util import replace from .util import LOGGER, replace
try: try:
from yaml import CLoader as Loader from yaml import CLoader as Loader
...@@ -67,14 +66,14 @@ class YamlConfig(IConfig): ...@@ -67,14 +66,14 @@ class YamlConfig(IConfig):
def load(self, default={}): def load(self, default={}):
self.values = default.copy() self.values = default.copy()
logging.debug(u'Loading application configuration file: %s.' % self.path) LOGGER.debug(u'Loading configuration file: %s.' % self.path)
try: try:
with open(self.path, 'r') as f: with open(self.path, 'r') as f:
self.values = yaml.load(f, Loader=self.LOADER) self.values = yaml.load(f, Loader=self.LOADER)
logging.debug(u'Application configuration file loaded: %s.' % self.path) LOGGER.debug(u'Configuration file loaded: %s.' % self.path)
except IOError: except IOError:
self.save() self.save()
logging.debug(u'Application configuration file created with default values: %s. Please customize it.' % self.path) LOGGER.debug(u'Configuration file created with default values: %s.' % self.path)
if self.values is None: if self.values is None:
self.values = {} self.values = {}
...@@ -88,6 +87,7 @@ class YamlConfig(IConfig): ...@@ -88,6 +87,7 @@ class YamlConfig(IConfig):
with f: with f:
yaml.dump(self.values, f, Dumper=self.DUMPER, default_flow_style=False) yaml.dump(self.values, f, Dumper=self.DUMPER, default_flow_style=False)
replace(f.name, self.path) replace(f.name, self.path)
LOGGER.debug(u'Configuration file saved: %s.' % self.path)
def get(self, *args, **kwargs): def get(self, *args, **kwargs):
v = self.values v = self.values
......