[GRASS-SVN] r49273 - in grass/branches/develbranch_6/gui: scripts wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Nov 16 10:58:34 EST 2011


Author: martinl
Date: 2011-11-16 07:58:34 -0800 (Wed, 16 Nov 2011)
New Revision: 49273

Modified:
   grass/branches/develbranch_6/gui/scripts/g.extension.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/ghelp.py
Log:
wxGUI: update extension dialog
       sync g.extension.py with trunk


Modified: grass/branches/develbranch_6/gui/scripts/g.extension.py
===================================================================
--- grass/branches/develbranch_6/gui/scripts/g.extension.py	2011-11-16 15:18:35 UTC (rev 49272)
+++ grass/branches/develbranch_6/gui/scripts/g.extension.py	2011-11-16 15:58:34 UTC (rev 49273)
@@ -63,7 +63,7 @@
 #%end
 #%flag
 #% key: c
-#% description: List available modules in the GRASS Addons SVN repository including complete module description
+#% description: List available modules in the GRASS Addons SVN repository including module description
 #% guisection: Print
 #%end
 #%flag
@@ -83,10 +83,6 @@
 #% key: i
 #% description: Don't install new extension, just compile it
 #%end
-#%flag
-#% key: f
-#% description: Force removal (required for actual deletion of files)
-#%end
 
 import os
 import sys
@@ -211,10 +207,11 @@
     
     url = '%s/%s' % (options['svnurl'], 'gui/wxpython')
     grass.debug("url = %s" % url, debug = 2)
-    f = urlopen(url)
-    if not f:
-        grass.warning(_("Unable to fetch '%s'") % url)
-        return
+    try:
+        f = urlopen(url)
+    except HTTPError:
+        grass.debug("Unable to fetch '%s'" % url, debug = 1)
+        return mlist
         
     for line in f.readlines():
         # list modules
@@ -366,7 +363,7 @@
         grass.fatal(_('$GISBASE not defined'))
     
     if grass.find_program(options['extension'], ['--help']):
-        grass.warning(_("Extension '%s' already installed. Will be updated...") % options['extension'])
+        grass.warning(_("Extension <%s> already installed. Will be updated...") % options['extension'])
     
     gui_list = list_wxgui_extensions(print_module = False)
 
@@ -479,37 +476,62 @@
         grass.warning(_('This add-on module will not function until you set the '
                         'GRASS_ADDON_PATH environment variable (see "g.manual variables")'))
 
-def remove_extension(flags):
-    #is module available?
-    bin_dir = os.path.join(options['prefix'], 'bin')
-    scr_dir = os.path.join(options['prefix'], 'scripts')
-    #add glob because if install a module with several submodule like r.modis 
-    #or r.pi.* or r.stream.* it was not possible to remove all the module
-    #but the user has to remove the single command
-    if glob.glob1(bin_dir,options['extension'] + "*"):
-	modules = glob.glob1(bin_dir,options['extension'] + "*")
-    elif glob.glob1(scr_dir,options['extension'] + "*"):
-	modules = glob.glob1(scr_dir,options['extension'] + "*")
-    else:
-        grass.fatal(_("No module <%s> found") % options['extension'])
-        
-    #the user want really remove the scripts
-    if flags['f']:
-	#for each module remove script and documentation files
-	for mod in modules:
-	    for f in [os.path.join(bin_dir, mod), os.path.join(scr_dir, mod),
-		      os.path.join(options['prefix'], 'docs', 'html', mod + '.html'),
-		      os.path.join(options['prefix'], 'man', 'man1', mod + '.1')]:
-		grass.try_remove(f)
-	#add etc for the internal library of a module
-	grass.try_rmdir(os.path.join(options['prefix'], 'etc', options['extension']))
-	grass.message(_("Module <%s> successfully uninstalled") % options['extension'])
-    #print modules that you are going to remove with -f option
-    else:
-	for mod in modules:
-	    grass.message(mod)
-	grass.message(_("You must use the force flag (-%s) to actually remove them. Exiting") % "f")
+def remove_extension():
+    # try to download XML metadata file first
+    url = "http://grass.osgeo.org/addons/grass%s.xml" % grass.version()['version'].split('.')[0]
+    name = options['extension']
+    try:
+        f = urlopen(url)
+        tree = etree.fromstring(f.read())
+        flist = []
+        for task in tree.findall('task'):
+            if name == task.get('name', default = '') and \
+                    task.find('binary') is not None:
+                for f in task.find('binary').findall('file'):
+                    fname = f.text
+                    if fname:
+                        fpath = fname.split('/')
+                        if sys.platform == 'win32':
+                            if fpath[0] == 'bin':
+                                fpath[-1] += '.exe'
+                            if fpath[0] == 'scripts':
+                                fpath[-1] += '.py'
+                        
+                        flist.append(fpath)
+        if flist:
+            removed = False
+            err = list()
+            for f in flist:
+                fpath = os.path.join(options['prefix'], os.path.sep.join(f))
+                try:
+                    os.remove(fpath)
+                    removed = True
+                except OSError:
+                    err.append((_("Unable to remove file '%s'") % fpath))
+            if not removed:
+                grass.fatal(_("Extension <%s> not found") % options['extension'])
+            
+            if err:
+                for e in err:
+                    grass.error(e)
+        else:
+            remove_extension_std()
+    except HTTPError:
+        remove_extension_std()
 
