build_rest.py 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. #!/usr/bin/env python
  2. """
  3. Created on Thu Aug 9 14:04:12 2012
  4. @author: lucadelu
  5. """
  6. # utilities for generating REST indices
  7. # utilities for generating HTML indices
  8. # (c) 2003-2006, 2009-2012 by the GRASS Development Team, Markus Neteler, Glynn Clements, Luca Delucchi
  9. import sys
  10. import os
  11. import string
  12. ## TODO: better fix this in include/Make/Rest.make, see bug RT #5361
  13. # exclude following list of modules from help index:
  14. exclude_mods = [
  15. "i.find",
  16. "r.watershed.ram",
  17. "r.watershed.seg",
  18. "v.topo.check",
  19. "helptext.html"]
  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. ############################################################################
  26. header2_tmpl = string.Template(\
  27. r"""
  28. ==================================================================
  29. GRASS GIS ${grass_version} Reference Manual
  30. ==================================================================
  31. .. figure:: grass_logo.png
  32. :align: center
  33. :alt: GRASS logo
  34. GRASS GIS ${grass_version} Reference Manual
  35. --------------------------------------------------------------------
  36. **Geographic Resources Analysis Support System**, commonly
  37. referred to as `GRASS <http://grass.osgeo.org>`_, is a `Geographic
  38. Information System <http://en.wikipedia.org/wiki/Geographic_information_system>`_
  39. (GIS) used for geospatial data management and analysis, image processing,
  40. graphics/maps production, spatial modeling, and visualization. GRASS is
  41. currently used in academic and commercial settings around the world, as
  42. well as by many governmental agencies and environmental consulting companies.
  43. This reference manual details the use of modules distributed with
  44. Geographic Resources Analysis Support System (GRASS), an open source
  45. (`GNU GPLed <http://www.gnu.org/licenses/gpl.html>`_), image
  46. processing and geographic information system (GIS).
  47. """)
  48. overview_tmpl = string.Template(\
  49. r"""
  50. Quick Introduction
  51. ~~~~~~~~~~~~~~~~~~~~
  52. .. toctree::
  53. :maxdepth: 1
  54. How to start with GRASS <helptext.html>
  55. Intro projections and spatial transformations <projectionintro>
  56. Intro 2D raster map processing <rasterintro>
  57. Intro 3D raster map (voxel) processing <raster3dintro>
  58. Intro image processing <imageryintro>
  59. Intro vector map processing and network analysis <vectorintro>
  60. Intro database management <databaseintro>
  61. Intro temporal data processing <temporalintro>
  62. Display/Graphical User Interfaces
  63. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  64. .. toctree::
  65. :maxdepth: 1
  66. wxGUI wxPython-based GUI frontend <wxGUI>
  67. Display commands manual <display>
  68. Display drivers <displaydrivers>
  69. nviz 3D visualization and animation tool <wxGUI.Nviz>
  70. Raster and 3D raster processing
  71. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  72. .. toctree::
  73. :maxdepth: 1
  74. Raster commands manual <raster>
  75. 3D raster (voxel) commands manual <raster3D>
  76. Image processing
  77. ~~~~~~~~~~~~~~~~~~
  78. .. toctree::
  79. :maxdepth: 1
  80. Imagery commands manual <imagery>
  81. Vector processing
  82. ~~~~~~~~~~~~~~~~~~
  83. .. toctree::
  84. :maxdepth: 1
  85. Vector commands manual <vector>
  86. GRASS ASCII vector format specification <vectorascii>
  87. Database
  88. ~~~~~~~~~
  89. .. toctree::
  90. :maxdepth: 1
  91. SQL support in GRASS GIS <sql>
  92. Database commands manual <database>
  93. General
  94. ~~~~~~~~~
  95. .. toctree::
  96. :maxdepth: 1
  97. GRASS startup manual page <grass7>
  98. General commands manual <general>
  99. Miscellaneous & Variables
  100. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  101. .. toctree::
  102. :maxdepth: 1
  103. Miscellaneous commands manual <misc>
  104. GRASS variables and environment variables <variables>
  105. Temporal processing
  106. ~~~~~~~~~~~~~~~~~~~~
  107. .. toctree::
  108. :maxdepth: 1
  109. Temporal commands manual <temporal>
  110. Printing
  111. ~~~~~~~~~~~~
  112. .. toctree::
  113. :maxdepth: 1
  114. Postscript commands manual <postscript>
  115. """)
  116. #TODO add copyright symbol
  117. footer_tmpl = string.Template(\
  118. r"""
  119. --------------
  120. :doc:`Manual main page <index>` \| :doc:`Full Index <full_index>`
  121. 2003-2017 `GRASS Development Team <http://grass.osgeo.org>`_, GRASS GIS ${grass_version} Reference Manual
  122. """)
  123. cmd1_tmpl = string.Template(\
  124. r"""*`$cmd.\* <${cmd}>` *""")
  125. cmd2_tmpl = string.Template(\
  126. r"""
  127. ${cmd}.* commands:
  128. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  129. .. toctree::
  130. :maxdepth: 1
  131. """)
  132. desc1_tmpl = string.Template(\
  133. r""" ${basename} - ${desc} <${basename}>
  134. """)
  135. sections = \
  136. r"""
  137. +-----------------------------+-------------------------------+
  138. |`d.* <full_index.html#d>`_ | `display commands` |
  139. +-----------------------------+-------------------------------+
  140. |`db.* <full_index.html#db>`_ | `database commands` |
  141. +-----------------------------+-------------------------------+
  142. |`g.* <full_index.html#g>`_ | `general commands` |
  143. +-----------------------------+-------------------------------+
  144. |`i.* <full_index.html#i>`_ | `imagery commands` |
  145. +-----------------------------+-------------------------------+
  146. |`m.* <full_index.html#m>`_ | `miscellaneous commands` |
  147. +-----------------------------+-------------------------------+
  148. |`ps.* <full_index.html#ps>`_ | `postscript commands` |
  149. +-----------------------------+-------------------------------+
  150. |`r.* <full_index.html#r>`_ | `raster commands` |
  151. +-----------------------------+-------------------------------+
  152. |`r3.* <full_index.html#r3>`_ | `raster3D commands` |
  153. +-----------------------------+-------------------------------+
  154. |`t.* <full_index.html#t>`_ | `temporal commands` |
  155. +-----------------------------+-------------------------------+
  156. |`v.* <full_index.html#v>`_ | `vector commands` |
  157. +-----------------------------+-------------------------------+
  158. |`nviz <wxGUI.Nviz.html>`_ | `visualization suite` |
  159. +-----------------------------+-------------------------------+
  160. |`wxGUI <wxGUI.html>`_ | `wxPython-based GUI frontend` |
  161. +-----------------------------+-------------------------------+
  162. """
  163. modclass_intro_tmpl = string.Template(\
  164. r"""Go to :doc:`${modclass} introduction <${modclass_lower}intro>`
  165. """)
  166. #"
  167. modclass_tmpl = string.Template(\
  168. r"""Go :doc:`back to help overview<index>`
  169. **${modclass} commands:**
  170. .. toctree::
  171. :maxdepth: 1
  172. """)
  173. #"
  174. desc2_tmpl = string.Template(\
  175. r""" ${basename} - ${desc} <${basename}>
  176. """)
  177. #"
  178. full_index_header = \
  179. r"""Go :doc:`back to help overview<index>`
  180. Full command index:
  181. ~~~~~~~~~~~~~~~~~~~~
  182. """
  183. #"
  184. message_tmpl = string.Template(\
  185. r"""Generated HTML docs in ${rest_dir}/index.txt
  186. ----------------------------------------------------------------------
  187. Following modules are missing the 'modulename.txt' file in src code:
  188. """)
  189. def check_for_desc_override(basename):
  190. return desc_override.get(basename)
  191. def read_file(name):
  192. f = open(name, 'rb')
  193. s = f.read()
  194. f.close()
  195. return s
  196. def write_file(name, contents):
  197. f = open(name, 'wb')
  198. f.write(contents)
  199. f.close()
  200. def try_mkdir(path):
  201. try:
  202. os.mkdir(path)
  203. except OSError as e:
  204. pass
  205. def replace_file(name):
  206. temp = name + ".tmp"
  207. if os.path.exists(name) and os.path.exists(temp) and read_file(name) == read_file(temp):
  208. os.remove(temp)
  209. else:
  210. try:
  211. os.remove(name)
  212. except OSError as e:
  213. pass
  214. os.rename(temp, name)
  215. def copy_file(src, dst):
  216. write_file(dst, read_file(src))
  217. def rest_files(cls = None):
  218. for cmd in sorted(os.listdir(rest_dir)):
  219. if cmd.endswith(".txt") and \
  220. (cls in [None, '*'] or cmd.startswith(cls + ".")) and \
  221. (cls != '*' or len(cmd.split('.')) >= 3) and \
  222. cmd not in ["full_index.txt", "index.txt"] and \
  223. cmd not in exclude_mods and \
  224. not cmd.startswith("wxGUI."):
  225. yield cmd
  226. def write_rest_header(f, title, ismain = False):
  227. f.write(header2_tmpl.substitute(grass_version = grass_version))
  228. def write_rest_cmd_overview(f):
  229. box_color = "#e1ecd0"
  230. f.write(overview_tmpl.substitute(box_color = box_color))
  231. def write_rest_footer(f, index_url):
  232. f.write(footer_tmpl.substitute(grass_version = grass_version,
  233. index_url = index_url))
  234. def get_desc(cmd):
  235. f = open(cmd, 'r')
  236. while True:
  237. line = f.readline()
  238. if not line:
  239. return ""
  240. if "NAME" in line:
  241. break
  242. while True:
  243. line = f.readline()
  244. if not line:
  245. return ""
  246. if "SYNOPSIS" in line:
  247. break
  248. if "*" in line:
  249. sp = line.split('-',1)
  250. if len(sp) > 1:
  251. return sp[1].strip()
  252. else:
  253. return None
  254. return ""
  255. ############################################################################
  256. arch_dist_dir = os.environ['ARCH_DISTDIR']
  257. rest_dir = os.path.join(arch_dist_dir, "docs", "rest")
  258. gisbase = os.environ['GISBASE']
  259. ver = read_file(os.path.join(gisbase, "etc", "VERSIONNUMBER"))
  260. try:
  261. grass_version = ver.split()[0].strip()
  262. except IndexError:
  263. grass_version = ver.split().strip()
  264. ############################################################################