Skip to content
Myr

silent option added to 'from_pyfile' to mirror 'from_envvar'.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Aaron Kavlie · committed by Aaron Kavlie · parent b3fc9eb · Browse files · 1 file+8 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+8 added−3 removed

  • other:+8 added−3 removed

1 file+8 added−3 removed

modified:flask/config.py+8 added-3 removed
81 unmodified lines
82 self.root_path = root_path8384 def from_envvar(self, variable_name, silent=False):85 """Loads a configuration from an environment variable pointing to86 a configuration file. This basically is just a shortcut with nicer86 a configuration file. This is basically just a shortcut with nicer87 error messages for this line of code::8889 app.config.from_pyfile(os.environ['YOURAPPLICATION_SETTINGS'])9091 :param variable_name: name of the environment variable92 :param silent: set to `True` if you want silent failing for missing92 :param silent: set to `True` if you want silent to fail for missing93 files.94 :return: bool. `True` if able to load config, `False` otherwise.95 """96 rv = os.environ.get(variable_name)
7 unmodified lines
104 variable_name)105 self.from_pyfile(rv)106 return True107108 def from_pyfile(self, filename):108 def from_pyfile(self, filename, silent=False):109 """Updates the values in the config from a Python file. This function110 behaves as if the file was imported as module with the111 :meth:`from_object` function.112113 :param filename: the filename of the config. This can either be an114 absolute filename or a filename relative to the115 root path.116 :param silent: set to `True` if you want silent to fail for missing117 files.118 """119 filename = os.path.join(self.root_path, filename)120 d = imp.new_module('config')121 d.__file__ = filename122 try:123 execfile(filename, d.__dict__)124 except IOError, e:125 if silent and e.errno in (errno.ENOENT, errno.EISDIR):126 return False127 e.strerror = 'Unable to load configuration file (%s)' % e.strerror128 raise129 self.from_object(d)130 return True131132 def from_object(self, obj):133 """Updates the values from the given object. An object can be of one134 of the following two types:
28 unmodified lines