[GRASS-SVN] r39796 - in grass/trunk: include/Make tools

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Nov 24 18:11:37 EST 2009


Author: glynn
Date: 2009-11-24 18:11:36 -0500 (Tue, 24 Nov 2009)
New Revision: 39796

Added:
   grass/trunk/tools/mkhtml.py
Removed:
   grass/trunk/tools/mkhtml.sh
Modified:
   grass/trunk/include/Make/Html.make
   grass/trunk/include/Make/ScriptRules.make
   grass/trunk/tools/Makefile
Log:
Convert mkhtml script to Python


Modified: grass/trunk/include/Make/Html.make
===================================================================
--- grass/trunk/include/Make/Html.make	2009-11-24 23:00:08 UTC (rev 39795)
+++ grass/trunk/include/Make/Html.make	2009-11-24 23:11:36 UTC (rev 39796)
@@ -12,7 +12,7 @@
 IMGSRC := $(wildcard *.png) $(wildcard *.jpg)
 
 $(HTMLDIR)/%.html: %.html %.tmp.html $(HTMLSRC) | $(HTMLDIR)
-	$(GISBASE)/tools/mkhtml.sh $* > $@
+	$(PYTHON) $(GISBASE)/tools/mkhtml.py $* > $@
 	$(MAKE) $(patsubst %,$(HTMLDIR)/%,$(IMGSRC))
 
 $(HTMLDIR)/%.png: %.png | $(HTMLDIR)

Modified: grass/trunk/include/Make/ScriptRules.make
===================================================================
--- grass/trunk/include/Make/ScriptRules.make	2009-11-24 23:00:08 UTC (rev 39795)
+++ grass/trunk/include/Make/ScriptRules.make	2009-11-24 23:11:36 UTC (rev 39796)
@@ -3,14 +3,15 @@
 
 STRINGDIR = $(GRASS_HOME)/locale/scriptstrings
 
-$(SCRIPTDIR)/%: %.py
-	if [ ! -d $(SCRIPTDIR) ]; then $(MKDIR) $(SCRIPTDIR); fi
+$(SCRIPTDIR)/%: %.py | $(SCRIPTDIR)
 	$(INSTALL) $< $@
 
-$(SCRIPTDIR)/%.py: %.py
-	if [ ! -d $(SCRIPTDIR) ]; then $(MKDIR) $(SCRIPTDIR); fi
+$(SCRIPTDIR)/%.py: %.py | $(SCRIPTDIR)
 	$(INSTALL) $< $@
 
+$(SCRIPTDIR):
+	$(MKDIR) $(SCRIPTDIR)
+
 # Make strings in a fake .c file so that they get picked up by the internationalizer stuff.
 # These are only the options (parser.c) type things.
 # See locale/scriptstrings/README for more information

Modified: grass/trunk/tools/Makefile
===================================================================
--- grass/trunk/tools/Makefile	2009-11-24 23:00:08 UTC (rev 39795)
+++ grass/trunk/tools/Makefile	2009-11-24 23:11:36 UTC (rev 39796)
@@ -4,7 +4,7 @@
 
 include $(MODULE_TOPDIR)/include/Make/Dir.make
 
-default: parsubdirs $(TOOLSDIR)/mkhtml.sh
+default: parsubdirs $(TOOLSDIR)/mkhtml.py
 
-$(TOOLSDIR)/mkhtml.sh: mkhtml.sh
+$(TOOLSDIR)/mkhtml.py: mkhtml.py
 	$(INSTALL) $< $@

