فهرست منبع

wxGUI: do not allow to run commands which tries to read stdin

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@48444 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 13 سال پیش
والد
کامیت
b3effb3bd8
2فایلهای تغییر یافته به همراه27 افزوده شده و 10 حذف شده
  1. 21 9
      gui/wxpython/gui_modules/goutput.py
  2. 6 1
      gui/wxpython/gui_modules/menuform.py

+ 21 - 9
gui/wxpython/gui_modules/goutput.py

@@ -442,10 +442,13 @@ class GMConsole(wx.SplitterWindow):
         @param compReg True use computation region
         @param switchPage switch to output page
         @param onDone function to be called when command is finished
+
+        @return 0 on success
+        @return 1 on failure
         """
         if len(command) == 0:
             Debug.msg(2, "GPrompt:RunCmd(): empty command")
-            return
+            return 0
         
         # update history file
         env = grass.gisenv()
@@ -501,7 +504,7 @@ class GMConsole(wx.SplitterWindow):
                     gcmd.GMessage(parent = self.parent,
                                   message = _("Command '%s' not yet implemented in the WxGUI. "
                                               "Try adding it as a command layer instead.") % command[0])
-                    return None
+                    return 1
                 
                 if layertype == 'barscale':
                     self.parent.curr_page.maptree.GetMapDisplay().OnAddBarscale(None)
@@ -518,6 +521,21 @@ class GMConsole(wx.SplitterWindow):
             
             else:
                 # other GRASS commands (r|v|g|...)
+                # check for <input>=-
+                # gtask.parse_command() is probably overkill here, use brute force instead
+                for opt in command[1:]:
+                    if opt[0] == '-':
+                        # skip flags
+                        continue
+                    key, value = map(lambda x: x.strip(), opt.split('=', 1))
+                    if value == '-':
+                        gcmd.GError(parent = self,
+                                    message = _("Unable to run command:\n%(cmd)s\n\n"
+                                                "Option <%(opt)s>: read from standard input is not "
+                                                "supported by wxGUI") % { 'cmd': ' '.join(command),
+                                                                          'opt': key })
+                        return 1
+                
                 # switch to 'Command output' if required
                 if switchPage:
                     self._notebook.SetSelectionByName('output')
@@ -533,10 +551,7 @@ class GMConsole(wx.SplitterWindow):
                         del os.environ["GRASS_REGION"]
                 
                 if len(command) == 1:
-                    import menuform
                     task = gtask.parse_interface(command[0])
-                    # if not task.has_required():
-                    # task = None # run command
                 else:
                     task = None
                 
@@ -548,8 +563,6 @@ class GMConsole(wx.SplitterWindow):
                     self.cmdThread.RunCmd(command, stdout = self.cmdStdOut, stderr = self.cmdStrErr,
                                           onDone = onDone)
                     self.cmdOutputTimer.Start(50)
-                    
-                    return None
                 
                 # deactivate computational region and return to display settings
                 if compReg and tmpreg:
@@ -558,7 +571,6 @@ class GMConsole(wx.SplitterWindow):
             # Send any other command to the shell. Send output to
             # console output window
             if len(command) == 1:
-                import menuform
                 try:
                     task = gtask.parse_interface(command[0])
                 except:
@@ -574,7 +586,7 @@ class GMConsole(wx.SplitterWindow):
                                       onDone = onDone)
             self.cmdOutputTimer.Start(50)
         
-        return None
+        return 0
 
     def ClearHistory(self, event):
         """!Clear history of commands"""

+ 6 - 1
gui/wxpython/gui_modules/menuform.py

@@ -688,6 +688,7 @@ class mainFrame(wx.Frame):
         if not cmd or len(cmd) < 1:
             return
         
+        ret = 0
         if self.standalone or cmd[0][0:2] !=  "d.":
             # Send any non-display command to parent window (probably wxgui.py)
             # put to parents switch to 'Command output'
@@ -697,13 +698,17 @@ class mainFrame(wx.Frame):
                 if self.task.path:
                     cmd[0] = self.task.path # full path
                 
-                self.goutput.RunCmd(cmd, onDone = self.OnDone)
+                ret = self.goutput.RunCmd(cmd, onDone = self.OnDone)
             except AttributeError, e:
                 print >> sys.stderr, "%s: Probably not running in wxgui.py session?" % (e)
                 print >> sys.stderr, "parent window is: %s" % (str(self.parent))
         else:
             gcmd.Command(cmd)
         
+        if ret != 0:
+            self.notebookpanel.notebook.SetSelection(0)
+            return
+        
         # update buttons status
         for btn in (self.btn_run,
                     self.btn_cancel,