This repository has been archived by the owner on Apr 20, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
readme_updater.py
81 lines (70 loc) · 3.1 KB
/
readme_updater.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from modules.cache.cache_manager import get_packages
from modules.configuration.config_extractor import get_configuration
from modules.languages.language_pack_manager import get_language_pack
import glob
import pickle
config = get_configuration()
packages_path = get_packages(
config["PACKAGES"]["packages_path"],
str(config["PACKAGES"]["ignore"]).split(sep=", "))
command_list = get_language_pack()["COMMANDS"]
help_list = get_language_pack()["HELP"]
readme_packages_path = config["PACKAGES"]["packages_path"] + "/README.md"
readme_help_path = config["COMMON"]["yapi_dir"] + "/README.md"
def packages_update(packages, readme_path):
start_update = True
continue_read = True
readme_updated = list()
with open(readme_path, "r") as readme:
for line in readme.readlines():
if not continue_read:
if start_update:
for package_counter in packages:
readme_updated.append(
str("- {0} - {1} - {2}".format(
packages[package_counter][0].capitalize(),
packages[package_counter][1],
packages[package_counter][2])))
start_update = False
if line == "<!--readme_update end packages -->\n":
readme_updated.append(line)
continue_read = True
else:
starter = "<!--readme_update start packages -->\n"
continue_read = line != starter
readme_updated.append(line)
del start_update, continue_read
with open(readme_path, "w") as readme:
for line in readme_updated:
print(line.strip("\n"), file=readme)
del readme_path, readme_updated
def help_update(commands, help, readme_path):
start_update = True
continue_read = True
readme_updated = list()
with open(readme_path, "r") as readme:
for line in readme.readlines():
if not continue_read:
if start_update:
for command in commands:
if not command == "description":
readme_updated.append(
str("To {}: \n \n \tyapi {} {} \n \n"
.format(
str(help[command]).lower(),
command,
commands[command])))
start_update = False
if line == "<!--readme_update end help -->\n":
readme_updated.append(line)
continue_read = True
else:
continue_read = line != "<!--readme_update start help -->\n"
readme_updated.append(line)
del start_update, continue_read
with open(readme_path, "w") as readme:
for line in readme_updated:
print(line.strip("\n"), file=readme)
del readme_path, readme_updated
packages_update(packages_path, readme_packages_path)
help_update(command_list, help_list, readme_help_path)