本文整理汇总了Python中flask.Config.from_envvar方法的典型用法代码示例。如果您正苦于以下问题:Python Config.from_envvar方法的具体用法?Python Config.from_envvar怎么用?Python Config.from_envvar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.Config
的用法示例。
在下文中一共展示了Config.from_envvar方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from flask import Config [as 别名]
# 或者: from flask.Config import from_envvar [as 别名]
def main(expected):
config = Config(here)
config.from_object('ooi_status.default_settings')
if 'OOISTATUS_SETTINGS' in os.environ:
config.from_envvar('OOISTATUS_SETTINGS')
for key in config:
log.info('OOI_STATUS CONFIG: %r: %r', key, config[key])
monitor = StatusMonitor(config)
if expected:
monitor.read_expected_csv(expected)
else:
scheduler = BlockingScheduler()
log.info('adding jobs')
# notify on change every minute
scheduler.add_job(monitor.check_all, 'cron', second=0)
scheduler.add_job(monitor.notify_all, 'cron', second=10)
log.info('starting jobs')
scheduler.start()
示例2: get_user_config
# 需要导入模块: from flask import Config [as 别名]
# 或者: from flask.Config import from_envvar [as 别名]
def get_user_config():
from flask import Config
config = Config('/')
config.from_object('alerta.settings')
config.from_pyfile('/etc/alertad.conf', silent=True)
config.from_envvar('ALERTA_SVR_CONF_FILE', silent=True)
if 'DEBUG' in os.environ:
config['DEBUG'] = True
if 'BASE_URL' in os.environ:
config['BASE_URL'] = os.environ['BASE_URL']
if 'USE_PROXYFIX' in os.environ:
config['USE_PROXYFIX'] = True if os.environ['USE_PROXYFIX'] == 'True' else False
if 'SECRET_KEY' in os.environ:
config['SECRET_KEY'] = os.environ['SECRET_KEY']
database_url = (
os.environ.get('DATABASE_URL', None) or
# The following database settings are deprecated.
os.environ.get('MONGO_URI', None) or
os.environ.get('MONGODB_URI', None) or
os.environ.get('MONGOHQ_URL', None) or
os.environ.get('MONGOLAB_URI', None)
)
# Use app config for DATABASE_URL if no env var from above override it
config['DATABASE_URL'] = database_url or config['DATABASE_URL']
if 'DATABASE_NAME' in os.environ:
config['DATABASE_NAME'] = os.environ['DATABASE_NAME']
if 'AUTH_REQUIRED' in os.environ:
config['AUTH_REQUIRED'] = True if os.environ['AUTH_REQUIRED'] == 'True' else False
if 'AUTH_PROVIDER' in os.environ:
config['AUTH_PROVIDER'] = os.environ['AUTH_PROVIDER']
if 'ADMIN_USERS' in os.environ:
config['ADMIN_USERS'] = os.environ['ADMIN_USERS'].split(',')
if 'SIGNUP_ENABLED' in os.environ:
config['SIGNUP_ENABLED'] = True if os.environ['SIGNUP_ENABLED'] == 'True' else False
if 'CUSTOMER_VIEWS' in os.environ:
config['CUSTOMER_VIEWS'] = True if os.environ['CUSTOMER_VIEWS'] == 'True' else False
if 'OAUTH2_CLIENT_ID' in os.environ:
config['OAUTH2_CLIENT_ID'] = os.environ['OAUTH2_CLIENT_ID']
if 'OAUTH2_CLIENT_SECRET' in os.environ:
config['OAUTH2_CLIENT_SECRET'] = os.environ['OAUTH2_CLIENT_SECRET']
if 'ALLOWED_EMAIL_DOMAINS' in os.environ:
config['ALLOWED_EMAIL_DOMAINS'] = os.environ['ALLOWED_EMAIL_DOMAINS'].split(',')
if 'AZURE_TENANT' in os.environ:
config['AZURE_TENANT'] = os.environ['AZURE_TENANT']
if 'GITHUB_URL' in os.environ:
config['GITHUB_URL'] = os.environ['GITHUB_URL']
if 'ALLOWED_GITHUB_ORGS' in os.environ:
config['ALLOWED_GITHUB_ORGS'] = os.environ['ALLOWED_GITHUB_ORGS'].split(',')
if 'GITLAB_URL' in os.environ:
config['GITLAB_URL'] = os.environ['GITLAB_URL']
if 'ALLOWED_GITLAB_GROUPS' in os.environ:
config['ALLOWED_OIDC_ROLES'] = os.environ['ALLOWED_GITLAB_GROUPS'].split(',')
if 'KEYCLOAK_URL' in os.environ:
config['KEYCLOAK_URL'] = os.environ['KEYCLOAK_URL']
if 'KEYCLOAK_REALM' in os.environ:
config['KEYCLOAK_REALM'] = os.environ['KEYCLOAK_REALM']
if 'ALLOWED_KEYCLOAK_ROLES' in os.environ:
config['ALLOWED_OIDC_ROLES'] = os.environ['ALLOWED_KEYCLOAK_ROLES'].split(',')
if 'OIDC_ISSUER_URL' in os.environ:
config['OIDC_ISSUER_URL'] = os.environ['OIDC_ISSUER_URL']
if 'ALLOWED_OIDC_ROLES' in os.environ:
config['ALLOWED_OIDC_ROLES'] = os.environ['ALLOWED_OIDC_ROLES'].split(',')
if 'PINGFEDERATE_OPENID_ACCESS_TOKEN_URL' in os.environ:
config['PINGFEDERATE_OPENID_ACCESS_TOKEN_URL'] = os.environ['PINGFEDERATE_OPENID_ACCESS_TOKEN_URL'].split(
',')
if 'PINGFEDERATE_OPENID_PAYLOAD_USERNAME' in os.environ:
config['PINGFEDERATE_OPENID_PAYLOAD_USERNAME'] = os.environ['PINGFEDERATE_OPENID_PAYLOAD_USERNAME'].split(
',')
if 'PINGFEDERATE_OPENID_PAYLOAD_EMAIL' in os.environ:
config['PINGFEDERATE_OPENID_PAYLOAD_EMAIL'] = os.environ['PINGFEDERATE_OPENID_PAYLOAD_EMAIL'].split(',')
if 'PINGFEDERATE_OPENID_PAYLOAD_GROUP' in os.environ:
#.........这里部分代码省略.........
示例3: Config
# 需要导入模块: from flask import Config [as 别名]
# 或者: from flask.Config import from_envvar [as 别名]
from flask import Config
cfg = Config('.')
cfg.from_envvar('TIGERGRADER_SETTINGS')
示例4: Configurator
# 需要导入模块: from flask import Config [as 别名]
# 或者: from flask.Config import from_envvar [as 别名]
class Configurator(object):
"""
Object that takes care of loading the different configurations from the
different sources. There are 3 types of settings:
* Project: The basic set of settings needed by the system. These are
shipped with Shiva.
* Local: Specific to each instance, useful for overwriting system
settings. Some of them must be defined before running Shiva, like the
DB URI.
* Debug: This setting will only be loaded if ``DEBUG`` is set to True
in the local settings.
There are also 3 different places where Shiva looks for this config files:
* A ``local.py`` file inside the ``config/`` directory, relative to
Shiva.
* The ``$SHIVA_CONFIG`` environment variable. It's assumed to be
pointing to a file (not a dir) if exists.
* The ``$XDG_CONFIG_HOME/shiva/config.py`` file. If
``$XDG_CONFIG_HOME`` is not set, defaults to ``$HOME/.config``, as
defined by the `XDG Base Directory Specification
<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest\
.html>`_.
"""
def __init__(self):
self._config = FlaskConfig("")
# project
_project = self.load_project()
# local
_xdg_config = self.from_xdg_config()
_env = self.from_env()
_local = self.from_local()
# debug
_debug = self.load_debug()
self.extract_conf(self._config)
if not (_xdg_config or _env or _local):
raise NoConfigFoundError
def load_project(self):
return self._config.from_object(project)
def get_xdg_path(self):
path_home = os.getenv("HOME")
if not path_home:
return None
default_config_home = os.path.join(path_home, ".config")
return os.getenv("XDG_CONFIG_HOME") or default_config_home
def from_xdg_config(self):
xdg_path = self.get_xdg_path()
if not xdg_path:
return False
local_py = os.path.join(xdg_path, "shiva/config.py")
if not os.path.exists(local_py):
return False
return self._config.from_pyfile(local_py)
def from_env(self):
if not os.getenv("SHIVA_CONFIG"):
return False
return self._config.from_envvar("SHIVA_CONFIG")
def from_local(self):
with ignored(ImportError):
self._config.from_object("shiva.config.local")
return True
return False
def load_debug(self):
if not self._config.get("DEBUG"):
return False
loaded = False
with ignored(ImportError):
from shiva.config import debug
loaded = self._config.from_object(debug)
xdg_path = self.get_xdg_path()
if not xdg_path:
return False
debug_py = os.path.join(xdg_path, "shiva/debug.py")
if not os.path.exists(debug_py):
return False
return self._config.from_pyfile(debug_py) or loaded
#.........这里部分代码省略.........
示例5: configure_engine
# 需要导入模块: from flask import Config [as 别名]
# 或者: from flask.Config import from_envvar [as 别名]
engine = None
sessionmaker = sa.orm.sessionmaker()
session = sa.orm.scoped_session(sessionmaker)
def configure_engine(url):
global sessionmaker, engine, session
engine = sa.create_engine(url)
session.remove()
sessionmaker.configure(bind=engine)
_config = Config('')
_config.from_object('config')
_config.from_envvar('MULCHN_CONFIG', silent=True)
configure_engine(_config.get('DATABASE_URL'))
class _Base(object):
@declared_attr
def __tablename__(cls):
"""
Convert CamelCase class name to underscores_between_words
table name.
"""
name = cls.__name__
return (
name[0].lower() +
re.sub(r'([A-Z])', lambda m:"_" + m.group(0).lower(), name[1:])
)
示例6: LoginManager
# 需要导入模块: from flask import Config [as 别名]
# 或者: from flask.Config import from_envvar [as 别名]
from flask.ext.login import LoginManager, login_required, \
login_user, logout_user
from matchmaker import app
from models import User, BotIdentity
# Wire everything up
login_manager = LoginManager()
login_manager.init_app(app)
oauth = OAuth(app)
# Casino GitHub OAuth
oauth_config = Config("")
oauth_config.from_object('matchmaker.default_oauth')
oauth_config.from_envvar('CASINO_OAUTH', silent=True)
github = oauth.remote_app(
'github',
**{k.lower(): v for k, v in oauth_config.items()}
)
@app.route('/login')
def login():
return github.authorize(
callback=url_for('authorized', _external=True,
_scheme=app.config.get("PREFERRED_URL_SCHEME"))
)
@app.route('/logout')