forked from ivansipiran/grafica
-
Notifications
You must be signed in to change notification settings - Fork 5
/
generate_readme.py
154 lines (125 loc) · 4.84 KB
/
generate_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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# coding=utf-8
"""Generate a nice and pretty Readme.md file for the repository"""
import os
import os.path
import ast
__author__ = "Daniel Calderon"
__license__ = "MIT"
def getDocString(filepath):
with open(filepath) as f:
return ast.get_docstring(ast.parse(f.read()))
return None
if __name__ == "__main__":
examplesPath = "examples"
headerText = """
# Computer Graphics with OpenGL and Python
This set of examples illustrate different computer graphics concepts in 2D and 3D while using: Python, OpenGL core profile, GLFW and Numpy.
"""
ExampleFamilyTemplateText = """
## $EXAMPLE_FAMILY_FILENAME$
"""
ExampleTemplateText = """
### $EXAMPLE_FILENAME$
$DESCRIPTION$
"""
ExampleImageTemplateText = """
[![$EXAMPLE_FILENAME$](./screenshots/$SCREENSHOT_FILENAME$)](./examples/$EXAMPLE_FILENAME$)
"""
dirPath = os.path.dirname(os.path.realpath(__file__))
screenshotsDir = os.path.join(dirPath, "screenshots")
readmeFilename = os.path.join(dirPath, "Readme.md")
#print("this path: ", dir_path)
class ExampleFamily:
def __init__(self, category, examples):
self.category = category
self.examples = examples
exampleList = [
ExampleFamily("Raster",[
"ex_color_palette.py",
"ex_color_palette_anim.py",
"ex_sira_direct.py",
"ex_sira_indirect.py"]),
ExampleFamily("OpenGL Basics",[
"opengl_version.py",
"ex_triangle.py",
"ex_quad.py",
"ex_cube.py",
"ex_stream_draw.py"]),
ExampleFamily("Transformations",[
"ex_transform_polygon.py",
"ex_cpu_transforms.py",
"ex_4shapes.py",
"ex_transformations_showcase.py",
"ex_quad_controlled.py",
"ex_transform_imgui.py",
"ex_mouse.py"]),
ExampleFamily("Textures",[
"ex_texture_boo.py",
"ex_texture_quad.py",
"ex_mipmap.py",
"ex_binding_textures.py",
"ex_text_renderer.py"]),
ExampleFamily("Scene Graphs",[
"ex_scene_graph_2dcars.py",
"ex_scene_graph_snowman.py"]),
ExampleFamily("Curves",[
"ex_curves.py"]),
ExampleFamily("3D World",[
"ex_projections.py",
"ex_texture_dice.py",
"ex_height_plotter.py",
"ex_scene_graph_3dcars.py",
"ex_mix2d3d.py",
"ex_surface.py",
]),
ExampleFamily("Shading and Lighting",[
"ex_lighting.py",
"ex_lighting_texture2.py",
"ex_obj_reader.py",
]),
ExampleFamily("Meshes",[
"ex_delaunay.py",
"ex_triangle_mesh.py",
"ex_triangle_mesh_builder.py",
"ex_openmesh_pyramid.py"
]),
ExampleFamily("Physics and Collisions",[
"ex_collisions.py",
]),
ExampleFamily("Advanced OpenGL",[
"ex_geometry_shader.py",
"ex_render_to_texture.py"
])
#ExampleFamily("Volumetric Rendering",[
# "ex4_mayavi.py"
#])
]
with open(readmeFilename,'w') as f:
f.write(headerText)
for exampleFamily in exampleList:
print("Processing Category: ", exampleFamily.category)
f.write(ExampleFamilyTemplateText.replace("$EXAMPLE_FAMILY_FILENAME$", exampleFamily.category))
for filename in exampleFamily.examples:
print(" Procesing example: ", filename)#, filename.__doc__)
filepath = os.path.join(examplesPath, filename)
description = ""
if os.path.isfile(filepath):
description = getDocString(filepath)
f.write(ExampleTemplateText\
.replace("$EXAMPLE_FILENAME$", filename)\
.replace("$DESCRIPTION$", description))
pngScreenshotCandidate = os.path.join(screenshotsDir, filename[:-3] + ".png")
hasPngScreenshot = os.path.isfile(pngScreenshotCandidate)
gifScreenshotCandidate = os.path.join(screenshotsDir, filename[:-3] + ".gif")
hasGifScreenshot = os.path.isfile(gifScreenshotCandidate)
if hasPngScreenshot:
f.write(ExampleImageTemplateText\
.replace("$EXAMPLE_FILENAME$", filename)\
.replace("$SCREENSHOT_FILENAME$", filename[:-3] + ".png"))
elif hasGifScreenshot:
f.write(ExampleImageTemplateText\
.replace("$EXAMPLE_FILENAME$", filename)\
.replace("$SCREENSHOT_FILENAME$", filename[:-3] + ".gif"))
#print(filename)
#print(hasPngScreenshot, hasGifScreenshot)
#print()