build_html.py 12 KB

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