EGS Brachy
An egs++ user code for rapid brachytherapy calculations
Loading...
Searching...
No Matches
gen_geom.py
Go to the documentation of this file.
1import os
2
3from doc_utils import find_file_descriptions
4
5
6root = os.path.join("..", "lib")
7abs_root = os.path.abspath(root)
8geom = os.path.join(abs_root, "geometry")
9
10
11def docs_lib_path(path):
12 """Path from the published docs/ root to a file under lib/."""
13 rel = os.path.relpath(os.path.abspath(path), abs_root)
14 return "lib/" + rel.replace("\\", "/")
15
16
17def get_readme(dir_path):
18
19 """Look in directory dir_path for a file called README.md and return
20 it's contents if available"""
21
22 try:
23 readme = open(os.path.join(dir_path, "README.md")).read()
24 return "\n%s\n" % readme
25 except IOError:
26 return ""
27
28
29def get_filetype_links(dir_path, extension):
30 files = [g for g in os.listdir(dir_path) if g.endswith(extension)]
31 links = [
32 "[%s](%s)" % (g, docs_lib_path(os.path.join(dir_path, g)))
33 for g in files
34 ]
35 return links
36
37
38def get_images(dir_path):
39 files = [g for g in os.listdir(dir_path) if g.lower().endswith(".png")]
40 images = [
41 '<img style="width: 200px;" src="%s" />' % docs_lib_path(os.path.join(dir_path, g))
42 for g in files
43 ]
44 return images
45
46
47def gen_geom_docs(droot, title, is_sources=False):
48
49 types = [os.path.join(droot, t) for t in os.listdir(droot) if os.path.isdir(os.path.join(droot, t))]
50
51 docs = []
52
53 for t in sorted(types):
54 _, type_ = os.path.split(t)
55 section = type_.replace(" ", "")
56
57 name = type_.replace("_", " ")
58 docs.append("\subsection %s %s %s" % (section, name, title))
59
60 dirs = [os.path.join(t, f) for f in sorted(os.listdir(t)) if not f.startswith('.')]
61
62 for d in dirs:
63 relpath = os.path.relpath(d)
64 _, subname = os.path.split(d)
65 subsection = (type_+subname).replace(" ", "").replace(".", "")
66
67 docs.append("\subsubsection %s %s" % (subsection, subname))
68
69
70 geom_links = get_filetype_links(d, ".geom")
71 shape_links = get_filetype_links(d, ".shape")
72 docs.append("<dl>")
73 docs.append("<dt>Description</dt><dd>%s</dd>" % (get_readme(d) or "<em>No description available</em>"))
74 if geom_links:
75 docs.append("<dt>Geometry Files</dt><dd>%s</dt>" % ','.join(geom_links))
76 if shape_links:
77 docs.append("<dt>Shape Files</dt><dd>%s</dt>" % ', '.join(shape_links))
78
79 images = get_images(d)
80 docs.append("<dt>Images</dt><dd>%s</dd>" % ('\n'.join(images) or "<em>No images available</em>"))
81
82 docs.append("</dl>")
83
84 return "\n".join(docs)
85
86
87def gen_docs(fname):
88 params = {}
89 params["sources"] = gen_geom_docs(os.path.join(geom, "sources"), "Sources")
90 params["eye_plaques"] = find_file_descriptions(os.path.join(geom, "eye_plaques"), "start geometry")
91 params["transforms"] = find_file_descriptions(os.path.join(geom, "transformations"), "start transformation")
92 params["phantoms"] = find_file_descriptions(os.path.join(geom, "phantoms"), "start geometry")
93 params["applicators"] = find_file_descriptions(os.path.join(geom, "applicators"), "start geometry")
94
95 docs = """@anchor egs_brachy_geom_lib
96
97[TOC]
98
99The egs_brachy Geometry Library
100===============================
101
102\section egs_brachysources Source Library
103
104
105The current list of sources available in the egs_brachy geometry
106library.
107
108{sources}
109
110\section egs_brachyphantoms Phantom Library
111
112The current list of phantoms available in the egs_brachy geometry
113library.
114
115{phantoms}
116
117
118\section egs_brachyapplicators Applicator Library
119
120The current list of applicators available in the egs_brachy geometry
121library.
122
123{applicators}
124
125
126\section egs_brachyplaques Eye Plaques Library
127
128The current list of eye plaques available in the egs_brachy geometry
129library.
130
131{eye_plaques}
132
133\section egs_brachytransforms Transformation Sets
134
135The current list of predefined transformation sets available in the
136egs_brachy geometry library.
137
138{transforms}
139""".format(**params)
140
141
142 open(fname, "w").write(docs)
143
144if __name__ == "__main__":
145 outfile = "geom.md"
146 gen_docs(outfile)
147
148
string join(const vector< string > &v, string delim)
Definition ginfo.cpp:56
docs_lib_path(path)
Definition gen_geom.py:11
gen_geom_docs(droot, title, is_sources=False)
Definition gen_geom.py:47
get_readme(dir_path)
Definition gen_geom.py:17
get_images(dir_path)
Definition gen_geom.py:38
get_filetype_links(dir_path, extension)
Definition gen_geom.py:29