[GRASS-SVN] r66517 - in grass-addons/tools/addons: . test test/data

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Oct 16 08:44:52 PDT 2015


Author: wenzeslaus
Date: 2015-10-16 08:44:52 -0700 (Fri, 16 Oct 2015)
New Revision: 66517

Added:
   grass-addons/tools/addons/get_page_description.py
   grass-addons/tools/addons/test/
   grass-addons/tools/addons/test/data/
   grass-addons/tools/addons/test/data/g.broken.example.html
   grass-addons/tools/addons/test/data/r.group.page.html
   grass-addons/tools/addons/test/data/r.standard.example.html
   grass-addons/tools/addons/test/data/wxGUI.example.html
   grass-addons/tools/addons/test/test_description_extraction.sh
Removed:
   grass-addons/tools/addons/get_page_description.sh
Modified:
   grass-addons/tools/addons/grass-addons-index.sh
Log:
Python port of description extraction for addons

The new version drops adding li end tag which was not working.
It also trips leading space and adds this to the caller script which
now adds space after colon.

Adding test files and script to quickly test the standalone script.


Copied: grass-addons/tools/addons/get_page_description.py (from rev 66516, grass-addons/tools/addons/get_page_description.sh)
===================================================================
--- grass-addons/tools/addons/get_page_description.py	                        (rev 0)
+++ grass-addons/tools/addons/get_page_description.py	2015-10-16 15:44:52 UTC (rev 66517)
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+
+# PURPOSE: Extracts page one line descriptions for index.html of GRASS GIS Addons
+
+# AUTHORS: Martin Landa (Bash version)
+#          Vaclav Petras (Python version)
+
+import os
+import sys
+import re
+
+
+def get_desc_from_manual_page_line(text):
+    """
+    >>> get_desc_from_manual_page_line("r.example - This is a description<br>")
+    'This is a description'
+    """
+    # this matches the dash at the beginning
+    text = text.split(" - ", 1)[1]
+    # this matches a tag at the end
+    # (supposing no tags in the description and < represented as <
+    text = text.split("<", 1)[0]
+    return text
+
+
+def main(filename):
+    with open(filename) as page_file:
+        desc = None
+        in_desc_block = False
+        desc_block_start = re.compile(r'NAME')
+        desc_block_end = re.compile(r'KEYWORDS')
+        desc_line = re.compile(r' - ')
+        for line in page_file:
+            line = line.rstrip()  # remove '\n' at end of line
+            if desc_block_start.search(line):
+                in_desc_block = True
+            elif desc_block_end.search(line):
+                in_desc_block = False
+            if in_desc_block:
+                if desc_line.search(line):
+                    desc = get_desc_from_manual_page_line(line)
+        if not desc:
+            desc = "(incomplete manual page, please fix)"
+        # the original script attempted to add also </li> but it as not working
+        # now we leave up to the caller as well as whitespace around
+        print desc
+
+
+if __name__ == "__main__":
+    if len(sys.argv) != 2:
+        sys.exit("{name} takes exactly one argument (HTML manual page name)."
+                 " {argc} parameters were given."
+                 .format(name=os.path.basename(sys.argv[0]),
+                                               argc=len(sys.argv) - 1))
+    sys.exit(main(sys.argv[1]))

