[GRASS-SVN] r41549 - grass/trunk/gui/wxpython/support

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Mar 26 05:16:08 EDT 2010


Author: martinl
Date: 2010-03-26 05:15:50 -0400 (Fri, 26 Mar 2010)
New Revision: 41549

Modified:
   grass/trunk/gui/wxpython/support/update_menudata.py
Log:
updata_menudata.py - dry run (svn diff)


Modified: grass/trunk/gui/wxpython/support/update_menudata.py
===================================================================
--- grass/trunk/gui/wxpython/support/update_menudata.py	2010-03-26 01:30:20 UTC (rev 41548)
+++ grass/trunk/gui/wxpython/support/update_menudata.py	2010-03-26 09:15:50 UTC (rev 41549)
@@ -12,13 +12,16 @@
 License (>=v2). Read the file COPYING that comes with GRASS
 for details.
 
-Usage: python support/update_menudata.py
+Usage: python support/update_menudata.py [-d]
 
+ -d - dry run (prints diff, file is not updated)
+
 @author Martin Landa <landa.martin gmail.com>
 """
 
 import os
 import sys
+import tempfile
 try:
     import xml.etree.ElementTree as etree
 except ImportError:
@@ -101,9 +104,11 @@
         if module not in menu_modules:
             grass.warning("'%s' not available from the menu" % module)
     
-def writeData(data):
+def writeData(data, file = None):
     """!Write updated menudata.xml"""
-    file = os.path.join('xml', 'menudata.xml')
+    if file is None:
+        file = os.path.join('xml', 'menudata.xml')
+    
     try:
         if not os.path.exists(file):
             raise IOError
@@ -125,7 +130,12 @@
     if argv is None:
         argv = sys.argv
 
-    if len(argv) != 1:
+    if len(argv) > 1 and argv[1] == '-d':
+        printDiff = True
+    else:
+        printDiff = False
+
+    if len(argv) > 1 and argv[1] == '-h':
         print >> sys.stderr, __doc__
         return 1
     
@@ -136,9 +146,20 @@
     data = menudata.Data()
     grass.info("Step 3: updating menu data...")
     updateData(data, modules)
-    grass.info("Step 4: writing menu data (menudata.xml)...")
-    writeData(data)
-    
+
+    if printDiff:
+        tempFile = tempfile.NamedTemporaryFile()
+        grass.info("Step 4: writing menu data...")
+        writeData(data, tempFile.name)
+        
+        nuldev = file(os.devnull, 'w+')
+        grass.call(['svn', 'diff',
+                    os.path.join('xml', 'menudata.xml'),
+                    tempFile.name], stderr = nuldev)
+    else:
+        grass.info("Step 4: writing menu data (menudata.xml)...")
+        writeData(data)
+        
     return 0
 
 if __name__ == '__main__':



More information about the grass-commit mailing list