Added: grass/trunk/tools/mkhtml.py
===================================================================
--- grass/trunk/tools/mkhtml.py	                        (rev 0)
+++ grass/trunk/tools/mkhtml.py	2009-11-24 23:11:36 UTC (rev 39796)
@@ -0,0 +1,94 @@
+#!/usr/bin/env python
+
+############################################################################
+#
+# MODULE:       mkhtml.py
+# AUTHOR(S):    Markus Neteler, Glynn Clements
+# PURPOSE:      create HTML manual page snippets
+# COPYRIGHT:    (C) 2007,2009 Glynn Clements and the GRASS Development Team
+#
+#               This program is free software under the GNU General Public
+#               License (>=v2). Read the file COPYING that comes with GRASS
+#               for details.
+#
+#############################################################################
+
+import sys
+import os
+import string
+import re
+
+pgm = sys.argv[1]
+
+src_file = "%s.html" % pgm
+tmp_file = "%s.tmp.html" % pgm
+
+header_tmpl = string.Template(\
+"""<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<title>GRASS GIS Manual: ${PGM}</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+<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>NAME</h2>
+<em><b>${PGM}</b></em>
+""")
+
+footer_tmpl = string.Template(\
+"""<hr>
+<p><a href="index.html">Main index</a> - <a href="$INDEXNAME.html">$INDEXNAME index</a> - <a href="full_index.html">Full index</a></p>
+<p>&copy; 2003-2009 <a href="http://grass.osgeo.org">GRASS Development Team</a></p>
+</body>
+</html>
+""")
+
+def read_file(name):
+    try:
+	f = open(name, 'rb')
+	s = f.read()
+	f.close()
+	return s
+    except IOError:
+	return ""
+
+src_data = read_file(src_file)
+
+if not re.search('<html>', src_data, re.IGNORECASE):
+    tmp_data = read_file(tmp_file)
+    if not re.search('<html>', tmp_data, re.IGNORECASE):
+	sys.stdout.write(header_tmpl.substitute(PGM = pgm))
+    if tmp_data:
+	for line in tmp_data.splitlines(True):
+	    if not re.search('</body>|</html>', line, re.IGNORECASE):
+		sys.stdout.write(line)
+
+sys.stdout.write(src_data)
+
+# if </html> is found, suppose a complete html is provided.
+# otherwise, generate module class reference:
+if re.search('</html>', src_data, re.IGNORECASE):
+    sys.exit()
+
+index_names = {
+    'd': 'display',
+    'db': 'database',
+    'g': 'general',
+    'i': 'imagery',
+    'm': 'misc',
+    'pg': 'postGRASS',
+    'ps': 'postscript',
+    'p': 'paint',
+    'r': 'raster',
+    'r3': 'raster3D',
+    's': 'sites',
+    'v': 'vector'
+    }
+
+mod_class = pgm.split('.', 1)[0]
+index_name = index_names.get(mod_class, mod_class)
+
+sys.stdout.write(footer_tmpl.substitute(INDEXNAME = index_name))
+

Deleted: grass/trunk/tools/mkhtml.sh
===================================================================
--- grass/trunk/tools/mkhtml.sh	2009-11-24 23:00:08 UTC (rev 39795)
+++ grass/trunk/tools/mkhtml.sh	2009-11-24 23:11:36 UTC (rev 39796)
@@ -1,70 +0,0 @@
-#!/bin/sh
-
-############################################################################
-#
-# MODULE:       mkhtml.sh
-# AUTHOR(S):    Markus Neteler, Glynn Clements
-# PURPOSE:      create HTML manual page snippets
-# COPYRIGHT:    (C) 2007 by the GRASS Development Team
-#
-#               This program is free software under the GNU General Public
-#               License (>=v2). Read the file COPYING that comes with GRASS
-#               for details.
-#
-#############################################################################
-
-PGM=$1
-
-if ! grep -i '<html>' "${PGM}.html" > /dev/null 2>&1 ; then
-    if ! grep -i '<html>' "${PGM}.tmp.html" > /dev/null 2>&1 ; then
-	cat <<-EOF
-	<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-	<html>
-	<head>
-	<title>GRASS GIS Manual: ${PGM}</title>
-	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
-	<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>NAME</h2>
-	<em><b>${PGM}</b></em>
-	EOF
-    fi
-    if [ -f "${PGM}.tmp.html" ] ; then
-	grep -iv '</body>\|</html>' "${PGM}.tmp.html"
-    fi
-fi
-
-cat "${PGM}.html"
-
-# if </html> is found, suppose a complete html is provided.
-# otherwise, generate module class reference:
-if grep -i '</html>' "${PGM}.html" > /dev/null 2>&1 ; then
-    exit 0
-fi
-
-MODCLASS=`echo ${PGM} | cut -d'.' -f1`
-case $MODCLASS in
-    d)  INDEXNAME=display   ;;
-    db) INDEXNAME=database  ;;
-    g)  INDEXNAME=general   ;;
-    i)  INDEXNAME=imagery   ;;
-    m)  INDEXNAME=misc      ;;
-    pg) INDEXNAME=postGRASS ;;
-    ps) INDEXNAME=postscript ;;
-    p)  INDEXNAME=paint     ;;
-    r)  INDEXNAME=raster    ;;
-    r3) INDEXNAME=raster3D  ;;
-    s)  INDEXNAME=sites     ;;
-    v)  INDEXNAME=vector    ;;
-    *)  INDEXNAME=$MODCLASS ;;
-esac
-
-cat <<-EOF
-	<hr>
-	<p><a href="index.html">Main index</a> - <a href="$INDEXNAME.html">$INDEXNAME index</a> - <a href="full_index.html">Full index</a></p>
-	<p>&copy; 2003-2009 <a href="http://grass.osgeo.org">GRASS Development Team</a></p>
-	</body>
-	</html>
-EOF



More information about the grass-commit mailing list