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