@@ -83,13 +83,13 @@ def __init__(self, root_path, defaults=None):
83
83
84
84
def from_envvar (self , variable_name , silent = False ):
85
85
"""Loads a configuration from an environment variable pointing to
86
- a configuration file. This basically is just a shortcut with nicer
86
+ a configuration file. This is basically just a shortcut with nicer
87
87
error messages for this line of code::
88
88
89
89
app.config.from_pyfile(os.environ['YOURAPPLICATION_SETTINGS'])
90
90
91
91
:param variable_name: name of the environment variable
92
- :param silent: set to `True` if you want silent failing for missing
92
+ :param silent: set to `True` if you want silent to fail for missing
93
93
files.
94
94
:return: bool. `True` if able to load config, `False` otherwise.
95
95
"""
@@ -105,24 +105,29 @@ def from_envvar(self, variable_name, silent=False):
105
105
self .from_pyfile (rv )
106
106
return True
107
107
108
- def from_pyfile (self , filename ):
108
+ def from_pyfile (self , filename , silent = False ):
109
109
"""Updates the values in the config from a Python file. This function
110
110
behaves as if the file was imported as module with the
111
111
:meth:`from_object` function.
112
112
113
113
:param filename: the filename of the config. This can either be an
114
114
absolute filename or a filename relative to the
115
115
root path.
116
+ :param silent: set to `True` if you want silent to fail for missing
117
+ files.
116
118
"""
117
119
filename = os .path .join (self .root_path , filename )
118
120
d = imp .new_module ('config' )
119
121
d .__file__ = filename
120
122
try :
121
123
execfile (filename , d .__dict__ )
122
124
except IOError , e :
125
+ if silent and e .errno in (errno .ENOENT , errno .EISDIR ):
126
+ return False
123
127
e .strerror = 'Unable to load configuration file (%s)' % e .strerror
124
128
raise
125
129
self .from_object (d )
130
+ return True
126
131
127
132
def from_object (self , obj ):
128
133
"""Updates the values from the given object. An object can be of one
0 commit comments