Просмотр исходного кода

wxGUI: improve OnRunScript - check permission and GRASS_ADDON_PATH

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@49915 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 13 лет назад
Родитель
Сommit
923c2a8013

+ 2 - 2
gui/wxpython/gcp/manager.py

@@ -947,7 +947,7 @@ class GCP(MapFrame, ColumnSorterMixin):
 
 
         if self.list.GetItemCount() <= minNumOfItems:
         if self.list.GetItemCount() <= minNumOfItems:
             GMessage(parent = self,
             GMessage(parent = self,
-                     message=_("At least %d GCPs required. Operation cancelled.") % minNumOfItems)
+                     message=_("At least %d GCPs required. Operation canceled.") % minNumOfItems)
             return
             return
 
 
         key = self.list.DeleteGCPItem()
         key = self.list.DeleteGCPItem()
@@ -2071,7 +2071,7 @@ class GCPList(wx.ListCtrl,
             
             
             if len(values) == 0:
             if len(values) == 0:
                 GError(parent = self,
                 GError(parent = self,
-                       message=_("Invalid coordinate value. Operation cancelled."))
+                       message=_("Invalid coordinate value. Operation canceled."))
             else:
             else:
                 for i in range(len(values)):
                 for i in range(len(values)):
                     if values[i] != coords[i]:
                     if values[i] != coords[i]:

+ 4 - 4
gui/wxpython/iclass/frame.py

@@ -633,7 +633,7 @@ class IClassMapFrame(DoubleMapFrame):
         if not group:
         if not group:
             GMessage(parent = self,
             GMessage(parent = self,
                      message = _("No imagery group selected. "
                      message = _("No imagery group selected. "
-                                 "Operation cancelled."))
+                                 "Operation canceled."))
             return False
             return False
             
             
         groupLayers = self.GetGroupLayers(group)
         groupLayers = self.GetGroupLayers(group)
@@ -642,7 +642,7 @@ class IClassMapFrame(DoubleMapFrame):
         if nLayers <= 1:
         if nLayers <= 1:
             GMessage(parent = self,
             GMessage(parent = self,
                      message = _("Group <%s> does not have enough files "
                      message = _("Group <%s> does not have enough files "
-                                 "(it has %d files). Operation cancelled.") % (group, nLayers))
+                                 "(it has %d files). Operation canceled.") % (group, nLayers))
             return False
             return False
         
         
         #check if vector has any areas
         #check if vector has any areas
@@ -652,7 +652,7 @@ class IClassMapFrame(DoubleMapFrame):
         if numAreas <= 0:
         if numAreas <= 0:
             GMessage(parent = self,
             GMessage(parent = self,
             message = _("No areas given. "
             message = _("No areas given. "
-                        "Operation cancelled."))
+                        "Operation canceled."))
             return False
             return False
             
             
         # check if vector is inside raster
         # check if vector is inside raster
@@ -664,7 +664,7 @@ class IClassMapFrame(DoubleMapFrame):
            vectorInfo['west'] < rasterInfo['west']:
            vectorInfo['west'] < rasterInfo['west']:
            GMessage(parent = self,
            GMessage(parent = self,
                     message = _("Vector features are outside raster layers. "
                     message = _("Vector features are outside raster layers. "
-                                "Operation cancelled."))
+                                "Operation canceled."))
            return False
            return False
             
             
         return True
         return True

+ 41 - 3
gui/wxpython/lmgr/frame.py

@@ -21,6 +21,7 @@ This program is free software under the GNU General Public License
 import sys
 import sys
 import os
 import os
 import tempfile
 import tempfile
+import stat
 try:
 try:
     import xml.etree.ElementTree as etree
     import xml.etree.ElementTree as etree
 except ImportError:
 except ImportError:
@@ -579,12 +580,49 @@ class GMFrame(wx.Frame):
         
         
         if not filename:
         if not filename:
             return False
             return False
-
+        
         if not os.path.exists(filename):
         if not os.path.exists(filename):
             GError(parent = self,
             GError(parent = self,
                    message = _("Script file '%s' doesn't exist. "
                    message = _("Script file '%s' doesn't exist. "
-                               "Operation cancelled.") % filename)
+                               "Operation canceled.") % filename)
             return
             return
+
+        # check permission
+        if not os.access(filename, os.X_OK):
+            dlg = wx.MessageDialog(self,
+                                   message = _("Script <%s> is not executable. "
+                                               "Do you want to set the permissions "
+                                               "that allows you to run this script "
+                                               "(note that you must be the owner of the file)?" % \
+                                                   os.path.basename(filename)),
+                                   caption = _("Set permission?"),
+                                   style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
+            if dlg.ShowModal() != wx.ID_YES:
+                return
+            dlg.Destroy()
+            try:
+                mode = stat.S_IMODE(os.lstat(filename)[stat.ST_MODE])
+                os.chmod(filename, mode | stat.S_IXUSR)
+            except OSError:
+                GError(_("Unable to set permission. Operation canceled."), parent = self)
+                return
+        
+        # check GRASS_ADDON_PATH
+        addonPath = os.getenv('GRASS_ADDON_PATH', [])
+        if addonPath:
+            addonPath = addonPath.split(os.pathsep)
+        dirName = os.path.dirname(filename)
+        if dirName not in addonPath:
+            addonPath.append(dirName)
+            dlg = wx.MessageDialog(self,
+                                   message = _("Directory '%s' is not defined in GRASS_ADDON_PATH. "
+                                               "Do you want add this directory to GRASS_ADDON_PATH?") % \
+                                       dirName,
+                                   caption = _("Update Addons path?"),
+                                   style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
+            if dlg.ShowModal() == wx.ID_YES:
+                os.environ['GRASS_ADDON_PATH'] = os.pathsep.join(addonPath)
+                RunCommand('g.gisenv', set = 'ADDON_PATH=%s' % os.environ['GRASS_ADDON_PATH'])
         
         
         self.goutput.WriteCmdLog(_("Launching script '%s'...") % filename)
         self.goutput.WriteCmdLog(_("Launching script '%s'...") % filename)
         self.goutput.RunCmd([filename], switchPage = True)
         self.goutput.RunCmd([filename], switchPage = True)
@@ -1645,6 +1683,6 @@ class GMFrame(wx.Frame):
     def MsgNoLayerSelected(self):
     def MsgNoLayerSelected(self):
         """!Show dialog message 'No layer selected'"""
         """!Show dialog message 'No layer selected'"""
         wx.MessageBox(parent = self,
         wx.MessageBox(parent = self,
-                      message = _("No map layer selected. Operation cancelled."),
+                      message = _("No map layer selected. Operation canceled."),
                       caption = _("Message"),
                       caption = _("Message"),
                       style = wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
                       style = wx.OK | wx.ICON_INFORMATION | wx.CENTRE)

+ 1 - 1
gui/wxpython/location_wizard/wizard.py

@@ -1816,7 +1816,7 @@ class LocationWizard(wx.Object):
                                           "Details: %(err)s") % \
                                           "Details: %(err)s") % \
                            { 'loc' : self.startpage.location,
                            { 'loc' : self.startpage.location,
                              'err' : msg })
                              'err' : msg })
