Add --paste-global-conf option (#1304)

* Add --paste-global-conf option so users can pass arbitrary values to the PasteDeploy entrypoint from cli

* Reflect the suggestions: `--paste-global-conf` => `--paste-global` and adding more description in the docstring.
This commit is contained in:
Moriyoshi Koizumi 2016-07-17 04:15:23 +09:00 committed by Randall Leeds
parent 28c12b2668
commit d468d5b592
2 changed files with 42 additions and 1 deletions

View File

@ -56,7 +56,7 @@ class WSGIApplication(Application):
# load the paste app
from .pasterapp import load_pasteapp
return load_pasteapp(self.cfgurl, self.relpath, global_conf=None)
return load_pasteapp(self.cfgurl, self.relpath, global_conf=self.cfg.paste_global_conf)
def load(self):
if self.cfg.paste is not None:

View File

@ -14,6 +14,7 @@ except ImportError: # python 2.6
from . import argparse_compat as argparse
import os
import pwd
import re
import ssl
import sys
import textwrap
@ -203,6 +204,25 @@ class Config(object):
return True
@property
def paste_global_conf(self):
raw_global_conf = self.settings['raw_paste_global_conf'].get()
if raw_global_conf is None:
return None
global_conf = {}
for e in raw_global_conf:
s = _compat.bytes_to_str(e)
try:
k, v = re.split(r'(?<!\\)=', s, 1)
except ValueError:
raise RuntimeError("environment setting %r invalid" % s)
k = k.replace('\\=', '=')
v = v.replace('\\=', '=')
global_conf[k] = v
return global_conf
class SettingMeta(type):
def __new__(cls, name, bases, attrs):
@ -1765,3 +1785,24 @@ if sys.version_info >= (2, 7):
desc = """\
Ciphers to use (see stdlib ssl module's)
"""
class PasteGlobalConf(Setting):
name = "raw_paste_global_conf"
action = "append"
section = "Server Mechanics"
cli = ["--paste-global"]
meta = "CONF"
validator = validate_list_string
default = []
desc = """\
Set a PasteDeploy global config variable (key=value).
The option can be specified multiple times.
The variables are passed to the the PasteDeploy entrypoint. Ex.::
$ gunicorn -b 127.0.0.1:8000 --paste development.ini --paste-global FOO=1 --paste-global BAR=2
"""