+    grass.message(_("Extension <%s> successfully uninstalled.") % options['extension'])
+    
+def remove_extension_std():
+    # is module available?
+    if not os.path.exists(os.path.join(options['prefix'], 'bin', options['extension'])):
+        grass.fatal(_("Extension <%s> not found") % options['extension'])
+    
+    for file in [os.path.join(options['prefix'], 'bin', options['extension']),
+                 os.path.join(options['prefix'], 'scripts', options['extension']),
+                 os.path.join(options['prefix'], 'docs', 'html', options['extension'] + '.html')]:
+        if os.path.isfile(file):
+            os.remove(file)
+    
 def create_dir(path):
     if os.path.isdir(path):
         return
@@ -591,7 +613,7 @@
         else:
             install_extension()
     else: # remove
-        remove_extension(flags)
+        remove_extension()
     
     return 0
 

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/ghelp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/ghelp.py	2011-11-16 15:18:35 UTC (rev 49272)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/ghelp.py	2011-11-16 15:58:34 UTC (rev 49273)
@@ -813,7 +813,7 @@
         self.fullDesc.SetValue(True)
         
         self.search = SearchModuleWindow(parent = self.panel)
-        self.search.SetSelection(2) 
+        self.search.SetSelection(0) 
         
         self.tree   = ExtensionTree(parent = self.panel, log = parent.GetLogWindow())
         
@@ -829,7 +829,7 @@
                 desc = f.get('description', '')
             if not name and not desc:
                 continue
-            if name in ('l', 'f', 'g', 'quiet', 'verbose'):
+            if name in ('l', 'c', 'g', 'quiet', 'verbose'):
                 continue
             self.options[name] = wx.CheckBox(parent = self.panel, id = wx.ID_ANY,
                                              label = desc)
@@ -1011,7 +1011,7 @@
         for prefix in ('display', 'database',
                        'general', 'imagery',
                        'misc', 'postscript', 'paint',
-                       'raster', 'raster3D', 'sites', 'vector', 'wxGUI'):
+                       'raster', 'raster3D', 'sites', 'vector', 'wxGUI', 'other'):
             self.AppendItem(parentId = self.root,
                             text = prefix)
         self._loaded = False
@@ -1028,7 +1028,8 @@
                  'r3' : 'raster3D',
                  's'  : 'sites',
                  'v'  : 'vector',
-                 'wx' : 'wxGUI' }
+                 'wx' : 'wxGUI',
+                 'u'  : 'other' }
         
         if c in name:
             return name[c]
@@ -1067,7 +1068,11 @@
             if full:
                 key, value = line.split('=', 1)
                 if key == 'name':
-                    prefix, name = value.split('.', 1)
+                    try:
+                        prefix, name = value.split('.', 1)
+                    except ValueError:
+                        prefix = 'u'
+                        name = value
                     if prefix not in mdict:
                         mdict[prefix] = dict()
                     mdict[prefix][name] = dict()



More information about the grass-commit mailing list