build_rest.py 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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 <nviz>
  70. xganim tool for animating a raster map series <xganim>
  71. Raster and 3D raster processing
  72. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. .. toctree::
  74. :maxdepth: 1
  75. Raster commands manual <raster>
  76. 3D raster (voxel) commands manual <raster3D>
  77. Image processing
  78. ~~~~~~~~~~~~~~~~~~
  79. .. toctree::
  80. :maxdepth: 1
  81. Imagery commands manual <imagery>
  82. Vector processing
  83. ~~~~~~~~~~~~~~~~~~
  84. .. toctree::
  85. :maxdepth: 1
  86. Vector commands manual <vector>
  87. GRASS ASCII vector format specification <vectorascii>
  88. Database
  89. ~~~~~~~~~
  90. .. toctree::
  91. :maxdepth: 1
  92. SQL support in GRASS GIS <sql>
  93. Database commands manual <database>
  94. General
  95. ~~~~~~~~~
  96. .. toctree::
  97. :maxdepth: 1
  98. GRASS startup manual page <grass7>
  99. General commands manual <general>
  100. Miscellaneous & Variables
  101. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  102. .. toctree::
  103. :maxdepth: 1
  104. Miscellaneous commands manual <misc>
  105. GRASS variables and environment variables <variables>
  106. Temporal processing
  107. ~~~~~~~~~~~~~~~~~~~~
  108. .. toctree::
  109. :maxdepth: 1
  110. Temporal commands manual <temporal>
  111. Printing
  112. ~~~~~~~~~~~~
  113. .. toctree::
  114. :maxdepth: 1
  115. Postscript commands manual <postscript>
  116. """)
  117. #TODO add copyright symbol
  118. footer_tmpl = string.Template(\
  119. r"""
  120. --------------
  121. :doc:`Help Index <index>` \| :doc:`Full Index <full_index>`
  122. 2003-2012 `GRASS Development Team <http://grass.osgeo.org>`_, GRASS GIS ${grass_version} Reference Manual
  123. """)
  124. cmd1_tmpl = string.Template(\
  125. r"""*`$cmd.\* <${cmd}>` *""")
  126. cmd2_tmpl = string.Template(\
  127. r"""
  128. ${cmd}.* commands:
  129. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  130. .. toctree::
  131. :maxdepth: 1
  132. """)
  133. desc1_tmpl = string.Template(\
  134. r""" ${basename} - ${desc} <${basename}>
  135. """)
  136. sections = \
  137. r"""
  138. +-----------------------------+-------------------------------+
  139. |`d.* <full_index.html#d>`_ | `display commands` |
  140. +-----------------------------+-------------------------------+
  141. |`db.* <full_index.html#db>`_ | `database commands` |
  142. +-----------------------------+-------------------------------+
  143. |`g.* <full_index.html#g>`_ | `general commands` |
  144. +-----------------------------+-------------------------------+
  145. |`i.* <full_index.html#i>`_ | `imagery commands` |
  146. +-----------------------------+-------------------------------+
  147. |`m.* <full_index.html#m>`_ | `miscellaneous commands` |
  148. +-----------------------------+-------------------------------+
  149. |`ps.* <full_index.html#ps>`_ | `postscript commands` |
  150. +-----------------------------+-------------------------------+
  151. |`r.* <full_index.html#r>`_ | `raster commands` |
  152. +-----------------------------+-------------------------------+
  153. |`r3.* <full_index.html#r3>`_ | `raster3D commands` |
  154. +-----------------------------+-------------------------------+
  155. |`t.* <full_index.html#t>`_ | `temporal commands` |
  156. +-----------------------------+-------------------------------+
  157. |`v.* <full_index.html#v>`_ | `vector commands` |
  158. +-----------------------------+-------------------------------+
  159. |`nviz <nviz.html>`_ | `visualization suite` |
  160. +-----------------------------+-------------------------------+
  161. |`wxGUI <wxGUI.html>`_ | `wxPython-based GUI frontend` |
  162. +-----------------------------+-------------------------------+
  163. |`xganim <xganim.html>`_ | `raster map slideshow` |
  164. +-----------------------------+-------------------------------+
  165. """
  166. modclass_intro_tmpl = string.Template(\
  167. r"""Go to :doc:`${modclass} introduction <${modclass_lower}intro>`
  168. """)
  169. #"
  170. modclass_tmpl = string.Template(\
  171. r"""Go :doc:`back to help overview<index>`
  172. **${modclass} commands:**
  173. .. toctree::
  174. :maxdepth: 1
  175. """)
  176. #"
  177. desc2_tmpl = string.Template(\
  178. r""" ${basename} - ${desc} <${basename}>
  179. """)
  180. #"
  181. full_index_header = \
  182. r"""Go :doc:`back to help overview<index>`
  183. Full command index:
  184. ~~~~~~~~~~~~~~~~~~~~
  185. """
  186. #"
  187. message_tmpl = string.Template(\
  188. r"""Generated HTML docs in ${rest_dir}/index.txt
  189. ----------------------------------------------------------------------
  190. Following modules are missing the 'description.txt' file in src code:
  191. """)
  192. def check_for_desc_override(basename):
  193. return desc_override.get(basename)
  194. def read_file(name):
  195. f = open(name, 'rb')
  196. s = f.read()
  197. f.close()
  198. return s
  199. def write_file(name, contents):
  200. f = open(name, 'wb')
  201. f.write(contents)
  202. f.close()
  203. def try_mkdir(path):
  204. try:
  205. os.mkdir(path)
  206. except OSError, e:
  207. pass
  208. def replace_file(name):
  209. temp = name + ".tmp"
  210. if os.path.exists(name) and os.path.exists(temp) and read_file(name) == read_file(temp):
  211. os.remove(temp)
  212. else:
  213. try:
  214. os.remove(name)
  215. except OSError, e:
  216. pass
  217. os.rename(temp, name)
  218. def copy_file(src, dst):
  219. write_file(dst, read_file(src))
  220. def rest_files(cls = None):
  221. for cmd in sorted(os.listdir(rest_dir)):
  222. if cmd.endswith(".txt") and \
  223. (cls in [None, '*'] or cmd.startswith(cls + ".")) and \
  224. (cls != '*' or len(cmd.split('.')) >= 3) and \
  225. cmd not in ["full_index.txt", "index.txt"] and \
  226. cmd not in exclude_mods and \
  227. not cmd.startswith("wxGUI."):
  228. yield cmd
  229. def write_rest_header(f, title, ismain = False):
  230. f.write(header2_tmpl.substitute(grass_version = grass_version))
  231. def write_rest_cmd_overview(f):
  232. box_color = "#e1ecd0"
  233. f.write(overview_tmpl.substitute(box_color = box_color))
  234. def write_rest_footer(f, index_url):
  235. f.write(footer_tmpl.substitute(grass_version = grass_version,
  236. index_url = index_url))
  237. def get_desc(cmd):
  238. f = open(cmd, 'r')
  239. while True:
  240. line = f.readline()
  241. if not line:
  242. return ""
  243. if "NAME" in line:
  244. break
  245. while True:
  246. line = f.readline()
  247. if not line:
  248. return ""
  249. if "SYNOPSIS" in line:
  250. break
  251. if "*" in line:
  252. sp = line.split('-',1)
  253. if len(sp) > 1:
  254. return sp[1].strip()
  255. else:
  256. return None
  257. return ""
  258. ############################################################################
  259. arch_dist_dir = os.environ['ARCH_DISTDIR']
  260. rest_dir = os.path.join(arch_dist_dir, "docs", "rest")
  261. gisbase = os.environ['GISBASE']
  262. ver = read_file(os.path.join(gisbase, "etc", "VERSIONNUMBER"))
  263. try:
  264. grass_version = ver.split()[0].strip()
  265. except IndexError:
  266. grass_version = ver.split().strip()
  267. ############################################################################