-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_readme.py
95 lines (61 loc) · 3.04 KB
/
create_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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: mustafa
"""
readme_file_name = "README.md"
import os
import json
from os import path
import urllib.parse
from functools import cmp_to_key
def create_header(f):
f.write("# Omniscope Project templates")
f.write(" · ")
f.write("[](https://github.com/visokio/omniscope-project-templates/actions/workflows/refresh_index.yml)")
f.write("[](https://github.com/visokio/omniscope-project-templates/actions/workflows/refresh_readme.yml)")
f.write("\n\n")
f.write("Public repository for project templates for Omniscope Evo.\n")
f.write("\n")
def get_templateName(t):
return t["name"]
def create_template_overview(f, templates):
f.write("## Template Overview\n")
templates.sort(key=get_templateName)
for aTemplate in templates:
f.write(f'<div id="{aTemplate["id"]}"/>\n\n')
f.write(f'### {aTemplate["name"]}\n\n')
has_thumbnail = "thumbnail" in aTemplate
if has_thumbnail:
f.write(f'<img align="right" src="https://github.com/visokio/omniscope-project-templates/blob/master/{aTemplate["thumbnail"]}" width="150px" height="auto"/>\n\n')
f.write(f'{aTemplate["description"]}\n\n')
f.write(f'Version: {aTemplate["version"]}\n\n')
f.write(f'[Link to Github page]({aTemplate["relative_path"]})\n\n')
def process_directory(root_path: str, path_parts, templates):
with open(root_path+"/index.json", 'r') as manifest_file:
indexJson = json.load(manifest_file)
if "version" in indexJson:
if (int(indexJson["version"]) < 2): return # Not supported versions less than 1
relative_path = os.sep.join(path_parts)
id = "".join(list(map(lambda s: s.replace(" ", ""), path_parts)))
aTemplate = {}
aTemplate["id"] = id
aTemplate["relative_path"] = urllib.parse.quote(relative_path)
aTemplate["name"] = indexJson["name"]
aTemplate["description"] = indexJson["description"]
aTemplate["version"] = indexJson["version"]
if (not relative_path.endswith(aTemplate["name"])):
raise Exception(f"Name of the template MUST match name of the folder." + relative_path + " != " + aTemplate["name"])
if path.isfile(root_path+"/thumbnail.png"):
aTemplate["thumbnail"] = relative_path+"/thumbnail.png"
templates.append(aTemplate)
templates = []
for root, dirs, files in os.walk("./"):
root_path = root.split(os.sep)
path_parts = root_path[1:]
for file in files:
if file == "index.json":
process_directory(root, path_parts, templates)
with open(readme_file_name, 'w') as readme_file:
create_header(readme_file)
create_template_overview(readme_file, templates)