瀏覽代碼

add script to create topics in html documentation

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@52931 15284696-431f-4ddb-bdfa-cd5b030d7da7
Luca Delucchi 12 年之前
父節點
當前提交
acd1acaeb8
共有 3 個文件被更改,包括 96 次插入2 次删除
  1. 1 0
      man/Makefile
  2. 34 2
      man/build_html.py
  3. 61 0
      man/build_topics.py

+ 1 - 0
man/Makefile

@@ -50,6 +50,7 @@ default: $(DSTFILES)
 	$(MAKE) $(INDICES)
 	$(MAKE) $(INDICES)
 	$(call build,check)
 	$(call build,check)
 	$(MAKE) manpages
 	$(MAKE) manpages
+	GISBASE="$(RUN_GISBASE)" ARCH="$(ARCH)" ARCH_DISTDIR="$(ARCH_DISTDIR)" $(PYTHON) ./build_topics.py $(HTMLDIR)
 	$(MAKE) restdocs
 	$(MAKE) restdocs
 
 
 restdocs: $(DSTFILES_REST)
 restdocs: $(DSTFILES_REST)

+ 34 - 2
man/build_html.py

@@ -2,7 +2,7 @@
 # -*- coding: utf-8 -*-
 # -*- coding: utf-8 -*-
 
 
 # utilities for generating HTML indices
 # utilities for generating HTML indices
-# (c) 2003-2006, 2009-2012 by the GRASS Development Team, Markus Neteler, Glynn Clements
+# (c) 2003-2006, 2009-2012 by the GRASS Development Team, Markus Neteler, Glynn Clements, Luca Delucchi
 
 
 import sys
 import sys
 import os
 import os
@@ -160,7 +160,7 @@ r"""<!-- the files grass7.html & helptext.html file live in lib/init/ -->
 footer_tmpl = string.Template(\
 footer_tmpl = string.Template(\
 r"""<BR><BR>
 r"""<BR><BR>
 <hr>
 <hr>
-<p><a href="${index_url}">Help Index</a> | <a href="full_index.html">Full Index</a><br>
+<p><a href="${index_url}">Help Index</a> | <a href="topics.html">Topics Index</a> | <a href="full_index.html">Full Index</a><br>
 &copy; 2003-2012 <a href="http://grass.osgeo.org">GRASS Development Team</a>, GRASS GIS ${grass_version} Reference Manual</p>
 &copy; 2003-2012 <a href="http://grass.osgeo.org">GRASS Development Team</a>, GRASS GIS ${grass_version} Reference Manual</p>
 </body>
 </body>
 </html>
 </html>
@@ -239,6 +239,38 @@ Following modules are missing the 'description.html' file in src code:
 """)
 """)
 #"
 #"
 
 
+moduletopics_tmpl = string.Template(\
+r"""
+<li> <a href="topic_${key}.html">${name}</a></li>
+"""
+)
+#"
+
+headertopics_tmpl = \
+r"""
+<link rel="stylesheet" href="grassdocs.css" type="text/css">
+</head>
+<body bgcolor="white">
+
+<img src="grass_logo.png" alt="GRASS logo"><hr align=center size=6 noshade> 
+<h2>Topics</h2>
+<ul>
+"""
+#"
+
+headerkey_tmpl = string.Template(\
+r"""
+<link rel="stylesheet" href="grassdocs.css" type="text/css">
+</head>
+<body bgcolor="white">
+
+<img src="grass_logo.png" alt="GRASS logo"><hr align=center size=6 noshade> 
+
+<h2>Topic: ${keyword}</h2>
+<table>
+""")
+#"
+
 ############################################################################
 ############################################################################
 
 
 def check_for_desc_override(basename):
 def check_for_desc_override(basename):

+ 61 - 0
man/build_topics.py

@@ -0,0 +1,61 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# generates topics.html and topic_*.html
+# (c) 2012 by the GRASS Development Team, Markus Neteler, Luca Delucchi
+
+import os
+import sys
+import glob
+import string
+from build_html import *
+
+
+path = sys.argv[1]
+
+keywords = {}
+
+htmlfiles = glob.glob1(path,'*.html')
+
+for fname in htmlfiles:
+    fil = open(os.path.join(path,fname))
+    # TODO maybe move to Python re (regex)
+    lines=fil.readlines()
+    try:
+        index_keys = lines.index('<h2>KEYWORDS</h2>\n')+1
+        index_desc = lines.index('<h2>NAME</h2>\n')+1
+    except:
+        continue 
+    try:
+        key = lines[index_keys].split(',')[1].strip().capitalize().replace(' ', '_')
+    except:
+        continue
+    try:
+        desc = lines[index_desc].split('-',1)[1].strip()
+    except:
+        desc.strip()
+    if key not in keywords.keys():
+        keywords[key] = {}
+        keywords[key][fname] = desc
+    elif fname not in keywords[key]:
+        keywords[key][fname] = desc
+
+topicsfile = open(os.path.join(path,'topics.html'),'w')
+topicsfile.write(header1_tmpl.substitute(title = "GRASS GIS " \
+                        "%s Reference Manual: Topics index" % grass_version))
+topicsfile.write(headertopics_tmpl)
+for key, values in sorted(keywords.iteritems()):
+    topicsfile.writelines([moduletopics_tmpl.substitute(key = key.lower(), 
+                                                        name = key.replace('_', ' '))])
+    keyfile = open(os.path.join(path,'topic_%s.html' % key.lower()),'w')
+    keyfile.write(header1_tmpl.substitute(title = "GRASS GIS " \
+                        "%s Reference Manual: Topic %s" % (grass_version, 
+                                                    key.replace('_', ' '))))
+    keyfile.write(headerkey_tmpl.substitute(keyword = key.replace('_', ' ')))
+    for mod, desc in sorted(values.iteritems()):
+        keyfile.write(desc1_tmpl.substitute(cmd = mod, desc = desc, 
+                                            basename = mod.replace('.html','')))
+    keyfile.write("</table>\n")
+    write_html_footer(keyfile, "index.html")
+topicsfile.write("</ul>\n")
+write_html_footer(topicsfile, "index.html")