[GRASS-SVN] r37607 - grass/branches/releasebranch_6_4/gui/wxpython/support

svn_grass at osgeo.org svn_grass at osgeo.org
Sat May 30 06:26:31 EDT 2009


Author: martinl
Date: 2009-05-30 06:26:31 -0400 (Sat, 30 May 2009)
New Revision: 37607

Added:
   grass/branches/releasebranch_6_4/gui/wxpython/support/update_menudata.py
Removed:
   grass/branches/releasebranch_6_4/gui/wxpython/support/update_menu_desc.py
Log:
script synchronized with devbr6


Deleted: grass/branches/releasebranch_6_4/gui/wxpython/support/update_menu_desc.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/support/update_menu_desc.py	2009-05-30 10:18:02 UTC (rev 37606)
+++ grass/branches/releasebranch_6_4/gui/wxpython/support/update_menu_desc.py	2009-05-30 10:26:31 UTC (rev 37607)
@@ -1,103 +0,0 @@
-"""
- at brief Reads menu data from menudata.py and for each command updates
-its description (based on interface description).
-
-Updated menu data is printed to stdout.
-
-Support script for wxGUI.
-
-COPYRIGHT:  (C) 2008 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.
-
-Usage: python update_menu_desc.py
-
- at author Martin Landa <landa.martin gmail.com>
-"""
-
-import os
-import sys
-
-import xml.sax
-import xml.sax.handler
-HandlerBase=xml.sax.handler.ContentHandler
-from xml.sax import make_parser
-
-def read_menudata():
-    menu = menudata.Data() # get menu data
-    for mainItem in menu.GetMenu()[0]:
-        print '                (_("%s"), (' % mainItem[0]
-        for item1 in mainItem[1]:
-            if len(item1[0]) == 0: # separator
-                print '                        ("","","", ""),'
-                continue
-            if len(item1) == 4:
-                desc = get_description(item1[1:])
-                print '                        (_("%s"),' % item1[0]
-                if desc and desc != item1[1]:
-                    print '                         _("%s"),' % desc
-                else:
-                    print '                         _("%s"),' % item1[1]
-                print '                         "%s",' % item1[2]
-                print '                         "%s"),' % item1[3]
-            else: # submenu
-                print '                        (_("%s"), (' % item1[0]
-                for item2 in item1[1]:
-                    if len(item2[0]) == 0: # separator
-                        print '                                ("","","", ""),'
-                        continue
-                    desc = get_description(item2[1:])
-                    print '                                (_("%s"),' % item2[0]
-                    if desc and desc != item2[1]:
-                        print '                                 _("%s"),' % desc
-                    else:
-                        print '                                 _("%s"),' % item2[1]
-                    print '                                 "%s",' % item2[2]
-                    print '                                 "%s"),' % item2[3]
-                print '                                )'
-                print '                         ),'
-        print '                        )'
-        print '                 ),'
-
-def get_description(item):
-    """Return command desctiption based on interface
-    description"""
-    print 
-    desc, type, cmd = item
-    if type in ("self.OnMenuCmd", "self.RunMenuCmd"):
-        module = cmd.split(' ')[0]
-        grass_task = menuform.grassTask()
-        handler = menuform.processTask(grass_task)
-        xml.sax.parseString(menuform.getInterfaceDescription(module), handler )
-
-        return grass_task.description.replace('"', '\\"')
-
-    return None
-
-def main(argv=None):
-    if argv is None:
-        argv = sys.argv
-
-    if len(argv) != 1:
-        print >> sys.stderr, __doc__
-        return 0
-
-    ### i18N
-    import gettext
-    gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
-
-    read_menudata()
-
-    return 0
-
-if __name__ == '__main__':
-    if os.getenv("GISBASE") is None:
-        print >> sys.stderr, "You must be in GRASS GIS to run this program."
-        sys.exit(1)
-
-    sys.path.append('../gui_modules')
-    import menudata
-    import menuform
-
-    sys.exit(main())

Copied: grass/branches/releasebranch_6_4/gui/wxpython/support/update_menudata.py (from rev 37602, grass/branches/releasebranch_6_4/gui/wxpython/support/update_menu_desc.py)
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/support/update_menudata.py	                        (rev 0)
+++ grass/branches/releasebranch_6_4/gui/wxpython/support/update_menudata.py	2009-05-30 10:26:31 UTC (rev 37607)
@@ -0,0 +1,111 @@
+"""
+ at brief Support script for wxGUI - only for developers needs. Updates
+menudata.xml file.
+
+Parse all GRASS modules in the search path ('bin' & 'script') and
+updates: - description (i.e. help)
+
+Prints warning for missing modules.
+
+(C) 2008-2009 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.
+
+Usage: python update_menudata.py
+
+ at author Martin Landa <landa.martin gmail.com>
+"""
+
+import os
+import sys
+try:
+    import xml.etree.ElementTree as etree
+except ImportError:
+    import elementtree.ElementTree as etree # Python <= 2.4
+
+def parseModules():
+    """!Parse modules' interface"""
+    modules = dict()
+    
+    # list of modules to be ignored
+    ignore =  [ 'mkftcap' ]
+    
+    count = len(globalvar.grassCmd['all'])
+    i = 0
+    for module in globalvar.grassCmd['all']:
+        i += 1
+        if i % 10 == 0:
+            print '   %d/%d' % (i, count)
+        if module in ignore:
+            continue
+        try:
+            interface = menuform.GUI().ParseInterface(cmd = [module])
+        except IOError, e:
+            print >> sys.stderr, e
+            continue
+        modules[interface.name] = { 'label'   : interface.label,
+                                    'desc'    : interface.description }
+        
+    return modules
+
+def updateData(data, modules):
+    """!Update menu data tree"""
+    for node in data.tree.getiterator():
+        if node.tag != 'menuitem':
+            continue
+        
+        item = dict()
+        for child in node.getchildren():
+            item[child.tag] = child.text
+        
+        if not item.has_key('command'):
+            continue
+        
+        module = item['command'].split(' ')[0]
+        if not modules.has_key(module):
+            print 'WARNING: \'%s\' not found in modules' % item['command']
+            continue
+        
+        if modules[module]['label']:
+            desc = modules[module]['label']
+        else:
+            desc = modules[module]['desc']
+        node.find('help').text = desc
+        
+def writeData(data):
+    """!Write updated menudata.xml"""
+    file = os.path.join('..', 'xml', 'menudata.xml')
+    data.tree.write(file)
+
+def main(argv = None):
+    if argv is None:
+        argv = sys.argv
+
+    if len(argv) != 1:
+        print >> sys.stderr, __doc__
+        return 1
+    
+    print "Step 1: parse modules..."
+    modules = dict()
+    modules = parseModules()
+    print "Step 2: read menu data..."
+    data = menudata.Data()
+    print "Step 3: update menu data..."
+    updateData(data, modules)
+    print "Step 4: write menu data (menudata.xml)..."
+    writeData(data)
+    
+    return 0
+
+if __name__ == '__main__':
+    if os.getenv("GISBASE") is None:
+        print >> sys.stderr, "You must be in GRASS GIS to run this program."
+        sys.exit(1)
+    
+    sys.path.append('../gui_modules')
+    import menudata
+    import menuform
+    import globalvar
+    
+    sys.exit(main())


Property changes on: grass/branches/releasebranch_6_4/gui/wxpython/support/update_menudata.py
___________________________________________________________________
Name: svn:mime-type
   + text/x-python
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native



More information about the grass-commit mailing list