[GRASS-SVN] r52931 - grass/trunk/man
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Aug 27 02:36:01 PDT 2012
Author: lucadelu
Date: 2012-08-27 02:36:01 -0700 (Mon, 27 Aug 2012)
New Revision: 52931
Added:
grass/trunk/man/build_topics.py
Modified:
grass/trunk/man/Makefile
grass/trunk/man/build_html.py
Log:
add script to create topics in html documentation
Modified: grass/trunk/man/Makefile
===================================================================
--- grass/trunk/man/Makefile 2012-08-26 17:16:43 UTC (rev 52930)
+++ grass/trunk/man/Makefile 2012-08-27 09:36:01 UTC (rev 52931)
@@ -50,6 +50,7 @@
$(MAKE) $(INDICES)
$(call build,check)
$(MAKE) manpages
+ GISBASE="$(RUN_GISBASE)" ARCH="$(ARCH)" ARCH_DISTDIR="$(ARCH_DISTDIR)" $(PYTHON) ./build_topics.py $(HTMLDIR)
$(MAKE) restdocs
restdocs: $(DSTFILES_REST)
Modified: grass/trunk/man/build_html.py
===================================================================
--- grass/trunk/man/build_html.py 2012-08-26 17:16:43 UTC (rev 52930)
+++ grass/trunk/man/build_html.py 2012-08-27 09:36:01 UTC (rev 52931)
@@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# 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 os
@@ -160,7 +160,7 @@
footer_tmpl = string.Template(\
r"""<BR><BR>
<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>
© 2003-2012 <a href="http://grass.osgeo.org">GRASS Development Team</a>, GRASS GIS ${grass_version} Reference Manual</p>
</body>
</html>
@@ -239,6 +239,38 @@
""")
#"
+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):
Added: grass/trunk/man/build_topics.py
===================================================================
--- grass/trunk/man/build_topics.py (rev 0)
+++ grass/trunk/man/build_topics.py 2012-08-27 09:36:01 UTC (rev 52931)
@@ -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")
Property changes on: grass/trunk/man/build_topics.py
___________________________________________________________________
Added: svn:mime-type
+ text/x-python
Added: svn:eol-style
+ native
More information about the grass-commit
mailing list