build_html.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # utilities for generating HTML indices
  4. # (c) 2003-2006, 2009-2013 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 style="width: ${body_width}">
  41. <!-- this file is generated by man/build_html.py -->
  42. <a href="index.html"><img src="grass_logo.png" alt="GRASS logo"></a>
  43. <hr class="header">
  44. <h2>GRASS GIS ${grass_version} Reference Manual</h2>
  45. <p><b>Geographic Resources Analysis Support System</b>, commonly
  46. referred to as <a href="http://grass.osgeo.org">GRASS</a>, is a <a
  47. href="http://en.wikipedia.org/wiki/Geographic_information_system">Geographic
  48. Information System</a> (GIS) used for geospatial data management and
  49. analysis, image processing, graphics/maps production, spatial
  50. modeling, and visualization. GRASS is currently used in academic and
  51. commercial settings around the world, as well as by many governmental
  52. agencies and environmental consulting companies.</p>
  53. <p>This reference manual details the use of modules distributed with
  54. Geographic Resources Analysis Support System (GRASS), an open source
  55. (<a href="http://www.gnu.org/licenses/gpl.html">GNU GPLed</a>), image
  56. processing and geographic information system (GIS).</p>
  57. """)
  58. #"
  59. overview_tmpl = string.Template(\
  60. r"""<!-- the files grass7.html & helptext.html file live in lib/init/ -->
  61. <table align="center" border="0" cellspacing="8">
  62. <tbody>
  63. <tr>
  64. <td width="33%" valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;Quick Introduction</h3>
  65. <ul>
  66. <li class="box"><a href="helptext.html">How to start with GRASS</a></li>
  67. <li class="box"><span>Index of <a href="topics.html">topics</a> and <a href="keywords.html">keywords</a></span></li>
  68. </ul>
  69. <p>
  70. <ul>
  71. <li class="box"><a href="projectionintro.html">Intro: projections and spatial transformations</a></li>
  72. </ul>
  73. <p>
  74. <ul>
  75. <li class="box"><span><a href="http://grasswiki.osgeo.org/wiki/Faq">FAQ - Frequently Asked Questions</a> (Wiki)</span></li>
  76. </ul>
  77. </td>
  78. <td width="33%" valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;Display/Graphical User Interfaces</h3>
  79. <ul>
  80. <li class="box"><span><a href="wxGUI.html">wxGUI</a> Graphical User Interface</span></li>
  81. <li class="box"><a href="wxGUI.components.html">wxGUI components</a></li>
  82. <li class="box"><a href="wxGUI.toolboxes.html">wxGUI toolboxes</a></li>
  83. </ul>
  84. <ul>
  85. <li class="box"><a href="topic_gui.html">GUI commands</a></li>
  86. </ul>
  87. <ul>
  88. <li class="box"><a href="display.html">Display commands manual</a></li>
  89. <li class="box"><a href="displaydrivers.html">Display drivers</a></li>
  90. </ul>
  91. </td>
  92. <td width="33%" valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;General</h3>
  93. <ul>
  94. <li class="box"><a href="grass7.html">GRASS GIS startup manual page</a></li>
  95. <li class="box"><a href="general.html">General commands manual</a></li>
  96. </ul>
  97. </td>
  98. </tr>
  99. <tr>
  100. <td width="33%" valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;Raster processing</h3>
  101. <ul>
  102. <li class="box"><a href="rasterintro.html">Intro: 2D raster map processing</a></li>
  103. <li class="box"><a href="raster.html">Raster commands manual</a></li>
  104. </ul>
  105. </td>
  106. <td width="33%" valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;3D raster processing</h3>
  107. <ul>
  108. <li class="box"><a href="raster3dintro.html">Intro: 3D raster map (voxel) processing</a></li>
  109. <li class="box"><a href="raster3D.html">3D raster (voxel) commands manual</a></li>
  110. </ul></td>
  111. <td width="33%" valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;Image processing</h3>
  112. <ul>
  113. <li class="box"><a href="imageryintro.html">Intro: image processing</a></li>
  114. <li class="box"><a href="imagery.html">Imagery commands manual</a></li>
  115. </ul></td>
  116. </tr>
  117. <tr>
  118. <td width="33%" valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;Vector processing</h3>
  119. <ul>
  120. <li class="box"><a href="vectorintro.html">Intro: vector map processing and network analysis</a></li>
  121. <li class="box"><a href="vector.html">Vector commands manual</a></li>
  122. <li class="box"><a href="vectorascii.html">GRASS ASCII vector format specification</a></li>
  123. </ul></td>
  124. <td width="33%" valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;Database</h3>
  125. <ul>
  126. <li class="box"><a href="databaseintro.html">Intro: database management</a></li>
  127. <li class="box"><a href="sql.html">SQL support in GRASS GIS</a></li>
  128. <li class="box"><a href="database.html">Database commands manual</a></li>
  129. </ul>
  130. </td>
  131. <td width="33%" valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;Temporal processing</h3>
  132. <ul>
  133. <li class="box"><a href="temporalintro.html">Intro: temporal data processing</a></li>
  134. <li class="box"><a href="temporal.html">Temporal commands manual</a></li>
  135. </ul>
  136. </td>
  137. </tr>
  138. <tr>
  139. <td width="33%" valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;Cartography</h3>
  140. <ul>
  141. <li class="box"><a href="postscript.html">Postscript commands manual</a></li>
  142. <li class="box"><a href="g.gui.psmap.html">wxGUI Cartographic Composer</a></li>
  143. </ul>
  144. </td>
  145. <td width="33%" valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;Miscellaneous&nbsp;&amp;&nbsp;Variables</h3>
  146. <ul>
  147. <li class="box"><a href="misc.html">Miscellaneous commands manual</a></li>
  148. <li class="box"><a href="variables.html">GRASS variables and environment variables</a></li>
  149. </ul>
  150. </td>
  151. <td width="33%" valign="top" bgcolor="${box_color}" class="box"><h3>&nbsp;Python</h3>
  152. <ul>
  153. <li class="box"><a href="libpython/index.html">PyGRASS documentation</a></li>
  154. <li class="box"><a href="libpython/index.html">GRASS GIS Testsuite</a></li>
  155. </ul>
  156. </td>
  157. </tr>
  158. </tbody>
  159. </table>
  160. """)
  161. #"
  162. footer_tmpl = string.Template(\
  163. r"""<hr class="header">
  164. <p><a href="${index_url}">Help Index</a> | <a href="topics.html">Topics Index</a> | <a href="keywords.html">Keywords Index</a> | <a href="full_index.html">Full Index</a></p>
  165. <p>&copy; 2003-${year} <a href="http://grass.osgeo.org">GRASS Development Team</a>, GRASS GIS ${grass_version} Reference Manual</p>
  166. </body>
  167. </html>
  168. """)
  169. #"
  170. cmd2_tmpl = string.Template(\
  171. r"""<a name="${cmd}"></a>
  172. <h3>${cmd_label} commands (${cmd}.*)</h3>
  173. <table>
  174. """)
  175. #"
  176. desc1_tmpl = string.Template(\
  177. r"""<tr><td valign="top"><a href="${cmd}">${basename}</a></td> <td>${desc}</td></tr>
  178. """)
  179. #"
  180. toc = \
  181. r"""
  182. <div class="toc">
  183. <ul class="toc">
  184. <li class="toc"><a class="toc" href="full_index.html#d">Display commands (d.*)</a></li>
  185. <li class="toc"><a class="toc" href="full_index.html#db">Database commands (db.*)</a></li>
  186. <li class="toc"><a class="toc" href="full_index.html#g">General commands (g.*)</a></li>
  187. <li class="toc"><a class="toc" href="full_index.html#i">Imagery commands (i.*)</a></li>
  188. <li class="toc"><a class="toc" href="full_index.html#m">Miscellaneous commands (m.*)</a></li>
  189. <li class="toc"><a class="toc" href="full_index.html#ps">PostScript commands (ps.*)</a></li>
  190. <li class="toc"><a class="toc" href="full_index.html#r">Raster commands (r.*)</a></li>
  191. <li class="toc"><a class="toc" href="full_index.html#r3">3d raster commands (r3.*)</a></li>
  192. <li class="toc"><a class="toc" href="full_index.html#t">Temporal commands (t.*)</a></li>
  193. <li class="toc"><a class="toc" href="full_index.html#v">Vector commands (v.*)</a></li>
  194. <li class="toc"><a class="toc" href="wxGUI.html">wxGUI Graphical User Interface</a></li>
  195. <li class="toc"><a class="toc" href="wxGUI.nviz.html">3D visualization suite</a></li>
  196. </ul>
  197. </div>
  198. """
  199. #"
  200. modclass_intro_tmpl = string.Template(\
  201. r"""Go to <a href="${modclass_lower}intro.html">${modclass} introduction</a> | <a href="topics.html">topics</a> <p>
  202. """)
  203. #"
  204. modclass_tmpl = string.Template(\
  205. r"""Go <a href="index.html">back to help overview</a>
  206. <h3>${modclass} commands:</h3>
  207. <table>
  208. """)
  209. #"
  210. desc2_tmpl = string.Template(\
  211. r"""<tr><td valign="top"><a href="${cmd}">${basename}</a></td> <td>${desc}</td></tr>
  212. """)
  213. #"
  214. full_index_header = \
  215. r"""
  216. Go <a href="index.html">back to help overview</a>
  217. """
  218. #"
  219. message_tmpl = string.Template(\
  220. r"""Generated HTML docs in ${html_dir}/index.html
  221. ----------------------------------------------------------------------
  222. Following modules are missing the 'modulename.html' file in src code:
  223. """)
  224. #"
  225. moduletopics_tmpl = string.Template(\
  226. r"""
  227. <li> <a href="topic_${key}.html">${name}</a></li>
  228. """
  229. )
  230. #"
  231. headertopics_tmpl = \
  232. r"""
  233. <link rel="stylesheet" href="grassdocs.css" type="text/css">
  234. </head>
  235. <body style="width: 99%">
  236. <a href="index.html"><img src="grass_logo.png" alt="GRASS logo"></a>
  237. <hr class="header">
  238. <h2>Topics</h2>
  239. <ul>
  240. """
  241. #"
  242. headerkeywords_tmpl = \
  243. r"""
  244. <link rel="stylesheet" href="grassdocs.css" type="text/css">
  245. </head>
  246. <body style="width: 99%">
  247. <a href="index.html"><img src="grass_logo.png" alt="GRASS logo"></a>
  248. <hr class="header">
  249. <h2>Keywords - Index of GRASS GIS modules</h2>
  250. """
  251. #"
  252. headerkey_tmpl = string.Template(\
  253. r"""
  254. <link rel="stylesheet" href="grassdocs.css" type="text/css">
  255. </head>
  256. <body bgcolor="white">
  257. <a href="index.html"><img src="grass_logo.png" alt="GRASS logo"></a>
  258. <hr class="header">
  259. <h2>Topic: ${keyword}</h2>
  260. <table>
  261. """)
  262. #"
  263. ############################################################################
  264. def check_for_desc_override(basename):
  265. return desc_override.get(basename)
  266. def read_file(name):
  267. f = open(name, 'rb')
  268. s = f.read()
  269. f.close()
  270. return s
  271. def write_file(name, contents):
  272. f = open(name, 'wb')
  273. f.write(contents)
  274. f.close()
  275. def try_mkdir(path):
  276. try:
  277. os.mkdir(path)
  278. except OSError as e:
  279. pass
  280. def replace_file(name):
  281. temp = name + ".tmp"
  282. if os.path.exists(name) and os.path.exists(temp) and read_file(name) == read_file(temp):
  283. os.remove(temp)
  284. else:
  285. try:
  286. os.remove(name)
  287. except OSError as e:
  288. pass
  289. os.rename(temp, name)
  290. def copy_file(src, dst):
  291. write_file(dst, read_file(src))
  292. def html_files(cls = None):
  293. for cmd in sorted(os.listdir(html_dir)):
  294. if cmd.endswith(".html") and \
  295. (cls in [None, '*'] or cmd.startswith(cls + ".")) and \
  296. (cls != '*' or len(cmd.split('.')) >= 3) and \
  297. cmd not in ["full_index.html", "index.html"] and \
  298. cmd not in exclude_mods and \
  299. not cmd.startswith("wxGUI."):
  300. yield cmd
  301. def write_html_header(f, title, ismain = False, body_width = "99%"):
  302. f.write(header1_tmpl.substitute(title = title))
  303. if ismain and macosx:
  304. f.write(macosx_tmpl.substitute(grass_version = grass_version,
  305. grass_mmver = grass_mmver))
  306. f.write(header2_tmpl.substitute(grass_version = grass_version, body_width = body_width))
  307. def write_html_cmd_overview(f):
  308. box_color = "#e1ecd0"
  309. f.write(overview_tmpl.substitute(box_color = box_color))
  310. def write_html_footer(f, index_url, year = None):
  311. if year is None:
  312. cur_year = default_year
  313. else:
  314. cur_year = year
  315. f.write(footer_tmpl.substitute(grass_version = grass_version,
  316. index_url = index_url, year = cur_year))
  317. def get_desc(cmd):
  318. f = open(cmd, 'r')
  319. while True:
  320. line = f.readline()
  321. if not line:
  322. return ""
  323. if "NAME" in line:
  324. break
  325. while True:
  326. line = f.readline()
  327. if not line:
  328. return ""
  329. if "SYNOPSIS" in line:
  330. break
  331. if "<em>" in line:
  332. sp = line.split('-',1)
  333. if len(sp) > 1:
  334. return sp[1].strip()
  335. else:
  336. return None
  337. return ""
  338. ############################################################################
  339. arch_dist_dir = os.environ['ARCH_DISTDIR']
  340. html_dir = os.path.join(arch_dist_dir, "docs", "html")
  341. gisbase = os.environ['GISBASE']
  342. grass_version = os.getenv("VERSION_NUMBER", "unknown")
  343. grass_mmver = '.'.join(grass_version.split('.')[0:2])
  344. macosx = "darwin" in os.environ['ARCH'].lower()
  345. default_year = os.getenv("VERSION_DATE")
  346. if not default_year:
  347. default_year = str(datetime.now().year)
  348. ############################################################################