2020-10-27 06:27:28 +08:00
|
|
|
import re
|
|
|
|
import os
|
|
|
|
from string import Template
|
|
|
|
|
|
|
|
with open("readme_template.md") as readme_file:
|
|
|
|
readme = readme_file.read()
|
|
|
|
|
|
|
|
codes = re.findall(r'\$code_([^\s]*)', readme)
|
|
|
|
demos = re.findall(r'\$demo_([^\s]*)', readme)
|
|
|
|
template_dict = {}
|
|
|
|
|
|
|
|
for code_src in codes:
|
|
|
|
with open(os.path.join("demo", code_src + ".py")) as code_file:
|
2021-02-27 02:51:51 +08:00
|
|
|
python_code = code_file.read()
|
|
|
|
python_code = python_code.replace('if __name__ == "__main__":\n iface.launch()', "iface.launch()")
|
|
|
|
if python_code.startswith("# Demo"):
|
|
|
|
python_code = "\n".join(python_code.split("\n")[2:])
|
2020-10-27 08:55:41 +08:00
|
|
|
template_dict["code_" + code_src] = "```python\n" + python_code + "\n```"
|
2020-10-27 06:27:28 +08:00
|
|
|
|
|
|
|
for demo_src in demos:
|
|
|
|
template_dict["demo_" + demo_src] = "![" + demo_src + " interface](demo/screenshots/" + demo_src + "/1.gif)"
|
|
|
|
|
|
|
|
readme_template = Template(readme)
|
|
|
|
output_readme = readme_template.substitute(template_dict)
|
|
|
|
|
|
|
|
with open("README.md", "w") as readme_md:
|
|
|
|
readme_md.write(output_readme)
|