Deleted: grass-addons/tools/addons/get_page_description.sh
===================================================================
--- grass-addons/tools/addons/get_page_description.sh	2015-10-16 13:53:02 UTC (rev 66516)
+++ grass-addons/tools/addons/get_page_description.sh	2015-10-16 15:44:52 UTC (rev 66517)
@@ -1,30 +0,0 @@
-#!/bin/sh
-
-# PURPOSE: Extracts page one line descriptions for index.html of GRASS GIS Addons
-
-# AUTHORS: Martin Landa
-
-if [ $# -ne 1 ]; then
-    echo "$(basename $0) takes exactly one argument (HTML manual page name)"
-    exit 1
-fi
-
-TMP=$$
-
-currfile=$1
-
-grep 'KEYWORDS' $currfile 2> /dev/null > /dev/null
-if [ $? -eq 0 ] ; then
-    # keywords found, so go ahead with extraction of one-line description
-    cat $currfile | awk '/NAME/,/KEYWORDS/' | grep ' - ' | cut -d'-' -f2- | cut -d'<' -f1 | sed 's+>$+></li>+g'  >> /tmp/d.$TMP
-    # argh, fake keyword line found (broken manual page or missing g.parser usage)
-    if [ ! -s /tmp/d.$TMP ] ; then
-        echo "(incomplete manual page, please fix; name part not found)" > /tmp/d.$TMP
-    fi
-    cat /tmp/d.$TMP
-    rm -f /tmp/d.$TMP
-else
-    # let's try to be more robust against missing keywords in a few HTML pages
-    # argh, no keywords found (broken manual page or missing g.parser usage)
-    echo "(incomplete manual page, please fix; keyword part not found)"
-fi

Modified: grass-addons/tools/addons/grass-addons-index.sh
===================================================================
--- grass-addons/tools/addons/grass-addons-index.sh	2015-10-16 13:53:02 UTC (rev 66516)
+++ grass-addons/tools/addons/grass-addons-index.sh	2015-10-16 15:44:52 UTC (rev 66517)
@@ -122,8 +122,8 @@
 	fi
 
 	module=`echo $currfile | sed 's+\.html$++g'`
-	echo "<li style=\"margin-left: 20px\"><a href=\"$currfile\">$module</a>:" >> index.html
-        ${SRC}grass-addons/tools/addons/get_page_description.sh $currfile >> index.html
+	echo "<li style=\"margin-left: 20px\"><a href=\"$currfile\">$module</a>: " >> index.html
+        ${SRC}grass-addons/tools/addons/get_page_description.py $currfile >> index.html
     done
 
     year=`date +%Y`

Added: grass-addons/tools/addons/test/data/g.broken.example.html
===================================================================
--- grass-addons/tools/addons/test/data/g.broken.example.html	                        (rev 0)
+++ grass-addons/tools/addons/test/data/g.broken.example.html	2015-10-16 15:44:52 UTC (rev 66517)
@@ -0,0 +1,43 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<title>GRASS GIS Manual (test page): r.broken.example</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+<body>
+
+<hr class="header">
+
+<h2>NAME</h2>
+<em><b>r.broken.example</b></em> <h2>KEYWORDS</h2>
+
+<h2>DESCRIPTION</h2>
+
+This is a test page which should be emulate a broken manual page.
+This can happen for example, when module cannot generate a proper
+description (broken imports, not using parser, etc.).
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="wxGUI.components.html">wxGUI components</a><br>
+</em>
+
+<h2>AUTHORS</h2>
+
+Random Author
+
+<p>
+<i>Data placeholder: 2015-09-06 (Sun, 06 Sep 2015)</i><hr class="header">
+<p>
+<a href="index.html">Main index</a>
+<p>
+© 2003-2015
+<a href="http://grass.osgeo.org">GRASS Development Team</a>,
+GRASS GIS x.x Reference Manual (test page)
+</p>
+
+</div>
+</body>
+</html>


Property changes on: grass-addons/tools/addons/test/data/g.broken.example.html
___________________________________________________________________
Added: svn:mime-type
   + text/html
Added: svn:keywords
   + Author Date Id
Added: svn:eol-style
   + native

Added: grass-addons/tools/addons/test/data/r.group.page.html
===================================================================
--- grass-addons/tools/addons/test/data/r.group.page.html	                        (rev 0)
+++ grass-addons/tools/addons/test/data/r.group.page.html	2015-10-16 15:44:52 UTC (rev 66517)
@@ -0,0 +1,42 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<title>GRASS GIS Manual (test page): r.group.page</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+<body>
+
+<hr class="header">
+
+<h2>NAME</h2>
+<em><b>r.group.page</b></em>
+
+<h2>DESCRIPTION</h2>
+
+This is a test page which should be similar to a manual page of a group
+of modules. Example can be r.modis which is not a module but it has
+its own page which links to r.modis.download and r.modis.import.
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="wxGUI.components.html">wxGUI components</a><br>
+</em>
+
+<h2>AUTHORS</h2>
+
+Random Author
+
+<p>
+<i>Data placeholder: 2015-09-06 (Sun, 06 Sep 2015)</i><hr class="header">
+<p>
+<a href="index.html">Main index</a>
+<p>
+© 2003-2015
+<a href="http://grass.osgeo.org">GRASS Development Team</a>,
+GRASS GIS x.x Reference Manual (test page)
+</p>
+
+</body>
+</html>


Property changes on: grass-addons/tools/addons/test/data/r.group.page.html
___________________________________________________________________
Added: svn:mime-type
   + text/html
Added: svn:keywords
   + Author Date Id
Added: svn:eol-style
   + native

Added: grass-addons/tools/addons/test/data/r.standard.example.html
===================================================================
--- grass-addons/tools/addons/test/data/r.standard.example.html	                        (rev 0)
+++ grass-addons/tools/addons/test/data/r.standard.example.html	2015-10-16 15:44:52 UTC (rev 66517)
@@ -0,0 +1,45 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<title>GRASS GIS Manual (test page): r.standard.example</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+<body>
+
+<hr class="header">
+
+<h2>NAME</h2>
+<em><b>r.standard.example</b></em>  - Description/label of a standard module.<BR>
+Aspect is calculated counterclockwise from east.
+<h2>KEYWORDS</h2>
+<a href="raster.html">raster</a>, <a href="topic_terrain.html">terrain</a>, <a href="keywords.html#aspect">aspect</a>
+
+
+<h2>DESCRIPTION</h2>
+
+This is a test page which should be similar to a standard module manual page.
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="wxGUI.components.html">wxGUI components</a><br>
+</em>
+
+<h2>AUTHORS</h2>
+
+Random Author
+
+<p>
+<i>Data placeholder: 2015-09-06 (Sun, 06 Sep 2015)</i><hr class="header">
+<p>
+<a href="index.html">Main index</a>
+<p>
+© 2003-2015
+<a href="http://grass.osgeo.org">GRASS Development Team</a>,
+GRASS GIS x.x Reference Manual (test page)
+</p>
+
+</div>
+</body>
+</html>


Property changes on: grass-addons/tools/addons/test/data/r.standard.example.html
___________________________________________________________________
Added: svn:mime-type
   + text/html
Added: svn:keywords
   + Author Date Id
Added: svn:eol-style
   + native

Added: grass-addons/tools/addons/test/data/wxGUI.example.html
===================================================================
--- grass-addons/tools/addons/test/data/wxGUI.example.html	                        (rev 0)
+++ grass-addons/tools/addons/test/data/wxGUI.example.html	2015-10-16 15:44:52 UTC (rev 66517)
@@ -0,0 +1,42 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<title>GRASS GIS Manual (test page): wxGUI</title>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+<body>
+
+<hr class="header">
+
+<h2>wxGUI</h2>
+
+<!-- meta page description: wxGUI -->
+
+<h2>DESCRIPTION</h2>
+
+This is a test page which should be similar to a wxGUI manual pages.
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="wxGUI.components.html">wxGUI components</a><br>
+</em>
+
+<h2>AUTHORS</h2>
+
+Random Author
+
+<p>
+<i>Data placeholder: 2015-09-06 (Sun, 06 Sep 2015)</i><hr class="header">
+<p>
+<a href="index.html">Main index</a>
+<p>
+© 2003-2015
+<a href="http://grass.osgeo.org">GRASS Development Team</a>,
+GRASS GIS x.x Reference Manual (test page)
+</p>
+
+</div>
+</body>
+</html>


Property changes on: grass-addons/tools/addons/test/data/wxGUI.example.html
___________________________________________________________________
Added: svn:mime-type
   + text/html
Added: svn:keywords
   + Author Date Id
Added: svn:eol-style
   + native

Added: grass-addons/tools/addons/test/test_description_extraction.sh
===================================================================
--- grass-addons/tools/addons/test/test_description_extraction.sh	                        (rev 0)
+++ grass-addons/tools/addons/test/test_description_extraction.sh	2015-10-16 15:44:52 UTC (rev 66517)
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+# test get_page_description.py
+# must be executed in the directory where it is paced in the source code
+
+python -m doctest ../get_page_description.py
+../get_page_description.py data/r.standard.example.html
+../get_page_description.py data/r.group.page.html
+../get_page_description.py data/wxGUI.example.html
+../get_page_description.py data/g.broken.example.html


Property changes on: grass-addons/tools/addons/test/test_description_extraction.sh
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:mime-type
   + text/x-sh
Added: svn:eol-style
   + native



More information about the grass-commit mailing list