Show More
@@ -386,9 +386,8 b' keys = generic, color_formatter, color_f' | |||||
386 | [logger_root] |
|
386 | [logger_root] | |
387 | level = NOTSET |
|
387 | level = NOTSET | |
388 | #handlers = console |
|
388 | #handlers = console | |
|
389 | ## For coloring based on log level: | |||
389 | handlers = console_color |
|
390 | handlers = console_color | |
390 | ## For coloring based on log level: |
|
|||
391 | #handlers = console_color |
|
|||
392 |
|
391 | |||
393 | [logger_routes] |
|
392 | [logger_routes] | |
394 | #level = WARN |
|
393 | #level = WARN |
@@ -103,20 +103,17 b' def expand(template, mako_variable_value' | |||||
103 | # option a was chosen |
|
103 | # option a was chosen | |
104 | <BLANKLINE> |
|
104 | <BLANKLINE> | |
105 | [comment-section] |
|
105 | [comment-section] | |
106 |
|
|
106 | variable3 = 3.0 | |
107 | #variable4 = 4.0 |
|
107 | #variable4 = 4.0 | |
|
108 | variable4 = 4.1 | |||
108 | #variable5 = 5.0 |
|
109 | #variable5 = 5.0 | |
109 | #variable5 = 5.1 |
|
110 | #variable5 = 5.1 | |
110 | variable5 = 5.2 |
|
111 | variable5 = 5.2 | |
111 | #variable6 = 6.0 |
|
112 | #variable6 = 6.0 | |
112 | #variable6 = 6.1 |
|
113 | #variable6 = 6.1 | |
113 |
|
|
114 | variable6 = 6.2 | |
114 | #variable7 = 7.1 |
|
|||
115 | variable7 = 7.0 |
|
115 | variable7 = 7.0 | |
116 | <BLANKLINE> |
|
116 | #variable7 = 7.1 | |
117 | variable3 = 3.0 |
|
|||
118 | variable4 = 4.1 |
|
|||
119 | variable6 = 6.2 |
|
|||
120 | <BLANKLINE> |
|
117 | <BLANKLINE> | |
121 | [fourth-section] |
|
118 | [fourth-section] | |
122 | fourth = "four" |
|
119 | fourth = "four" | |
@@ -143,20 +140,44 b' def expand(template, mako_variable_value' | |||||
143 | sectionname, lines = m.groups() |
|
140 | sectionname, lines = m.groups() | |
144 | if sectionname in settings: |
|
141 | if sectionname in settings: | |
145 | section_settings = settings.pop(sectionname) |
|
142 | section_settings = settings.pop(sectionname) | |
|
143 | add_after_key_value = {} # map key to value it should be added after | |||
146 |
|
144 | |||
147 |
|
|
145 | # 1st pass: | |
148 | """process a section line and update value if necessary""" |
|
146 | # comment out lines with keys that have new values | |
149 | key, value = m.groups() |
|
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 | line = m.group(0) |
|
150 | line = m.group(0) | |
151 | if key in section_settings: |
|
151 | comment, key, line_value = m.groups() | |
152 |
|
|
152 | if key not in section_settings: | |
153 |
|
|
153 | return line | |
154 | # keep old entry as example - comments might refer to it |
|
154 | new_value = section_settings[key] | |
155 | line = '#%s\n%s' % (line, new_line) |
|
155 | if line_value == new_value or add_after_key_value.get(key) != new_value: | |
156 | return line.rstrip() |
|
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 |
|
163 | def add_after_comment(m): | |
159 | lines = re.sub(r'^([^#\n\s]*)[ \t]*=[ \t]*(.*)$', process_line, lines, flags=re.MULTILINE) |
|
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 | # add unused section settings |
|
181 | # add unused section settings | |
161 | if section_settings: |
|
182 | if section_settings: | |
162 | lines += '\n' + ''.join('%s = %s\n' % (key, value) for key, value in sorted(section_settings.items())) |
|
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