-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-readme.py
More file actions
29 lines (21 loc) · 888 Bytes
/
update-readme.py
File metadata and controls
29 lines (21 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python3
"""Update README.md with content from config files."""
import re
from pathlib import Path
CONFIG_FILES = {
'GITCONFIG_EXAMPLE': '.gitconfig.example',
'GITCONFIG_GITHUB': '.gitconfig-github',
'GITCONFIG_GITLAB': '.gitconfig-gitlab',
}
def update_readme():
readme_path = Path('README.md')
content = readme_path.read_text()
for marker, config_file in CONFIG_FILES.items():
config_content = Path(config_file).read_text()
# Replace section between markers with config file content
pattern = f'(<!-- {marker}_START -->)\n\n```ini\n.*?\n```\n\n(<!-- {marker}_END -->)'
replacement = f'\\1\n\n```ini\n{config_content}```\n\n\\2'
content = re.sub(pattern, replacement, content, flags=re.DOTALL)
readme_path.write_text(content)
if __name__ == '__main__':
update_readme()