build_html.py 11 KB

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