Show More
@@ -386,9 +386,8 b' keys = generic, color_formatter, color_f' | |||
|
386 | 386 | [logger_root] |
|
387 | 387 | level = NOTSET |
|
388 | 388 | #handlers = console |
|
389 | ## For coloring based on log level: | |
|
389 | 390 | handlers = console_color |
|
390 | ## For coloring based on log level: | |
|
391 | #handlers = console_color | |
|
392 | 391 | |
|
393 | 392 | [logger_routes] |
|
394 | 393 | #level = WARN |
@@ -103,20 +103,17 b' def expand(template, mako_variable_value' | |||
|
103 | 103 | # option a was chosen |
|
104 | 104 | <BLANKLINE> |
|
105 | 105 | [comment-section] |
|
106 |
|
|
|
106 | variable3 = 3.0 | |
|
107 | 107 | #variable4 = 4.0 |
|
108 | variable4 = 4.1 | |
|
108 | 109 | #variable5 = 5.0 |
|
109 | 110 | #variable5 = 5.1 |
|
110 | 111 | variable5 = 5.2 |
|
111 | 112 | #variable6 = 6.0 |
|
112 | 113 | #variable6 = 6.1 |
|
113 |
|
|
|
114 | #variable7 = 7.1 | |
|
114 | variable6 = 6.2 | |
|
115 | 115 | variable7 = 7.0 |
|
116 | <BLANKLINE> | |
|
117 | variable3 = 3.0 | |
|
118 | variable4 = 4.1 | |
|
119 | variable6 = 6.2 | |
|
116 | #variable7 = 7.1 | |
|
120 | 117 | <BLANKLINE> |
|
121 | 118 | [fourth-section] |
|
122 | 119 | fourth = "four" |
@@ -143,20 +140,44 b' def expand(template, mako_variable_value' | |||
|
143 | 140 | sectionname, lines = m.groups() |
|
144 | 141 | if sectionname in settings: |
|
145 | 142 | section_settings = settings.pop(sectionname) |
|
143 | add_after_key_value = {} # map key to value it should be added after | |
|
146 | 144 | |
|
147 |
|
|
|
148 | """process a section line and update value if necessary""" | |
|
149 | key, value = m.groups() | |
|
145 | # 1st pass: | |
|
146 | # comment out lines with keys that have new values | |
|
147 | # find best line for keeping or un-commenting (because it has the right value) or adding after (because it is the last with other value) | |
|
148 | def comment_out(m): | |
|
149 | """process a section line if in section_settings and comment out and track in add_after_key_value""" | |
|
150 | 150 | line = m.group(0) |
|
151 | if key in section_settings: | |
|
152 |
|
|
|
153 |
|
|
|
154 | # keep old entry as example - comments might refer to it | |
|
155 | line = '#%s\n%s' % (line, new_line) | |
|
156 | return line.rstrip() | |
|
151 | comment, key, line_value = m.groups() | |
|
152 | if key not in section_settings: | |
|
153 | return line | |
|
154 | new_value = section_settings[key] | |
|
155 | if line_value == new_value or add_after_key_value.get(key) != new_value: | |
|
156 | add_after_key_value[key] = line_value | |
|
157 | if comment: | |
|
158 | return line | |
|
159 | return '#' + line | |
|
160 | ||
|
161 | lines = re.sub(r'^(#)?([^#\n\s]*)[ \t]*=[ \t]*(.*)$', comment_out, lines, flags=re.MULTILINE) | |
|
157 | 162 | |
|
158 | # process lines that not are comments or empty and look like name=value | |
|
159 | lines = re.sub(r'^([^#\n\s]*)[ \t]*=[ \t]*(.*)$', process_line, lines, flags=re.MULTILINE) | |
|
163 | def add_after_comment(m): | |
|
164 | """process a section comment line and add new value""" | |
|
165 | line = m.group(0) | |
|
166 | key, line_value = m.groups() | |
|
167 | if key not in section_settings: | |
|
168 | return line | |
|
169 | if line_value != add_after_key_value.get(key): | |
|
170 | return line | |
|
171 | new_value = section_settings[key] | |
|
172 | if new_value == line_value: | |
|
173 | line = line.lstrip('#') | |
|
174 | else: | |
|
175 | line += '\n%s = %s' % (key, new_value) | |
|
176 | section_settings.pop(key) | |
|
177 | return line | |
|
178 | ||
|
179 | lines = re.sub(r'^#([^#\n\s]*)[ \t]*=[ \t]*(.*)$', add_after_comment, lines, flags=re.MULTILINE) | |
|
180 | ||
|
160 | 181 | # add unused section settings |
|
161 | 182 | if section_settings: |
|
162 | 183 | lines += '\n' + ''.join('%s = %s\n' % (key, value) for key, value in sorted(section_settings.items())) |
General Comments 0
You need to be logged in to leave comments.
Login now