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

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jul 25 00:36:30 PDT 2017


Author: zarch
Date: 2017-07-25 00:36:30 -0700 (Tue, 25 Jul 2017)
New Revision: 71315

Modified:
   grass/trunk/scripts/g.extension/g.extension.py
Log:
g.extension: When remove an extension remove directories in GRASS_ADDONS/etc/{name}/*

Modified: grass/trunk/scripts/g.extension/g.extension.py
===================================================================
--- grass/trunk/scripts/g.extension/g.extension.py	2017-07-25 06:12:37 UTC (rev 71314)
+++ grass/trunk/scripts/g.extension/g.extension.py	2017-07-25 07:36:30 UTC (rev 71315)
@@ -1273,15 +1273,14 @@
                 removed = False
                 err = list()
                 for fpath in flist:
-                    try:
-                        if force:
-                            grass.verbose(fpath)
+                    grass.verbose(fpath)
+                    if force:
+                        try:
+                            os.remove(fpath)
                             removed = True
-                            os.remove(fpath)
-                        else:
-                            print(fpath)
-                    except OSError:
-                        err.append((_("Unable to remove file '%s'") % fpath))
+                        except OSError:
+                            msg = "Unable to remove file '%s'"
+                            err.append((_(msg) % fpath))
                 if force and not removed:
                     grass.fatal(_("Extension <%s> not found") % name)
 
@@ -1293,7 +1292,14 @@
         else:
             remove_extension_std(name, force)
 
+    # remove module libraries directories under GRASS_ADDONS/etc/{name}/*
+    libpath = os.path.join(options['prefix'], 'etc', name)
+    if os.path.isdir(libpath):
+        grass.verbose(libpath)
+        if force:
+            shutil.rmtree(libpath)
 
+
 def remove_extension_std(name, force=False):
     """Remove extension/module expecting the standard layout"""
     for fpath in [os.path.join(options['prefix'], 'bin', name),
@@ -1305,13 +1311,18 @@
                   os.path.join(options['prefix'], 'docs', 'man', 'man1',
                                name + '.1')]:
         if os.path.isfile(fpath):
+            grass.verbose(fpath)
             if force:
-                grass.verbose(fpath)
                 os.remove(fpath)
-            else:
-                print(fpath)
 
+    # remove module libraries under GRASS_ADDONS/etc/{name}/*
+    libpath = os.path.join(options['prefix'], 'etc', name)
+    if os.path.isdir(libpath):
+        grass.verbose(libpath)
+        if force:
+            shutil.rmtree(libpath)
 
+
 def remove_from_toolbox_xml(name):
     """Update local meta-file when removing existing toolbox"""
     xml_file = os.path.join(options['prefix'], 'toolboxes.xml')



More information about the grass-commit mailing list