-
Notifications
You must be signed in to change notification settings - Fork 0
/
readme.py
41 lines (34 loc) · 1.56 KB
/
readme.py
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
30
31
32
33
34
35
36
37
38
39
40
41
"""
Fills in the variable fields of the README template and generates README.md file.
"""
from musify import PROGRAM_OWNER_USER, PROGRAM_NAME
from musify.libraries.local.track import TRACK_FILETYPES
from musify.libraries.local.playlist import PLAYLIST_FILETYPES
from musify.libraries.local.library import LIBRARY_CLASSES, LocalLibrary
from musify.utils import SafeDict
from musify.libraries.remote.spotify.wrangle import SpotifyDataWrangler
SRC_FILENAME = "README.template.md"
TRG_FILENAME = SRC_FILENAME.replace(".template", "")
def format_readme():
"""Format the readme template and save the formatted readme"""
format_map_standard = {
"program_name": PROGRAM_NAME,
"program_name_lower": PROGRAM_NAME.lower(),
"program_owner_user": PROGRAM_OWNER_USER,
}
format_map_code = {
"local_sources": sorted(cls.source for cls in LIBRARY_CLASSES if cls != LocalLibrary),
"remote_sources": [SpotifyDataWrangler.source],
"track_filetypes": sorted(TRACK_FILETYPES),
"playlist_filetypes": sorted(PLAYLIST_FILETYPES),
}
format_map_code = {k: "`" + "` `".join(v) + "`" for k, v in format_map_code.items()}
format_map = SafeDict(format_map_standard | format_map_code)
with open(SRC_FILENAME, 'r') as file:
template = file.read()
formatted = template.format_map(format_map)
with open(TRG_FILENAME, 'w') as file:
file.write(formatted)
if __name__ == "__main__":
format_readme()
print(f"Formatted {TRG_FILENAME} file using template: {SRC_FILENAME}")