[GRASS-SVN] r66481 - grass-addons/tools/addons

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Oct 12 17:34:34 PDT 2015


Author: wenzeslaus
Date: 2015-10-12 17:34:33 -0700 (Mon, 12 Oct 2015)
New Revision: 66481

Modified:
   grass-addons/tools/addons/grass-addons-build.sh
   grass-addons/tools/addons/update_manual.py
Log:
don't change links for the actual HTML files, don't guess from addon names

r66479 and r66480 were doing nothing as the actual HTMLs are in docs/html directory.

Adding path to existing HTMLs as a 3rd parameter to update_manual.py. In this
way it is possible to test it locally.

The tree is traversed for every file to find existing HTMLs (as opposed to
having one script to fix all files or storing filenames in a file).
With all HTMLs in trunk's dist dir and searching in trunk including dist dir
it takes real 3m45.726s, user 2m16.512s, sys 1m23.124s. The addons case
should be smaller.


Modified: grass-addons/tools/addons/grass-addons-build.sh
===================================================================
--- grass-addons/tools/addons/grass-addons-build.sh	2015-10-12 21:01:41 UTC (rev 66480)
+++ grass-addons/tools/addons/grass-addons-build.sh	2015-10-13 00:34:33 UTC (rev 66481)
@@ -30,7 +30,7 @@
     for dir in `find . -maxdepth 1 -type d`; do
         if [ -d $dir/docs/html ] ; then
             for f in `pwd`/$dir/docs/html/*.html ; do 
-                ${SRC}grass-addons/tools/addons/update_manual.py $f http://grass.osgeo.org/grass${1}${2}/manuals
+                ${SRC}grass-addons/tools/addons/update_manual.py $f http://grass.osgeo.org/grass${1}${2}/manuals `pwd`
             done
             cp -r $dir/docs/html/* $HTMLDIR/ 2>/dev/null
         fi

Modified: grass-addons/tools/addons/update_manual.py
===================================================================
--- grass-addons/tools/addons/update_manual.py	2015-10-12 21:01:41 UTC (rev 66480)
+++ grass-addons/tools/addons/update_manual.py	2015-10-13 00:34:33 UTC (rev 66481)
@@ -8,21 +8,20 @@
 import re
 
 
-def get_addons(path):
-    """Get list of addons
+def get_pages(path):
+    """Get list of HTML pages in the given directory and its subdirectories
 
-    Goes two levels deep to get directory names which are assumed
-    to be addon names.
+    Only filenames are returned, not the paths.
     """
-    top_directories = os.walk(path).next()[1]
-    addons = []
-    for directory in top_directories:
-        addons.extend(os.walk(directory).next()[1])
-    addons.extend(top_directories)
-    return addons
+    matches = []
+    for root, dirnames, filenames in os.walk(path):
+        for filename in filenames:
+            if filename.endswith('.html'):
+                matches.append(filename)
+    return matches
 
 
-def main(htmlfile, prefix):
+def main(htmlfile, prefix, html_directory):
     try:
         f = open(htmlfile)
         shtml = f.read()
@@ -35,8 +34,7 @@
 
     # find URIs
     pattern = r'''<a href="([^"]+)">([^>]+)</a>'''
-    # TODO: replace the magic 4 by passing the base addons dir as parameter
-    addons = get_addons(os.sep.join(htmlfile.split(os.sep)[:4]))
+    addon_pages = get_pages(html_directory)
     for match in re.finditer(pattern, shtml):
         # most common URLs
         if match.group(1).startswith('http://'):
@@ -48,7 +46,7 @@
             continue
         # TODO: perhaps we could match any *://
         # link to other addon
-        if match.group(1).replace('.html', '') in addons:
+        if match.group(1) in addon_pages:
             continue
         pos.append(match.start(1))
 
@@ -72,6 +70,6 @@
 
 
 if __name__ == "__main__":
-    if len(sys.argv) != 3:
-        sys.exit("provide file and url")
-    main(sys.argv[1], sys.argv[2])
+    if len(sys.argv) != 4:
+        sys.exit("Provide file, URL and directory with other HTML files")
+    main(sys.argv[1], sys.argv[2], sys.argv[3])



More information about the grass-commit mailing list