Replace everything between marker comments for section_name with new_text.
(content, ext, section_name, new_text)
| 135 | |
| 136 | |
| 137 | def replace_marker_section(content, ext, section_name, new_text): |
| 138 | """Replace everything between marker comments for section_name with new_text.""" |
| 139 | begin_tag, end_tag = MARKERS[ext] |
| 140 | begin = begin_tag.format(name=section_name) |
| 141 | end = end_tag.format(name=section_name) |
| 142 | |
| 143 | if begin not in content: |
| 144 | raise ValueError(f"BEGIN marker '{begin_tag.format(name=section_name)}' not found") |
| 145 | if end not in content: |
| 146 | raise ValueError(f"END marker '{end_tag.format(name=section_name)}' not found") |
| 147 | |
| 148 | before, rest = content.split(begin, 1) |
| 149 | _, after = rest.split(end, 1) |
| 150 | return before + begin + "\n" + new_text + "\n" + end + after |
| 151 | |
| 152 | |
| 153 | def generate_script(script_path, constants): |