build_html.py 17 KB

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