-        else: # -> cancelled
+        else: # -> canceled
             self.wizard.Destroy()
             self.wizard.Destroy()
             GMessage(parent = self.parent,
             GMessage(parent = self.parent,
                      message = _("Location wizard canceled. "
                      message = _("Location wizard canceled. "

+ 1 - 1
gui/wxpython/modules/vclean.py

@@ -461,7 +461,7 @@ class VectorCleaningFrame(wx.Frame):
                 err.append(_("'%s' not defined") % name)
                 err.append(_("'%s' not defined") % name)
         if err:
         if err:
             GError(_("Some parameters not defined. Operation "
             GError(_("Some parameters not defined. Operation "
-                     "cancelled.\n\n%s") % '\n'.join(err),
+                     "canceled.\n\n%s") % '\n'.join(err),
                    parent = self)
                    parent = self)
             return
             return
         
         

+ 9 - 9
gui/wxpython/vdigit/wxdigit.py

@@ -55,7 +55,7 @@ class VDigitError:
             message = _('Unable to open vector map <%s>.') % name
             message = _('Unable to open vector map <%s>.') % name
         else:
         else:
             message =  _('No vector map open for editing.')
             message =  _('No vector map open for editing.')
-        GError(message + ' ' + _('Operation cancelled.'),
+        GError(message + ' ' + _('Operation canceled.'),
                parent  = self.parent,
                parent  = self.parent,
                caption = self.caption)
                caption = self.caption)
 
 
@@ -63,7 +63,7 @@ class VDigitError:
         """!Writing line failed
         """!Writing line failed
         """
         """
         GError(message = _('Writing new feature failed. '
         GError(message = _('Writing new feature failed. '
-                           'Operation cancelled.\n\n'
+                           'Operation canceled.\n\n'
                            'Reason: %s') % GetLastError(),
                            'Reason: %s') % GetLastError(),
                parent  = self.parent,
                parent  = self.parent,
                caption = self.caption)
                caption = self.caption)
@@ -72,7 +72,7 @@ class VDigitError:
         """!Reading line failed
         """!Reading line failed
         """
         """
         GError(message = _('Reading feature id %d failed. '
         GError(message = _('Reading feature id %d failed. '
-                           'Operation cancelled.') % line,
+                           'Operation canceled.') % line,
                parent  = self.parent,
                parent  = self.parent,
                caption = self.caption)
                caption = self.caption)
 
 
@@ -80,7 +80,7 @@ class VDigitError:
         """!No dblink available
         """!No dblink available
         """
         """
         GError(message = _('Database link %d not available. '
         GError(message = _('Database link %d not available. '
-                           'Operation cancelled.') % dblink,
+                           'Operation canceled.') % dblink,
                parent  = self.parent,
                parent  = self.parent,
                caption = self.caption)
                caption = self.caption)
 
 
@@ -88,7 +88,7 @@ class VDigitError:
         """!Staring driver failed
         """!Staring driver failed
         """
         """
         GError(message = _('Unable to start database driver <%s>. '
         GError(message = _('Unable to start database driver <%s>. '
-                           'Operation cancelled.') % driver,
+                           'Operation canceled.') % driver,
                parent  = self.parent,
                parent  = self.parent,
                caption = self.caption)
                caption = self.caption)
 
 
@@ -96,7 +96,7 @@ class VDigitError:
         """!Opening database failed
         """!Opening database failed
         """
         """
         GError(message = _('Unable to open database <%(db)s> by driver <%(driver)s>. '
         GError(message = _('Unable to open database <%(db)s> by driver <%(driver)s>. '
-                           'Operation cancelled.') % { 'db' : database, 'driver' : driver},
+                           'Operation canceled.') % { 'db' : database, 'driver' : driver},
                parent  = self.parent,
                parent  = self.parent,
                caption = self.caption)
                caption = self.caption)
 
 
@@ -104,7 +104,7 @@ class VDigitError:
         """!Sql query failed
         """!Sql query failed
         """
         """
         GError(message = _("Unable to execute SQL query '%s'. "
         GError(message = _("Unable to execute SQL query '%s'. "
-                           "Operation cancelled.") % sql,
+                           "Operation canceled.") % sql,
                parent  = self.parent,
                parent  = self.parent,
                caption = self.caption)
                caption = self.caption)
 
 
@@ -112,7 +112,7 @@ class VDigitError:
         """!Dead line
         """!Dead line
         """
         """
         GError(message = _("Feature id %d is marked as dead. "
         GError(message = _("Feature id %d is marked as dead. "
-                           "Operation cancelled.") % line,
+                           "Operation canceled.") % line,
                parent  = self.parent,
                parent  = self.parent,
                caption = self.caption)
                caption = self.caption)
 
 
@@ -120,7 +120,7 @@ class VDigitError:
         """!Unknown feature type
         """!Unknown feature type
         """
         """
         GError(message = _("Unsupported feature type %d. "
         GError(message = _("Unsupported feature type %d. "
-                           "Operation cancelled.") % ftype,
+                           "Operation canceled.") % ftype,
                parent  = self.parent,
                parent  = self.parent,
                caption = self.caption)
                caption = self.caption)
         
         

+ 1 - 1
gui/wxpython/xml/menudata.xml

@@ -895,7 +895,7 @@
 	      <help>Rebuilds all locally installed GRASS Addons extensions.</help>
 	      <help>Rebuilds all locally installed GRASS Addons extensions.</help>
 	      <keywords>general,installation,extensions</keywords>
 	      <keywords>general,installation,extensions</keywords>
 	      <handler>OnMenuCmd</handler>
 	      <handler>OnMenuCmd</handler>
-	      <command>g.extension.rebuild.all</command>
+	      <command>g.extension.rebuild.all.py</command>
 	    </menuitem>
 	    </menuitem>
 	    <menuitem>
 	    <menuitem>
 	      <label>Remove extension</label>
 	      <label>Remove extension</label>