diff --git a/flask/config.py b/flask/config.py index aa65f460..2b7499a4 100644 --- a/flask/config.py +++ b/flask/config.py @@ -83,13 +83,13 @@ class Config(dict): def from_envvar(self, variable_name, silent=False): """Loads a configuration from an environment variable pointing to - a configuration file. This basically is just a shortcut with nicer + a configuration file. This is basically just a shortcut with nicer error messages for this line of code:: app.config.from_pyfile(os.environ['YOURAPPLICATION_SETTINGS']) :param variable_name: name of the environment variable - :param silent: set to `True` if you want silent failing for missing + :param silent: set to `True` if you want silent to fail for missing files. :return: bool. `True` if able to load config, `False` otherwise. """ @@ -105,7 +105,7 @@ class Config(dict): self.from_pyfile(rv) return True - def from_pyfile(self, filename): + def from_pyfile(self, filename, silent=False): """Updates the values in the config from a Python file. This function behaves as if the file was imported as module with the :meth:`from_object` function. @@ -113,6 +113,8 @@ class Config(dict): :param filename: the filename of the config. This can either be an absolute filename or a filename relative to the root path. + :param silent: set to `True` if you want silent to fail for missing + files. """ filename = os.path.join(self.root_path, filename) d = imp.new_module('config') @@ -120,9 +122,12 @@ class Config(dict): try: execfile(filename, d.__dict__) except IOError, e: + if silent and e.errno in (errno.ENOENT, errno.EISDIR): + return False e.strerror = 'Unable to load configuration file (%s)' % e.strerror raise self.from_object(d) + return True def from_object(self, obj): """Updates the values from the given object. An object can be of one