浏览代码

g.search.modules: support for addons added (fixes 3583, contributed by AnikaBettge)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@74379 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Neteler 6 年之前
父节点
当前提交
6e70c16eef
共有 2 个文件被更改,包括 44 次插入15 次删除
  1. 25 9
      scripts/g.search.modules/g.search.modules.html
  2. 19 6
      scripts/g.search.modules/g.search.modules.py

+ 25 - 9
scripts/g.search.modules/g.search.modules.html

@@ -1,15 +1,18 @@
 <h2>DESCRIPTION</h2>
 <h2>DESCRIPTION</h2>
 
 
-<em>g.search.module</em> searches for given keyword in GRASS modules name,
-description, keywords and optionally manpages too.
+<em>g.search.module</em> searches for given keyword in GRASS GIS modules name,
+description, keywords and optionally manpages, too. Also installed addons are
+considered in the search.
 
 
 <h2>NOTES</h2>
 <h2>NOTES</h2>
 
 
-There can be more keywords, <em>g.search.modules</em> will search for each of them
+Multiple keywords may be specified, <em>g.search.modules</em> will search for
+all of them.
 
 
 <h2>EXAMPLE</h2>
 <h2>EXAMPLE</h2>
 
 
-Search all modules, where keywords <em>buffer</em> OR <em>clip</em> can be found
+Search all modules, where keywords <em>buffer</em> OR <em>clip</em> can be found:
+
 <div class="code"><pre>
 <div class="code"><pre>
 g.search.modules keyword=buffer,clip
 g.search.modules keyword=buffer,clip
 
 
@@ -30,17 +33,28 @@ r.buffer
                  that contain non-NULL category values.
                  that contain non-NULL category values.
 </pre></div>
 </pre></div>
 
 
+<p>
 Search all modules, where keywords <em>overlay</em> AND <em>clip</em> can be
 Search all modules, where keywords <em>overlay</em> AND <em>clip</em> can be
-found with some fancy terminal output
+found with some fancy terminal output (not shown here):
+
 <div class="code"><pre>
 <div class="code"><pre>
 g.search.modules keyword=clip,overlay -a -c
 g.search.modules keyword=clip,overlay -a -c
 
 
+v.clip
+    keywords: vector,clip,area
+    description: Extracts features of input map which overlay features
+                 of clip map.
+
 v.overlay
 v.overlay
-    keywords: vector,geometry,spatial query,intersection,union,clip
-    description: Overlays two vector maps.;
+    keywords: vector,geometry,spatial
+              query,clip,difference,intersection,union
+    description: Overlays two vector maps offering clip, intersection,
+                 difference, symmetrical difference, union operators.
 </pre></div>
 </pre></div>
 
 
-Search in manual pages too 
+<p>
+Search in manual pages as well:
+
 <div class="code"><pre>
 <div class="code"><pre>
 g.search.modules -m keyword=kapri
 g.search.modules -m keyword=kapri
 
 
@@ -64,7 +78,9 @@ db.select
 
 
 <h2>AUTHORS</h2>
 <h2>AUTHORS</h2>
 
 
-Jachym Cepicky, OpenGeoLabs s.r.o., Czech Republic
+Jachym Cepicky, OpenGeoLabs s.r.o., Czech Republic: original author
+<br>
+Anika Bettge, mundialis, Germany: addon search added
 
 
 <p>
 <p>
 <i>Last changed: $Date$</i>
 <i>Last changed: $Date$</i>

+ 19 - 6
scripts/g.search.modules/g.search.modules.py

@@ -61,6 +61,7 @@
 #% description: JSON format
 #% description: JSON format
 #% guisection: Output
 #% guisection: Output
 #%end
 #%end
+
 from __future__ import print_function
 from __future__ import print_function
 import os
 import os
 import sys
 import sys
@@ -198,6 +199,15 @@ def _search_module(keywords, logical_and=False, invert=False, manpages=False,
 
 
     items = menudata.findall('module-item')
     items = menudata.findall('module-item')
 
 
+    # add installed addons to modules list
+    if os.getenv("GRASS_ADDON_BASE"):
+        filename_addons = os.path.join(os.getenv("GRASS_ADDON_BASE"), 'modules.xml')
+        addon_menudata_file = open(filename_addons, 'r')
+        addon_menudata = etree.parse(addon_menudata_file)
+        addon_menudata_file.close()
+        addon_items = addon_menudata.findall('task')
+        items.extend(addon_items)
+
     found_modules = []
     found_modules = []
     for item in items:
     for item in items:
         name = item.attrib['name']
         name = item.attrib['name']
@@ -246,7 +256,7 @@ def _search_module(keywords, logical_and=False, invert=False, manpages=False,
                 }
                 }
             })
             })
 
 
-    return found_modules
+    return sorted(found_modules, key=lambda k: k['name'])
 
 
 
 
 def _basic_search(pattern, name, description, module_keywords):
 def _basic_search(pattern, name, description, module_keywords):
@@ -255,11 +265,13 @@ def _basic_search(pattern, name, description, module_keywords):
     This lowercases the strings before searching in them, so the pattern
     This lowercases the strings before searching in them, so the pattern
     string should be lowercased too.
     string should be lowercased too.
     """
     """
-    if name.lower().find(pattern) > -1 or\
-       description.lower().find(pattern) > -1 or\
-       module_keywords.lower().find(pattern) > -1:
-
-        return True
+    if (name and description and module_keywords):
+        if name.lower().find(pattern) > -1 or\
+           description.lower().find(pattern) > -1 or\
+           module_keywords.lower().find(pattern) > -1:
+           return True
+        else:
+            return False
     else:
     else:
         return False
         return False
 
 
@@ -283,6 +295,7 @@ def _manpage_search(pattern, name):
 
 
     return manpage.lower().find(pattern) > -1
     return manpage.lower().find(pattern) > -1
 
 
+
 if __name__ == "__main__":
 if __name__ == "__main__":
     options, flags = grass.parser()
     options, flags = grass.parser()
     sys.exit(main())
     sys.exit(main())