From 6b3c47b8264a4cf3c11d97183baabb75f6b749d5 Mon Sep 17 00:00:00 2001 From: Alessio Sergi Date: Sun, 22 Feb 2015 12:12:12 +0100 Subject: [PATCH] Fix logging support for Python 2.6 Use logutils when running on Python 2.6. Close #512. --- glances/core/glances_logging.py | 19 +++++++++---------- setup.py | 5 ++--- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/glances/core/glances_logging.py b/glances/core/glances_logging.py index c7cb7e94..2900ae7c 100644 --- a/glances/core/glances_logging.py +++ b/glances/core/glances_logging.py @@ -20,7 +20,12 @@ """Custom logging class""" import logging -import logging.config +try: + # Python 2.6 + from logutils.dictconfig import dictConfig +except ImportError: + # Python >= 2.7 + from logging.config import dictConfig import os import tempfile @@ -86,15 +91,9 @@ def glances_logger(): """Build and return the logger""" temp_path = tempfile_name() _logger = logging.getLogger() - try: - LOGGING_CFG['handlers']['file']['filename'] = temp_path - logging.config.dictConfig(LOGGING_CFG) - except AttributeError: - # dictConfig is only available for Python 2.7 or higher - # Minimal configuration for Python 2.6 - logging.basicConfig(filename=temp_path, - level=logging.DEBUG, - format='%(asctime)s -- %(levelname)s -- %(message)s') + LOGGING_CFG['handlers']['file']['filename'] = temp_path + dictConfig(LOGGING_CFG) + return _logger logger = glances_logger() diff --git a/setup.py b/setup.py index f598e2bf..ae3af32f 100755 --- a/setup.py +++ b/setup.py @@ -31,7 +31,6 @@ def get_data_files(): conf_path = os.path.join(os.environ.get('APPDATA'), 'glances') else: # Unix-like + per-user install conf_path = os.path.join('etc', 'glances') - data_files.append((conf_path, ['conf/glances.conf'])) for mo in glob.glob('i18n/*/LC_MESSAGES/*.mo'): @@ -45,8 +44,8 @@ def get_requires(): requires = ['psutil>=2.0.0'] if sys.platform.startswith('win'): requires += ['colorconsole'] - if sys.version_info < (2, 7): - requires += ['argparse'] + if sys.version_info == (2, 6): + requires += ['argparse', 'logutils'] return requires