<s> import os <EOL> import inspect <EOL> from docutils import nodes , utils <EOL> import gunicorn . config as guncfg <EOL> HEAD = """<STR_LIT>""" <EOL> ISSUE_URI = '<STR_LIT>' <EOL> PULL_REQUEST_URI = '<STR_LIT>' <EOL> def format_settings ( app ) : <EOL> settings_file = os . path . join ( app . srcdir , "<STR_LIT>" ) <EOL> ret = [ ] <EOL> for i , s in enumerate ( guncfg . KNOWN_SETTINGS ) : <EOL> if i == <NUM_LIT:0> or s . section != guncfg . KNOWN_SETTINGS [ i - <NUM_LIT:1> ] . section : <EOL> ret . append ( "<STR_LIT>" % ( s . section , "<STR_LIT:->" * len ( s . section ) ) ) <EOL> ret . append ( fmt_setting ( s ) ) <EOL> with open ( settings_file , '<STR_LIT:w>' ) as settings : <EOL> settings . write ( HEAD ) <EOL> settings . write ( '<STR_LIT>' . join ( ret ) ) <EOL> def fmt_setting ( s ) : <EOL> if callable ( s . default ) : <EOL> val = inspect . getsource ( s . default ) <EOL> val = "<STR_LIT:\n>" . join ( "<STR_LIT>" % l for l in val . splitlines ( ) ) <EOL> val = "<STR_LIT>" + val <EOL> else : <EOL> val = "<STR_LIT>" % s . default <EOL> if s . cli and s . meta : <EOL> args = [ "<STR_LIT>" % ( arg , s . meta ) for arg in s . cli ] <EOL> cli = '<STR_LIT:U+002CU+0020>' . join ( args ) <EOL> elif s . cli : <EOL> cli = "<STR_LIT:U+002CU+0020>" . join ( s . cli ) <EOL> out = [ ] <EOL> out . append ( "<STR_LIT:%s>" % s . name ) <EOL> out . append ( "<STR_LIT>" * len ( s . name ) ) <EOL> out . append ( "<STR_LIT>" ) <EOL> if s . cli : <EOL> out . append ( "<STR_LIT>" % cli ) <EOL> out . append ( "<STR_LIT>" % val ) <EOL> out . append ( "<STR_LIT>" ) <EOL> out . append ( s . desc ) <EOL> out . append ( "<STR_LIT>" ) <EOL> out . append ( "<STR_LIT>" ) <EOL> return "<STR_LIT:\n>" . join ( out ) <EOL> def issue_role ( typ , rawtext , text , lineno , inliner , options = { } , content = [ ] ) : <EOL> issue = utils . unescape ( text ) <EOL> text = '<STR_LIT>' + issue <EOL> refnode = nodes . reference ( text , text , refuri = ISSUE_URI % issue ) <EOL> return [ refnode ] , [ ] <EOL> def pull_request_role ( typ , rawtext , text , lineno , inliner , options = { } , content = [ ] ) : <EOL> issue = utils . unescape ( text ) <EOL> text = '<STR_LIT>' + issue <EOL> refnode = nodes . reference ( text , text , refuri = PULL_REQUEST_URI % issue ) <EOL> return [ refnode ] , [ ] <EOL> def setup ( app ) : <EOL> app . connect ( '<STR_LIT>' , format_settings ) <EOL> app . add_role ( '<STR_LIT>' , issue_role ) <EOL> app . add_role ( '<STR_LIT>' , pull_request_role ) </s>
