##// END OF EJS Templates
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako...
Mads Kiilerich -
r5536:06d5c043 default
parent child Browse files
Show More
@@ -0,0 +1,173 b''
1 #!/usr/bin/env python2
2 """
3 Based on kallithea/bin/template.ini.mako, generate
4 kallithea/config/deployment.ini_tmpl
5 development.ini
6 kallithea/tests/test.ini
7 """
8
9 import re
10
11 makofile = 'kallithea/bin/template.ini.mako'
12
13 # the mako conditionals used in all other ini files and templates
14 selected_mako_conditionals = set([
15 "database_engine == 'sqlite'",
16 "http_server == 'waitress'",
17 "error_aggregation_service == 'errormator'",
18 "error_aggregation_service == 'sentry'",
19 ])
20
21 # the mako variables used in all other ini files and templates
22 mako_variable_values = {
23 'host': '127.0.0.1',
24 'port': '5000',
25 'here': '%(here)s',
26 'uuid()': '${app_instance_uuid}',
27 }
28
29 # files to be generated from the mako template
30 ini_files = [
31 ('kallithea/config/deployment.ini_tmpl',
32 '''
33 Kallithea - Example config
34
35 The %(here)s variable will be replaced with the parent directory of this file
36 ''',
37 {}, # exactly the same settings as template.ini.mako
38 ),
39 ('kallithea/tests/test.ini',
40 '''
41 Kallithea - config for tests:
42 initial_repo_scan = true
43 vcs_full_cache = false
44 sqlalchemy and kallithea_test.sqlite
45 custom logging
46
47 The %(here)s variable will be replaced with the parent directory of this file
48 ''',
49 {
50 '[server:main]': {
51 'port': '4999',
52 },
53 '[app:main]': {
54 'initial_repo_scan': 'true',
55 'app_instance_uuid': 'test',
56 'vcs_full_cache': 'false',
57 'show_revision_number': 'true',
58 'beaker.cache.sql_cache_short.expire': '1',
59 'beaker.session.secret': '{74e0cd75-b339-478b-b129-07dd221def1f}',
60 'sqlalchemy.db1.url': 'sqlite:///%(here)s/kallithea_test.sqlite',
61 },
62 '[logger_root]': {
63 'level': 'DEBUG',
64 },
65 '[logger_sqlalchemy]': {
66 'level': 'ERROR',
67 'handlers': 'console',
68 },
69 '[handler_console]': {
70 'level': 'NOTSET',
71 },
72 },
73 ),
74 ('development.ini',
75 '''
76 Kallithea - Development config:
77 listening on *:5000
78 sqlite and kallithea.db
79 initial_repo_scan = true
80 set debug = true
81 verbose and colorful logging
82
83 The %(here)s variable will be replaced with the parent directory of this file
84 ''',
85 {
86 '[server:main]': {
87 'host': '0.0.0.0',
88 },
89 '[app:main]': {
90 'initial_repo_scan': 'true',
91 'set debug': 'true',
92 'app_instance_uuid': 'development-not-secret',
93 'beaker.session.secret': 'development-not-secret',
94 },
95 '[handler_console]': {
96 'level': 'DEBUG',
97 'formatter': 'color_formatter',
98 },
99 '[handler_console_sql]': {
100 'level': 'DEBUG',
101 'formatter': 'color_formatter_sql',
102 },
103 },
104 ),
105 ]
106
107
108 def main():
109 # make sure all mako lines starting with '#' (the '##' comments) are marked up as <text>
110 print 'reading:', makofile
111 mako_org = file(makofile).read()
112 mako_no_text_markup = re.sub(r'</?%text>', '', mako_org)
113 mako_marked_up = re.sub(r'\n(##.*)', r'\n<%text>\1</%text>', mako_no_text_markup, flags=re.MULTILINE)
114 if mako_marked_up != mako_org:
115 print 'writing:', makofile
116 file(makofile, 'w').write(mako_marked_up)
117
118 # select the right mako conditionals for the other less sophisticated formats
119 def sub_conditionals(m):
120 """given a %if...%endif match, replace with just the selected
121 conditional sections enabled and the rest as comments
122 """
123 conditional_lines = m.group(1)
124 def sub_conditional(m):
125 """given a conditional and the corresponding lines, return them raw
126 or commented out, based on whether conditional is selected
127 """
128 criteria, lines = m.groups()
129 if criteria not in selected_mako_conditionals:
130 lines = '\n'.join((l if not l or l.startswith('#') else '#' + l) for l in lines.split('\n'))
131 return lines
132 conditional_lines = re.sub(r'^%(?:el)?if (.*):\n((?:^[^%\n].*\n|\n)*)',
133 sub_conditional, conditional_lines, flags=re.MULTILINE)
134 return conditional_lines
135 mako_no_conditionals = re.sub(r'^(%if .*\n(?:[^%\n].*\n|%elif .*\n|\n)*)%endif\n',
136 sub_conditionals, mako_no_text_markup, flags=re.MULTILINE)
137
138 # expand mako variables
139 def pyrepl(m):
140 return mako_variable_values.get(m.group(1), m.group(0))
141 mako_no_variables = re.sub(r'\${([^}]*)}', pyrepl, mako_no_conditionals)
142
143 # remove utf-8 coding header
144 base_ini = re.sub(r'^## -\*- coding: utf-8 -\*-\n', '', mako_no_variables)
145
146 # create ini files
147 for fn, desc, settings in ini_files:
148 print 'updating:', fn
149 ini_lines = re.sub(
150 '# Kallithea - config file generated with kallithea-config *#\n',
151 ''.join('# %-77s#\n' % l.strip() for l in desc.strip().split('\n')),
152 base_ini)
153 def process_section(m):
154 """process a ini section, replacing values as necessary"""
155 sectionname, lines = m.groups()
156 if sectionname in settings:
157 section_settings = settings[sectionname]
158 def process_line(m):
159 """process a section line and update value if necessary"""
160 setting, value = m.groups()
161 line = m.group(0)
162 if setting in section_settings:
163 line = '%s = %s' % (setting, section_settings[setting])
164 if '$' not in value:
165 line = '#%s = %s\n%s' % (setting, value, line)
166 return line.rstrip()
167 lines = re.sub(r'^([^#\n].*) = ?(.*)', process_line, lines, flags=re.MULTILINE)
168 return sectionname + '\n' + lines
169 ini_lines = re.sub(r'^(\[.*\])\n((?:(?:[^[\n].*)?\n)*)', process_section, ini_lines, flags=re.MULTILINE)
170 file(fn, 'w').write(ini_lines)
171
172 if __name__ == '__main__':
173 main()
@@ -163,6 +163,7 b' max_request_body_size = 107374182400'
163 #cheaper-step = 1
163 #cheaper-step = 1
164
164
165 ## COMMON ##
165 ## COMMON ##
166 #host = 127.0.0.1
166 host = 0.0.0.0
167 host = 0.0.0.0
167 port = 5000
168 port = 5000
168
169
@@ -554,16 +555,16 b' propagate = 1'
554 class = StreamHandler
555 class = StreamHandler
555 args = (sys.stderr,)
556 args = (sys.stderr,)
556 #level = INFO
557 #level = INFO
558 level = DEBUG
557 #formatter = generic
559 #formatter = generic
558 level = DEBUG
559 formatter = color_formatter
560 formatter = color_formatter
560
561
561 [handler_console_sql]
562 [handler_console_sql]
562 class = StreamHandler
563 class = StreamHandler
563 args = (sys.stderr,)
564 args = (sys.stderr,)
564 #level = WARN
565 #level = WARN
566 level = DEBUG
565 #formatter = generic
567 #formatter = generic
566 level = DEBUG
567 formatter = color_formatter_sql
568 formatter = color_formatter_sql
568
569
569 ################
570 ################
@@ -163,6 +163,7 b' max_request_body_size = 107374182400'
163
163
164 ## COMMON ##
164 ## COMMON ##
165 host = 127.0.0.1
165 host = 127.0.0.1
166 #port = 5000
166 port = 4999
167 port = 4999
167
168
168 ## middleware for hosting the WSGI application under a URL prefix
169 ## middleware for hosting the WSGI application under a URL prefix
@@ -224,6 +225,7 b' rss_include_diff = false'
224
225
225 ## options for showing and identifying changesets
226 ## options for showing and identifying changesets
226 show_sha_length = 12
227 show_sha_length = 12
228 #show_revision_number = false
227 show_revision_number = true
229 show_revision_number = true
228
230
229 ## gist URL alias, used to create nicer urls for gist. This should be an
231 ## gist URL alias, used to create nicer urls for gist. This should be an
@@ -341,6 +343,7 b' beaker.cache.long_term.expire = 36000'
341 beaker.cache.long_term.key_length = 256
343 beaker.cache.long_term.key_length = 256
342
344
343 beaker.cache.sql_cache_short.type = memory
345 beaker.cache.sql_cache_short.type = memory
346 #beaker.cache.sql_cache_short.expire = 10
344 beaker.cache.sql_cache_short.expire = 1
347 beaker.cache.sql_cache_short.expire = 1
345 beaker.cache.sql_cache_short.key_length = 256
348 beaker.cache.sql_cache_short.key_length = 256
346
349
@@ -537,8 +540,8 b' propagate = 1'
537
540
538 [logger_sqlalchemy]
541 [logger_sqlalchemy]
539 #level = INFO
542 #level = INFO
543 level = ERROR
540 #handlers = console_sql
544 #handlers = console_sql
541 level = ERROR
542 handlers = console
545 handlers = console
543 qualname = sqlalchemy.engine
546 qualname = sqlalchemy.engine
544 propagate = 0
547 propagate = 0
General Comments 0
You need to be logged in to leave comments. Login now