[GRASS-SVN] r74379 - grass/trunk/scripts/g.search.modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Apr 15 04:27:42 PDT 2019
Author: neteler
Date: 2019-04-15 04:27:42 -0700 (Mon, 15 Apr 2019)
New Revision: 74379
Modified:
grass/trunk/scripts/g.search.modules/g.search.modules.html
grass/trunk/scripts/g.search.modules/g.search.modules.py
Log:
g.search.modules: support for addons added (fixes 3583, contributed by AnikaBettge)
Modified: grass/trunk/scripts/g.search.modules/g.search.modules.html
===================================================================
--- grass/trunk/scripts/g.search.modules/g.search.modules.html 2019-04-15 02:52:20 UTC (rev 74378)
+++ grass/trunk/scripts/g.search.modules/g.search.modules.html 2019-04-15 11:27:42 UTC (rev 74379)
@@ -1,15 +1,18 @@
<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>
-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>
-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>
g.search.modules keyword=buffer,clip
@@ -30,17 +33,28 @@
that contain non-NULL category values.
</pre></div>
+<p>
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>
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
- 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>
-Search in manual pages too
+<p>
+Search in manual pages as well:
+
<div class="code"><pre>
g.search.modules -m keyword=kapri
@@ -64,7 +78,9 @@
<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>
<i>Last changed: $Date$</i>
Modified: grass/trunk/scripts/g.search.modules/g.search.modules.py
===================================================================
--- grass/trunk/scripts/g.search.modules/g.search.modules.py 2019-04-15 02:52:20 UTC (rev 74378)
+++ grass/trunk/scripts/g.search.modules/g.search.modules.py 2019-04-15 11:27:42 UTC (rev 74379)
@@ -61,6 +61,7 @@
#% description: JSON format
#% guisection: Output
#%end
+
from __future__ import print_function
import os
import sys
@@ -198,6 +199,15 @@
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 = []
for item in items:
name = item.attrib['name']
@@ -246,7 +256,7 @@
}
})
- return found_modules
+ return sorted(found_modules, key=lambda k: k['name'])
def _basic_search(pattern, name, description, module_keywords):
@@ -255,11 +265,13 @@
This lowercases the strings before searching in them, so the pattern
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:
return False
@@ -283,6 +295,7 @@
return manpage.lower().find(pattern) > -1
+
if __name__ == "__main__":
options, flags = grass.parser()
sys.exit(main())
More information about the grass-commit
mailing list