[GRASS-SVN] r49911 - grass/trunk/scripts/g.extension.rebuild.all

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Dec 25 19:05:40 EST 2011


Author: martinl
Date: 2011-12-25 16:05:39 -0800 (Sun, 25 Dec 2011)
New Revision: 49911

Modified:
   grass/trunk/scripts/g.extension.rebuild.all/g.extension.rebuild.all.html
   grass/trunk/scripts/g.extension.rebuild.all/g.extension.rebuild.all.py
Log:
g.extension.rebuild.all: check libgis revision
			 flag to force rebuilding all extensions


Modified: grass/trunk/scripts/g.extension.rebuild.all/g.extension.rebuild.all.html
===================================================================
--- grass/trunk/scripts/g.extension.rebuild.all/g.extension.rebuild.all.html	2011-12-25 23:28:31 UTC (rev 49910)
+++ grass/trunk/scripts/g.extension.rebuild.all/g.extension.rebuild.all.html	2011-12-26 00:05:39 UTC (rev 49911)
@@ -9,18 +9,28 @@
 
 <h2>EXAMPLES</h2>
 
-Re-install all locally installed extensions
+Rebuild locally installed extensions which were built against
+different GIS Library (see <tt>g.version -r</tt>)
 
 <div class="code"><pre>
 g.extension.rebuild.all
 </pre></div>
 
+Force to rebuild all locally installed extensions
+
+<div class="code"><pre>
+g.extension.rebuild.all -f
+</pre></div>
+
 <h2>SEE ALSO</h2>
 
 <em>
   <a href="g.extension.html">g.extension</a>
 </em>
 
+<p>
+See also <a href="http://grass.osgeo.org/wiki/GRASS_AddOns">GRASS Addons</a> wiki page.
+
 <h2>AUTHOR</h2>
 
 <a href="http://geo.fsv.cvut.cz/gwiki/Landa">Martin

Modified: grass/trunk/scripts/g.extension.rebuild.all/g.extension.rebuild.all.py
===================================================================
--- grass/trunk/scripts/g.extension.rebuild.all/g.extension.rebuild.all.py	2011-12-25 23:28:31 UTC (rev 49910)
+++ grass/trunk/scripts/g.extension.rebuild.all/g.extension.rebuild.all.py	2011-12-26 00:05:39 UTC (rev 49911)
@@ -17,21 +17,65 @@
 #############################################################################
 
 #%module
-#% description: Rebuilds all locally installed GRASS Addons extensions.
+#% label: Rebuilds all locally installed GRASS Addons extensions.
+#% description: By default only extensions built against different GIS Library are rebuilt.
 #% keywords: general
 #% keywords: installation
 #% keywords: extensions
 #%end
+#%flag
+#% key: f
+#% description: Force to rebuild all extensions
+#% end
 
+import os
 import sys
 
+try:
+    import xml.etree.ElementTree as etree
+except ImportError:
+    import elementtree.ElementTree as etree # Python <= 2.4
+
 import grass.script as grass
 
+def get_extensions():
+    addon_base = os.getenv('GRASS_ADDON_BASE')
+    if not addon_base:
+        grass.fatal(_("%s not defined") % "GRASS_ADDON_BASE")
+    fXML = os.path.join(addon_base, 'modules.xml')
+    if not os.path.exists(fXML):
+        return []
+
+    # read XML file
+    fo = open(fXML, 'r')
+    try:
+        tree = etree.fromstring(fo.read())
+    except StandardError, e:
+        grass.error(_("Unable to parse metadata file: %s") % e)
+        fo.close()
+        return []
+    
+    fo.close()
+    
+    libgis_rev = grass.version()['libgis_revision']
+    ret = list()
+    for tnode in tree.findall('task'):
+        gnode = tnode.find('libgis')
+        if gnode is not None and \
+                gnode.get('revision', '') != libgis_rev:
+            ret.append(tnode.get('name'))
+    
+    return ret
+
 def main():
-    extensions = grass.read_command('g.extension',
-                                    quiet = True, flags = 'a').splitlines()
+    if flags['f']:
+        extensions = grass.read_command('g.extension',
+                                        quiet = True, flags = 'a').splitlines()
+    else:
+        extensions = get_extensions()
+    
     if not extensions:
-        grass.info(_("No extension installed. Nothing to rebuild."))
+        grass.info(_("Nothing to rebuild."))
         return 0
     
     for ext in extensions:



More information about the grass-commit mailing list