forked from benoitc/gunicorn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgunicorn_ext.py
executable file
·84 lines (64 loc) · 2.3 KB
/
gunicorn_ext.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import os
import inspect
from docutils import nodes, utils
import gunicorn.config as guncfg
HEAD = """\
.. Please update gunicorn/config.py instead.
.. _settings:
Settings
========
This is an exhaustive list of settings for Gunicorn. Some settings are only
able to be set from a configuration file. The setting name is what should be
used in the configuration file. The command line arguments are listed as well
for reference on setting at the command line.
"""
ISSUE_URI = 'https://github.com/benoitc/gunicorn/issues/%s'
PULL_REQUEST_URI = 'https://github.com/benoitc/gunicorn/pull/%s'
def format_settings(app):
settings_file = os.path.join(app.srcdir, "settings.rst")
ret = []
for i, s in enumerate(guncfg.KNOWN_SETTINGS):
if i == 0 or s.section != guncfg.KNOWN_SETTINGS[i - 1].section:
ret.append("%s\n%s\n\n" % (s.section, "-" * len(s.section)))
ret.append(fmt_setting(s))
with open(settings_file, 'w') as settings:
settings.write(HEAD)
settings.write(''.join(ret))
def fmt_setting(s):
if callable(s.default):
val = inspect.getsource(s.default)
val = "\n".join(" %s" % l for l in val.splitlines())
val = " ::\n\n" + val
else:
val = "``%s``" % s.default
if s.cli and s.meta:
args = ["%s %s" % (arg, s.meta) for arg in s.cli]
cli = ', '.join(args)
elif s.cli:
cli = ", ".join(s.cli)
out = []
out.append("%s" % s.name)
out.append("~" * len(s.name))
out.append("")
if s.cli:
out.append("* ``%s``" % cli)
out.append("* %s" % val)
out.append("")
out.append(s.desc)
out.append("")
out.append("")
return "\n".join(out)
def issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
issue = utils.unescape(text)
text = 'issue ' + issue
refnode = nodes.reference(text, text, refuri=ISSUE_URI % issue)
return [refnode], []
def pull_request_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
issue = utils.unescape(text)
text = 'pull request ' + issue
refnode = nodes.reference(text, text, refuri=PULL_REQUEST_URI % issue)
return [refnode], []
def setup(app):
app.connect('builder-inited', format_settings)
app.add_role('issue', issue_role)
app.add_role('pr', pull_request_role)