2 @brief Support script for wxGUI - only for developers needs. Updates
5 Parse all GRASS modules in the search path ('bin' & 'script') and
6 updates: - description (i.e. help) - keywords
8 Prints warning for missing modules.
10 (C) 2008-2010 by the GRASS Development Team
11 This program is free software under the GNU General Public
12 License (>=v2). Read the file COPYING that comes with GRASS
15 Usage: python support/update_menudata.py [-d]
17 -d - dry run (prints diff, file is not updated)
19 @author Martin Landa <landa.martin gmail.com>
26 import xml.etree.ElementTree
as etree
28 import elementtree.ElementTree
as etree
33 sys.path.append(
'gui_modules')
37 """!Parse modules' interface"""
47 count = len(globalvar.grassCmd[
'all'])
49 for module
in globalvar.grassCmd[
'all']:
52 grass.info(
'* %d/%d' % (i, count))
56 interface = gtask.parse_interface(module)
60 modules[interface.name] = {
'label' : interface.label,
61 'desc' : interface.description,
62 'keywords': interface.keywords }
67 """!Update menu data tree"""
69 ignore = [
'v.type_wrapper.py',
73 for node
in data.tree.getiterator():
74 if node.tag !=
'menuitem':
78 for child
in node.getchildren():
79 item[child.tag] = child.text
81 if 'command' not in item:
84 if item[
'command']
in ignore:
87 module = item[
'command'].
split(
' ')[0]
88 if module
not in modules:
89 grass.warning(
"'%s' not found in modules" % item[
'command'])
92 if modules[module][
'label']:
93 desc = modules[module][
'label']
95 desc = modules[module][
'desc']
96 if node.find(
'handler').text ==
'OnMenuCmd':
97 node.find(
'help').text = desc
99 if 'keywords' not in modules[module]:
100 grass.warning(
'%s: keywords missing' % module)
102 if node.find(
'keywords')
is None:
103 node.insert(2, etree.Element(
'keywords'))
104 grass.warning(
"Adding tag 'keywords' to '%s'" % module)
105 node.find(
'keywords').text =
','.join(modules[module][
'keywords'])
107 menu_modules.append(item[
'command'])
109 for module
in modules.keys():
110 if module
not in menu_modules:
111 grass.warning(
"'%s' not available from the menu" % module)
114 """!Write updated menudata.xml"""
116 file = os.path.join(
'xml',
'menudata.xml')
119 data.tree.write(file)
121 print >> sys.stderr,
"'%s' not found. Please run the script from 'gui/wxpython'." % file
131 print >> sys.stderr,
"ERROR: Unable to write to menudata file."
137 if len(argv) > 1
and argv[1] ==
'-d':
142 if len(argv) > 1
and argv[1] ==
'-h':
143 print >> sys.stderr, __doc__
146 nuldev = file(os.devnull,
'w+')
147 grass.info(
"Step 1: running make...")
148 grass.call([
'make'], stderr = nuldev)
149 grass.info(
"Step 2: parsing modules...")
152 grass.info(
"Step 3: reading menu data...")
153 data = menudata.ManagerData()
154 grass.info(
"Step 4: updating menu data...")
158 tempFile = tempfile.NamedTemporaryFile()
159 grass.info(
"Step 5: diff menu data...")
162 grass.call([
'diff',
'-u',
163 os.path.join(
'xml',
'menudata.xml'),
164 tempFile.name], stderr = nuldev)
166 grass.info(
"Step 5: writing menu data (menudata.xml)...")
171 if __name__ ==
'__main__':
172 if os.getenv(
"GISBASE")
is None:
173 sys.exit(
"You must be in GRASS GIS to run this program.")
175 sys.path.append(os.path.join(os.getenv(
"GISBASE"),
'etc',
'wxpython',
'gui_modules'))