[GRASS-SVN] r38264 - grass/trunk/scripts/g.extension

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jul 5 14:37:19 EDT 2009


Author: martinl
Date: 2009-07-05 14:37:19 -0400 (Sun, 05 Jul 2009)
New Revision: 38264

Modified:
   grass/trunk/scripts/g.extension/g.extension.html
   grass/trunk/scripts/g.extension/g.extension.py
Log:
+ prefix and operation paramaters add
very simple uninstall method


Modified: grass/trunk/scripts/g.extension/g.extension.html
===================================================================
--- grass/trunk/scripts/g.extension/g.extension.html	2009-07-05 18:09:29 UTC (rev 38263)
+++ grass/trunk/scripts/g.extension/g.extension.html	2009-07-05 18:37:19 UTC (rev 38264)
@@ -1,22 +1,24 @@
 <h2>DESCRIPTION</h2>
 
-<em>g.extension.add</em> downloads and installs extensions from 
-GRASS Addons SVN repository into the local GRASS installation.
+<em>g.extension</em> downloads and installs, removes or updates
+extensions from GRASS Addons SVN repository into the local GRASS
+installation.
 
 <p>
-Re-running the script on an installed GRASS Addon re-installs
+Re-running the script on an installed GRASS Addons re-installs
 the requested extension which may include updates.
 
 <h2>EXAMPLES</h2>
 
 Download and install i.landsat.toar into current GRASS installation:
+
 <div class="code"><pre>
-  g.extension.add extension=i.landsat.toar
+  g.extension extension=i.landsat.toar operation=add
 </pre></div>
 
 <h2>AUTHOR</h2>
 
 Markus Neteler<br>
-Upgraded for GRASS 7 by Martin Landa
+Upgraded for GRASS 7 by Martin Landa, CTU in Prague, Czech Republic
 
 <p><i>Last changed: $Date$</i>

Modified: grass/trunk/scripts/g.extension/g.extension.py
===================================================================
--- grass/trunk/scripts/g.extension/g.extension.py	2009-07-05 18:09:29 UTC (rev 38263)
+++ grass/trunk/scripts/g.extension/g.extension.py	2009-07-05 18:37:19 UTC (rev 38264)
@@ -17,18 +17,36 @@
 #       $GISBASE directory)
 #############################################################################
 
-#%Module
-#%  description: Tool to download and install extensions from GRASS Addons SVN repository into local GRASS installation.
-#%  keywords: installation, extensions
-#%End
+#%module
+#% label: Tool to maintain GRASS extensions in local GRASS installation.
+#% description: Downloads, installs extensions from GRASS Addons SVN repository into local GRASS installation or removes installed extensions.
+#% keywords: installation, extensions
+#%end
 
 #%option
 #% key: extension
 #% type: string
-#% key_desc : name
-#% description: Name of extension to install from GRASS Addons SVN repository
-#% required : no
+#% key_desc: name
+#% description: Name of extension to install/remove
+#% required: no
 #%end
+#%option
+#% key: operation
+#% type: string
+#% key_desc: name
+#% description: Operation to be performed
+#% required: no
+#% options: add,remove
+#% answer: add
+#%end
+#%option
+#% key: prefix
+#% type: string
+#% key_desc: path
+#% description: Prefix where to install extension (default: GISBASE)
+#% required: no
+#%end
+
 #%flag
 #%  key: l
 #%  description: List available modules in the GRASS Addons SVN repository
@@ -96,26 +114,14 @@
     global tmpdir
     grass.try_rmdir(tmpdir)
 
-def main():
-    # check dependecies
-    check()
-
-    # list available modules
-    if flags['l']:
-        list_available_modules()
-        return 0
-    else:
-        if not options['extension']:
-            grass.fatal('You need to define an extension name or use -l')
-    
-    module = options['extension']
+def install_extension(gisbase, module):
     classchar = module.split('.', 1)[0]
     moduleclass = expand_module_class_name(classchar)
     global svnurl_addons
     url = svnurl_addons + moduleclass + '/' + module
+        
+    grass.message("Fetching '%s' from GRASS-Addons SVN (be patient)..." % module)
     global tmpdir
-    print tmpdir
-    grass.message("Fetching '%s' from GRASS-Addons SVN (be patient)..." % module)
     os.chdir(tmpdir)
     if grass.call(['svn', 'checkout',
                    url]) != 0:
@@ -123,10 +129,8 @@
 
     os.chdir(os.path.join(tmpdir, module))
     grass.message("Compiling '%s'..." % module)
-    gisbase = os.getenv('GISBASE')
     if grass.call(['make',
                    'MODULE_TOPDIR=%s' % gisbase]) != 0:
-        cleanup()
         grass.fatal('Compilation failed, sorry. Please check above error messages')
     
     grass.message("Installing '%s'..." % module)
@@ -147,12 +151,46 @@
                           'install'])
     
     if ret != 0:
-        cleanup()
         grass.fatal('Installation failed, sorry. Please check above error messages.')
     
     grass.message("Installation of '%s' successfully finished." % module)
-    cleanup()
+
+def remove_extension(gisbase, module):
+    # is module available?
+    if not grass.find_program(module):
+        grass.fatal("'%s' not found" % module)
     
+    for file in [os.path.join(gisbase, 'bin', module),
+                 os.path.join(gisbase, 'scripts', module),
+                 os.path.join(gisbase, 'docs', 'html', module + '.html')]:
+        if os.path.isfile(file):
+            os.remove(file)
+                    
+    grass.message("'%s' successfully removed." % module)
+    
+def main():
+    # check dependecies
+    check()
+
+    # list available modules
+    if flags['l']:
+        list_available_modules()
+        return 0
+    else:
+        if not options['extension']:
+            grass.fatal('You need to define an extension name or use -l')
+    
+    module = options['extension']
+    if options['prefix']:
+        gisbase = options['prefix']
+    else:
+        gisbase = os.getenv('GISBASE')
+
+    if options['operation'] == 'add':
+        install_extension(gisbase, module)
+    else: # remove
+        remove_extension(gisbase, module)
+        
     return 0
 
 if __name__ == "__main__":



More information about the grass-commit mailing list