Mercurial > kallithea
annotate scripts/generate-ini.py @ 6060:40edadecda69
run-all-cleanup: fix incorrect interpreter
POSIX (and Debian) requires /bin/sh.
author | Søren Løvborg <sorenl@unity3d.com> |
---|---|
date | Thu, 28 Jul 2016 13:41:28 +0200 |
parents | 9358211ee144 |
children | b1fc5a98952c |
rev | line source |
---|---|
5536
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python2 |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
2 """ |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
3 Based on kallithea/bin/template.ini.mako, generate |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
4 kallithea/config/deployment.ini_tmpl |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
5 development.ini |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
6 kallithea/tests/test.ini |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
7 """ |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
8 |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
9 import re |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
10 |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
11 makofile = 'kallithea/bin/template.ini.mako' |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
12 |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
13 # the mako conditionals used in all other ini files and templates |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
14 selected_mako_conditionals = set([ |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
15 "database_engine == 'sqlite'", |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
16 "http_server == 'waitress'", |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
17 "error_aggregation_service == 'errormator'", |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
18 "error_aggregation_service == 'sentry'", |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
19 ]) |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
20 |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
21 # the mako variables used in all other ini files and templates |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
22 mako_variable_values = { |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
23 'host': '127.0.0.1', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
24 'port': '5000', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
25 'here': '%(here)s', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
26 'uuid()': '${app_instance_uuid}', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
27 } |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
28 |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
29 # files to be generated from the mako template |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
30 ini_files = [ |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
31 ('kallithea/config/deployment.ini_tmpl', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
32 ''' |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
33 Kallithea - Example config |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
34 |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
35 The %(here)s variable will be replaced with the parent directory of this file |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
36 ''', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
37 {}, # exactly the same settings as template.ini.mako |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
38 ), |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
39 ('kallithea/tests/test.ini', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
40 ''' |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
41 Kallithea - config for tests: |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
42 initial_repo_scan = true |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
43 sqlalchemy and kallithea_test.sqlite |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
44 custom logging |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
45 |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
46 The %(here)s variable will be replaced with the parent directory of this file |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
47 ''', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
48 { |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
49 '[server:main]': { |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
50 'port': '4999', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
51 }, |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
52 '[app:main]': { |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
53 'initial_repo_scan': 'true', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
54 'app_instance_uuid': 'test', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
55 'show_revision_number': 'true', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
56 'beaker.cache.sql_cache_short.expire': '1', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
57 'beaker.session.secret': '{74e0cd75-b339-478b-b129-07dd221def1f}', |
6038
9358211ee144
tests: move test data to top level 'data' folder - make grepping in kallithea/ easier
Mads Kiilerich <madski@unity3d.com>
parents:
5769
diff
changeset
|
58 'cache_dir': '%(here)s/../../data/test/cache', |
9358211ee144
tests: move test data to top level 'data' folder - make grepping in kallithea/ easier
Mads Kiilerich <madski@unity3d.com>
parents:
5769
diff
changeset
|
59 'index_dir': '%(here)s/../../data/test/index', |
9358211ee144
tests: move test data to top level 'data' folder - make grepping in kallithea/ easier
Mads Kiilerich <madski@unity3d.com>
parents:
5769
diff
changeset
|
60 'archive_cache_dir': '%(here)s/../../data/test/tarballcache', |
9358211ee144
tests: move test data to top level 'data' folder - make grepping in kallithea/ easier
Mads Kiilerich <madski@unity3d.com>
parents:
5769
diff
changeset
|
61 'beaker.cache.data_dir': '%(here)s/../../data/test/cache/data', |
9358211ee144
tests: move test data to top level 'data' folder - make grepping in kallithea/ easier
Mads Kiilerich <madski@unity3d.com>
parents:
5769
diff
changeset
|
62 'beaker.cache.lock_dir': '%(here)s/../../data/test/cache/lock', |
5536
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
63 'sqlalchemy.db1.url': 'sqlite:///%(here)s/kallithea_test.sqlite', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
64 }, |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
65 '[logger_root]': { |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
66 'level': 'DEBUG', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
67 }, |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
68 '[logger_sqlalchemy]': { |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
69 'level': 'ERROR', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
70 'handlers': 'console', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
71 }, |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
72 '[handler_console]': { |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
73 'level': 'NOTSET', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
74 }, |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
75 }, |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
76 ), |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
77 ('development.ini', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
78 ''' |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
79 Kallithea - Development config: |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
80 listening on *:5000 |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
81 sqlite and kallithea.db |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
82 initial_repo_scan = true |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
83 set debug = true |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
84 verbose and colorful logging |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
85 |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
86 The %(here)s variable will be replaced with the parent directory of this file |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
87 ''', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
88 { |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
89 '[server:main]': { |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
90 'host': '0.0.0.0', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
91 }, |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
92 '[app:main]': { |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
93 'initial_repo_scan': 'true', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
94 'set debug': 'true', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
95 'app_instance_uuid': 'development-not-secret', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
96 'beaker.session.secret': 'development-not-secret', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
97 }, |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
98 '[handler_console]': { |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
99 'level': 'DEBUG', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
100 'formatter': 'color_formatter', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
101 }, |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
102 '[handler_console_sql]': { |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
103 'level': 'DEBUG', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
104 'formatter': 'color_formatter_sql', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
105 }, |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
106 }, |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
107 ), |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
108 ] |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
109 |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
110 |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
111 def main(): |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
112 # make sure all mako lines starting with '#' (the '##' comments) are marked up as <text> |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
113 print 'reading:', makofile |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
114 mako_org = file(makofile).read() |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
115 mako_no_text_markup = re.sub(r'</?%text>', '', mako_org) |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
116 mako_marked_up = re.sub(r'\n(##.*)', r'\n<%text>\1</%text>', mako_no_text_markup, flags=re.MULTILINE) |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
117 if mako_marked_up != mako_org: |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
118 print 'writing:', makofile |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
119 file(makofile, 'w').write(mako_marked_up) |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
120 |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
121 # select the right mako conditionals for the other less sophisticated formats |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
122 def sub_conditionals(m): |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
123 """given a %if...%endif match, replace with just the selected |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
124 conditional sections enabled and the rest as comments |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
125 """ |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
126 conditional_lines = m.group(1) |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
127 def sub_conditional(m): |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
128 """given a conditional and the corresponding lines, return them raw |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
129 or commented out, based on whether conditional is selected |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
130 """ |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
131 criteria, lines = m.groups() |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
132 if criteria not in selected_mako_conditionals: |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
133 lines = '\n'.join((l if not l or l.startswith('#') else '#' + l) for l in lines.split('\n')) |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
134 return lines |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
135 conditional_lines = re.sub(r'^%(?:el)?if (.*):\n((?:^[^%\n].*\n|\n)*)', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
136 sub_conditional, conditional_lines, flags=re.MULTILINE) |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
137 return conditional_lines |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
138 mako_no_conditionals = re.sub(r'^(%if .*\n(?:[^%\n].*\n|%elif .*\n|\n)*)%endif\n', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
139 sub_conditionals, mako_no_text_markup, flags=re.MULTILINE) |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
140 |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
141 # expand mako variables |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
142 def pyrepl(m): |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
143 return mako_variable_values.get(m.group(1), m.group(0)) |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
144 mako_no_variables = re.sub(r'\${([^}]*)}', pyrepl, mako_no_conditionals) |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
145 |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
146 # remove utf-8 coding header |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
147 base_ini = re.sub(r'^## -\*- coding: utf-8 -\*-\n', '', mako_no_variables) |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
148 |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
149 # create ini files |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
150 for fn, desc, settings in ini_files: |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
151 print 'updating:', fn |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
152 ini_lines = re.sub( |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
153 '# Kallithea - config file generated with kallithea-config *#\n', |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
154 ''.join('# %-77s#\n' % l.strip() for l in desc.strip().split('\n')), |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
155 base_ini) |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
156 def process_section(m): |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
157 """process a ini section, replacing values as necessary""" |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
158 sectionname, lines = m.groups() |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
159 if sectionname in settings: |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
160 section_settings = settings[sectionname] |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
161 def process_line(m): |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
162 """process a section line and update value if necessary""" |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
163 setting, value = m.groups() |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
164 line = m.group(0) |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
165 if setting in section_settings: |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
166 line = '%s = %s' % (setting, section_settings[setting]) |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
167 if '$' not in value: |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
168 line = '#%s = %s\n%s' % (setting, value, line) |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
169 return line.rstrip() |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
170 lines = re.sub(r'^([^#\n].*) = ?(.*)', process_line, lines, flags=re.MULTILINE) |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
171 return sectionname + '\n' + lines |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
172 ini_lines = re.sub(r'^(\[.*\])\n((?:(?:[^[\n].*)?\n)*)', process_section, ini_lines, flags=re.MULTILINE) |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
173 file(fn, 'w').write(ini_lines) |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
174 |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
175 if __name__ == '__main__': |
06d5c043e989
ini: add scripts/generate-ini.py for generating all .ini files from template.ini.mako
Mads Kiilerich <madski@unity3d.com>
parents:
diff
changeset
|
176 main() |