build_html.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. #!/usr/bin/env python
  2. # utilities for generating HTML indices
  3. # (c) The GRASS Development Team, Markus Neteler, Glynn Clements 2003, 2004, 2005, 2006, 2009
  4. import sys
  5. import os
  6. import string
  7. ## TODO: better fix this in include/Make/Html.make, see bug RT #5361
  8. # exclude following list of modules from help index:
  9. exclude_mods = [
  10. "i.find",
  11. "r.watershed.ram",
  12. "r.watershed.seg",
  13. "v.topo.check",
  14. "helptext.html"]
  15. # these modules don't use G_parser()
  16. desc_override = {
  17. "g.parser": "Provides automated parser, GUI, and help support for GRASS scipts.",
  18. "r.li.daemon": "Support module for r.li landscape index calculations."
  19. }
  20. ############################################################################
  21. header1_tmpl = string.Template(\
  22. r"""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  23. <html>
  24. <head>
  25. <title>${title}</title>
  26. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  27. <meta name="Author" content="GRASS Development Team">
  28. """)
  29. macosx_tmpl = string.Template(\
  30. r"""
  31. <meta name="AppleTitle" content="GRASS GIS ${grass_version} Help">
  32. <meta name="AppleIcon" content="GRASS-${grass_mmver}/grass_icon.png">
  33. <meta name="robots" content="anchors">
  34. """)
  35. header2_tmpl = string.Template(\
  36. r""" <link rel="stylesheet" href="grassdocs.css" type="text/css">
  37. </head>
  38. <body bgcolor="#FFFFFF">
  39. <!-- this file is generated by tools/build_html_index.sh -->
  40. <img src="grass_logo.png" alt="GRASS logo"><hr align=center size=6 noshade>
  41. <h2>GRASS GIS ${grass_version} Reference Manual</h2>
  42. <p><b>Geographic Resources Analysis Support System</b>, commonly
  43. referred to as <a href="http://grass.osgeo.org">GRASS</a>, is a <a
  44. href="http://en.wikipedia.org/wiki/Geographic_information_system">Geographic
  45. Information System</a> (GIS) used for geospatial data management and
  46. analysis, image processing, graphics/maps production, spatial
  47. modeling, and visualization. GRASS is currently used in academic and
  48. commercial settings around the world, as well as by many governmental
  49. agencies and environmental consulting companies.</p>
  50. <p>This reference manual details the use of modules distributed with
  51. Geographic Resources Analysis Support System (GRASS), an open source (GNU
  52. GPLed), image processing and geographic information system (GIS).</p>
  53. """)
  54. #"
  55. overview_tmpl = string.Template(\
  56. r"""<!-- the files grass7.html & helptext.html file live in lib/init/ -->
  57. <table align="center" border="0" cellspacing="8">
  58. <tbody>
  59. <tr>
  60. <td valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;Quick Introduction</h3>
  61. <ul>
  62. <li><a href="grass6.html">GRASS startup manual page</a></li>
  63. <li><a href="helptext.html">How to start with GRASS</a></li>
  64. </ul></td>
  65. <td valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;General</h3>
  66. <ul>
  67. <li><a href="general.html">General commands manual</a></li>
  68. </ul></td>
  69. </tr>
  70. <tr>
  71. <td valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;Raster/Image processing</h3>
  72. <ul>
  73. <li><a href="rasterintro.html">Intro 2D raster map processing</a></li>
  74. <li><a href="raster.html">Raster commands manual</a></li>
  75. <li><a href="raster3dintro.html">Intro 3D raster map (voxel) processing</a></li>
  76. <li><a href="raster3D.html">Raster3D commands manual</a></li>
  77. </ul></td>
  78. <td valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;Vector processing</h3>
  79. <ul>
  80. <li><a href="vectorintro.html">Intro vector map processing and network analysis</a></li>
  81. <li><a href="vector.html">Vector commands manual</a></li>
  82. </ul></td>
  83. </tr>
  84. <tr>
  85. <td valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;Display/Graphical User Interfaces</h3>
  86. <ul>
  87. <li><a href="wxGUI.html">wxGUI</a> wxPython-based GUI frontend</li>
  88. </ul>
  89. <ul>
  90. <li><a href="display.html">Display commands manual</a></li>
  91. <li><a href="displaydrivers.html">Display drivers</a></li>
  92. </ul>
  93. <ul>
  94. <li><a href="nviz.html">nviz</a> 3D visualization and animation tool</li>
  95. <li><a href="xganim.html">xganim</a> tool for animating a raster map series</li>
  96. </ul></td>
  97. <td valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;Database</h3>
  98. <ul>
  99. <li><a href="databaseintro.html">Intro database management</a></li>
  100. <li><a href="sql.html">SQL support in GRASS GIS</a></li>
  101. <li><a href="database.html">Database commands manual</a></li>
  102. </ul></td>
  103. </tr>
  104. <tr>
  105. <td valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;Projections</h3>
  106. <ul>
  107. <li><a href="projectionintro.html">Intro projections and spatial transformations</a></li>
  108. </ul></td>
  109. <td valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;Miscellaneous</h3>
  110. <ul>
  111. <li><a href="variables.html">GRASS variables and environment variables</a></li>
  112. <li><a href="gem/index.html">The GRASS Extensions Manager (GEM)</a></li>
  113. <li><a href="misc.html">Misc. commands manual</a></li>
  114. </ul></td>
  115. </tr>
  116. <tr>
  117. <td valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;Image processing</h3>
  118. <ul>
  119. <li><a href="imageryintro.html">Intro image processing</a></li>
  120. <li><a href="imagery.html">Imagery commands manual</a></li>
  121. </ul></td>
  122. <td valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;Printing</h3>
  123. <ul>
  124. <li><a href="postscript.html">Postscript commands manual</a></li>
  125. </ul></td>
  126. </tr>
  127. </tbody>
  128. </table>
  129. """)
  130. #"
  131. footer_tmpl = string.Template(\
  132. r"""<BR><BR>
  133. <hr>
  134. <p><a href="${index_url}">Help Index</a> | <a href="full_index.html">Full Index</a><br>
  135. &copy; 2003-2009 <a href="http://grass.osgeo.org">GRASS Development Team</a></p>
  136. </body>
  137. </html>
  138. """)
  139. #"
  140. cmd1_tmpl = string.Template(\
  141. r"""<b><a href="#${cmd}">${cmd}.*</a></b>""")
  142. #"
  143. cmd2_tmpl = string.Template(\
  144. r"""<a name="${cmd}"></a>
  145. <BR><BR><h3>${cmd}.* commands:</h3>
  146. <table>
  147. """)
  148. #"
  149. desc1_tmpl = string.Template(\
  150. r"""<tr><td valign="top"><a href="${cmd}">${basename}</a></td> <td>${desc}</td></tr>
  151. """)
  152. #"
  153. sections = \
  154. r""" ]
  155. <BR><BR>
  156. <table border=0>
  157. <tr><td>&nbsp;&nbsp;<a href="full_index.html#d">d.*</a> </td><td>display commands</td></tr>
  158. <tr><td>&nbsp;&nbsp;<a href="full_index.html#db">db.*</a> </td><td>database commands</td></tr>
  159. <tr><td>&nbsp;&nbsp;<a href="full_index.html#g">g.*</a> </td><td>general commands</td></tr>
  160. <tr><td>&nbsp;&nbsp;<a href="full_index.html#i">i.*</a> </td><td>imagery commands</td></tr>
  161. <tr><td>&nbsp;&nbsp;<a href="full_index.html#m">m.*</a> </td><td>miscellaneous commands</td></tr>
  162. <tr><td>&nbsp;&nbsp;<a href="full_index.html#ps">ps.*</a> </td><td>postscript commands</td></tr>
  163. <tr><td>&nbsp;&nbsp;<a href="full_index.html#r">r.*</a> </td><td>raster commands</td></tr>
  164. <tr><td>&nbsp;&nbsp;<a href="full_index.html#r3">r3.*</a> </td><td>raster3D commands</td></tr>
  165. <tr><td>&nbsp;&nbsp;<a href="full_index.html#v">v.*</a> </td><td>vector commands</td></tr>
  166. <tr><td>&nbsp;&nbsp;<a href="nviz.html">nviz</a> </td><td>visualization suite</td></tr>
  167. <tr><td>&nbsp;&nbsp;<a href="wxGUI.html">wxGUI</a> </td><td>wxPython-based GUI frontend</td></tr>
  168. <tr><td>&nbsp;&nbsp;<a href="xganim.html">xganim</a> </td><td>raster map slideshow</td></tr>
  169. </table>
  170. """
  171. #"
  172. modclass_tmpl = string.Template(\
  173. r"""Go <a href="index.html">back to help overview</a><BR><BR><BR>
  174. <b>${modclass} commands:</b>
  175. <table>
  176. """)
  177. #"
  178. desc2_tmpl = string.Template(\
  179. r"""<tr><td valign="top"><a href="${cmd}">${basename}</a></td> <td>${desc}</td></tr>
  180. """)
  181. #"
  182. full_index_header = \
  183. r"""Go <a href="index.html">back to help overview</a><BR>
  184. <BR><h3>Full command index:</h3>
  185. [
  186. """
  187. #"
  188. gem_ext_marker = r"""
  189. <!-- GEM Extensions StartHTML. Do not delete or change this comment! -->
  190. """
  191. #"
  192. message_tmpl = string.Template(\
  193. r"""Generated HTML docs in ${html_dir}/index.html
  194. ----------------------------------------------------------------------
  195. Following modules are missing the 'description.html' file in src code:
  196. """)
  197. #"
  198. ############################################################################
  199. def check_for_desc_override(basename):
  200. return desc_override.get(basename)
  201. def read_file(name):
  202. f = open(name, 'rb')
  203. s = f.read()
  204. f.close()
  205. return s
  206. def write_file(name, contents):
  207. f = open(name, 'wb')
  208. f.write(contents)
  209. f.close()
  210. def try_mkdir(path):
  211. try:
  212. os.mkdir(path)
  213. except OSError, e:
  214. pass
  215. def replace_file(name):
  216. temp = name + ".tmp"
  217. if os.path.exists(name) and os.path.exists(temp) and read_file(name) == read_file(temp):
  218. os.remove(temp)
  219. else:
  220. try:
  221. os.remove(name)
  222. except OSError, e:
  223. pass
  224. os.rename(temp, name)
  225. def copy_file(src, dst):
  226. write_file(dst, read_file(src))
  227. def html_files(cls = None):
  228. for cmd in sorted(os.listdir(html_dir)):
  229. if cmd.endswith(".html") and \
  230. (cls in [None, '*'] or cmd.startswith(cls + ".")) and \
  231. (cls != '*' or len(cmd.split('.')) >= 3) and \
  232. cmd not in ["full_index.html", "index.html"] and \
  233. cmd not in exclude_mods and \
  234. not cmd.startswith("wxGUI."):
  235. yield cmd
  236. def write_html_header(f, title, ismain = False):
  237. f.write(header1_tmpl.substitute(title = title))
  238. if ismain and macosx:
  239. f.write(macosx_tmpl.substitute(grass_version = grass_version,
  240. grass_mmver = grass_mmver))
  241. f.write(header2_tmpl.substitute(grass_version = grass_version))
  242. def write_html_cmd_overview(f):
  243. box_color = "#e1ecd0"
  244. f.write(overview_tmpl.substitute(box_color = box_color))
  245. def write_html_footer(f, index_url):
  246. f.write(footer_tmpl.substitute(index_url = index_url))
  247. def get_desc(cmd):
  248. f = open(cmd, 'r')
  249. while True:
  250. line = f.readline()
  251. if not line:
  252. return ""
  253. if "NAME" in line:
  254. break
  255. while True:
  256. line = f.readline()
  257. if not line:
  258. return ""
  259. if "SYNOPSIS" in line:
  260. break
  261. if "<em>" in line:
  262. sp = line.split('-',1)
  263. if len(sp) > 1:
  264. return sp[1].strip()
  265. else:
  266. return None
  267. return ""
  268. ############################################################################
  269. gem_dir = os.path.join("..", "gem")
  270. arch_dist_dir = os.environ['ARCH_DISTDIR']
  271. html_dir = os.path.join(arch_dist_dir, "docs", "html")
  272. gisbase = os.environ['GISBASE']
  273. ver = read_file(os.path.join(gisbase, "etc", "VERSIONNUMBER"))
  274. grass_version = ver.strip()
  275. grass_mmver = '.'.join(ver.split('.')[0:2])
  276. macosx = "darwin" in os.environ['ARCH'].lower()
  277. ############################################################################