build_html.py 16 KB

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