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 = [
61 os.path.join(t, f)
62 for f in sorted(os.listdir(t))
63 if not f.startswith('.') and os.path.isdir(os.path.join(t, f))
64 ]
65 # Flat folders (e.g. sample eye plaque inputs) have files but no model subdirs
66 if not dirs:
67 dirs = [t]
68
69 for d in dirs:
70 _, subname = os.path.split(d)
71 subsection = (type_+subname).replace(" ", "").replace(".", "")
72
73 docs.append("\subsubsection %s %s" % (subsection, subname))
74
75 geom_links = get_filetype_links(d, ".geom")
76 shape_links = get_filetype_links(d, ".shape")
77 egsinp_links = get_filetype_links(d, ".egsinp")
78 docs.append("<dl>")
79 docs.append("<dt>Description</dt><dd>%s</dd>" % (get_readme(d) or "<em>No description available</em>"))
80 if geom_links:
81 docs.append("<dt>Geometry Files</dt><dd>%s</dt>" % ','.join(geom_links))
82 if shape_links:
83 docs.append("<dt>Shape Files</dt><dd>%s</dt>" % ', '.join(shape_links))
84 if egsinp_links:
85 docs.append("<dt>Example Inputs</dt><dd>%s</dd>" % ', '.join(egsinp_links))
86
87 images = get_images(d)
88 docs.append("<dt>Images</dt><dd>%s</dd>" % ('\n'.join(images) or "<em>No images available</em>"))
89
90 docs.append("</dl>")
91
92 return "\n".join(docs)
93
94
95def gen_docs(fname):
96 params = {}
97 params["sources"] = gen_geom_docs(os.path.join(geom, "sources"), "Sources")
98 params["eye_plaques"] = gen_geom_docs(os.path.join(geom, "eye_plaques"), "Eye Plaques")
99 params["transforms"] = find_file_descriptions(os.path.join(geom, "transformations"), "start transformation")
100 params["phantoms"] = find_file_descriptions(os.path.join(geom, "phantoms"), "start geometry")
101 params["applicators"] = find_file_descriptions(os.path.join(geom, "applicators"), "start geometry")
102
103 docs = """@anchor egs_brachy_geom_lib
104
105[TOC]
106
107The egs_brachy Geometry Library
108===============================
109
110\section egs_brachysources Source Library
111
112
113The current list of sources available in the egs_brachy geometry
114library.
115
116{sources}
117
118\section egs_brachyphantoms Phantom Library
119
120The current list of phantoms available in the egs_brachy geometry
121library.
122
123{phantoms}
124
125
126\section egs_brachyapplicators Applicator Library
127
128The current list of applicators available in the egs_brachy geometry
129library.
130
131{applicators}
132
133
134\section egs_brachyplaques Eye Plaques Library
135
136The current list of eye plaques available in the egs_brachy geometry
137library.
138
139{eye_plaques}
140
141\section egs_brachytransforms Transformation Sets
142
143The current list of predefined transformation sets available in the
144egs_brachy geometry library.
145
146{transforms}
147""".format(**params)
148
149
150 open(fname, "w").write(docs)
151
152if __name__ == "__main__":
153 outfile = "geom.md"
154 gen_docs(outfile)
155
156
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