# HG changeset patch # User Sylvain Thénault # Date 1304437433 -7200 # Node ID 93e96700e0c04a3352a20d95ec842fab5fa9b4e9 # Parent 4058ed1e3bc23b298bcc51db5faa5fbeda4b4ce9 [configuration] exit with proper message when sources file is unreadable (you usually started cw while logged with a wrong user). Closes #1631238 diff -r 4058ed1e3bc2 -r 93e96700e0c0 devtools/__init__.py --- a/devtools/__init__.py Tue May 03 13:57:18 2011 +0200 +++ b/devtools/__init__.py Tue May 03 17:43:53 2011 +0200 @@ -28,15 +28,17 @@ import pickle import glob import warnings +import hashlib from datetime import timedelta from os.path import (abspath, join, exists, basename, dirname, normpath, split, isfile, isabs, splitext, isdir, expanduser) from functools import partial -import hashlib from logilab.common.date import strptime from logilab.common.decorators import cached, clear_cache -from cubicweb import CW_SOFTWARE_ROOT, ConfigurationError, schema, cwconfig, BadConnectionId + +from cubicweb import ConfigurationError, ExecutionError, BadConnectionId +from cubicweb import CW_SOFTWARE_ROOT, schema, cwconfig from cubicweb.server.serverconfig import ServerConfiguration from cubicweb.etwist.twconfig import TwistedConfiguration @@ -197,7 +199,10 @@ directory from wich tests are launched or by specifying an alternative sources file using self.sourcefile. """ - sources = super(TestServerConfiguration, self).sources() + try: + sources = super(TestServerConfiguration, self).sources() + except ExecutionError: + sources = {} if not sources: sources = DEFAULT_SOURCES if 'admin' not in sources: diff -r 4058ed1e3bc2 -r 93e96700e0c0 server/serverconfig.py --- a/server/serverconfig.py Tue May 03 13:57:18 2011 +0200 +++ b/server/serverconfig.py Tue May 03 17:43:53 2011 +0200 @@ -255,7 +255,7 @@ # configuration file (#16102) @cached def read_sources_file(self): - return read_config(self.sources_file()) + return read_config(self.sources_file(), raise_if_unreadable=True) def sources(self): """return a dictionnaries containing sources definitions indexed by diff -r 4058ed1e3bc2 -r 93e96700e0c0 toolsutils.py --- a/toolsutils.py Tue May 03 13:57:18 2011 +0200 +++ b/toolsutils.py Tue May 03 17:43:53 2011 +0200 @@ -159,15 +159,11 @@ print '-> set permissions to 0600 for %s' % filepath chmod(filepath, 0600) -def read_config(config_file): - """read the instance configuration from a file and return it as a - dictionnary - - :type config_file: str - :param config_file: path to the configuration file - - :rtype: dict - :return: a dictionary with specified values associated to option names +def read_config(config_file, raise_if_unreadable=False): + """read some simple configuration from `config_file` and return it as a + dictionary. If `raise_if_unreadable` is false (the default), an empty + dictionary will be returned if the file is inexistant or unreadable, else + :exc:`ExecutionError` will be raised. """ from logilab.common.fileutils import lines config = current = {} @@ -190,8 +186,12 @@ value = value.strip() current[option] = value or None except IOError, ex: - warning('missing or non readable configuration file %s (%s)', - config_file, ex) + if raise_if_unreadable: + raise ExecutionError('%s. Are you logged with the correct user ' + 'to use this instance?' % ex) + else: + warning('missing or non readable configuration file %s (%s)', + config_file, ex) return config