[GRASS-SVN] r30501 - grass/trunk/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Mar 7 18:56:14 EST 2008
Author: martinl
Date: 2008-03-07 18:56:14 -0500 (Fri, 07 Mar 2008)
New Revision: 30501
Modified:
grass/trunk/gui/wxpython/gui_modules/gcmd.py
grass/trunk/gui/wxpython/gui_modules/globalvar.py
Log:
wxGUI (gcmd) MS Windows related fixes
Modified: grass/trunk/gui/wxpython/gui_modules/gcmd.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gcmd.py 2008-03-07 17:53:58 UTC (rev 30500)
+++ grass/trunk/gui/wxpython/gui_modules/gcmd.py 2008-03-07 23:56:14 UTC (rev 30501)
@@ -6,7 +6,7 @@
Classes:
* GException
* DigitError
- * Popen
+ * Popen (from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440554)
* Command
* CommandThread
@@ -127,10 +127,12 @@
def kill(self):
"""Try to kill running process"""
- try:
+ if subprocess.mswindows:
+ import win32api
+ handle = win32api.OpenProcess(1, 0, self.pid)
+ return (0 != win32api.TerminateProcess(handle, 0))
+ else:
os.kill(-self.pid, signal.SIGTERM) # kill whole group
- except OSError:
- pass
if subprocess.mswindows:
def send(self, input):
@@ -213,6 +215,37 @@
if not conn.closed:
fcntl.fcntl(conn, fcntl.F_SETFL, flags)
+message = "Other end disconnected!"
+
+def recv_some(p, t=.1, e=1, tr=5, stderr=0):
+ if tr < 1:
+ tr = 1
+ x = time.time()+t
+ y = []
+ r = ''
+ pr = p.recv
+ if stderr:
+ pr = p.recv_err
+ while time.time() < x or r:
+ r = pr()
+ if r is None:
+ if e:
+ raise Exception(message)
+ else:
+ break
+ elif r:
+ y.append(r)
+ else:
+ time.sleep(max((x-time.time())/tr, 0))
+ return ''.join(y)
+
+def send_all(p, data):
+ while len(data):
+ sent = p.send(data)
+ if sent is None:
+ raise Exception(message)
+ data = buffer(data, sent)
+
# Define notification event for thread completion
EVT_RESULT_ID = wx.NewId()
@@ -528,18 +561,22 @@
wx.PostEvent(self.stderr.gmstc.parent, ResultEvent(None))
return
if self.stdout:
- line = self.__read_all(self.module.stdout)
+ # line = self.__read_all(self.module.stdout)
+ line = recv_some(self.module, e=0, stderr=0)
self.stdout.write(line)
if self.stderr:
- line = self.__read_all(self.module.stderr)
+ # line = self.__read_all(self.module.stderr)
+ line = recv_some(self.module, e=0, stderr=1)
self.stderr.write(line)
# get the last output
if self.stdout:
- line = self.__read_all(self.module.stdout)
+ # line = self.__read_all(self.module.stdout)
+ line = recv_some(self.module, e=0, stderr=0)
self.stdout.write(line)
if self.stderr:
- line = self.__read_all(self.module.stderr)
+ # line = self.__read_all(self.module.stderr)
+ line = recv_some(self.module, e=0, stderr=1)
self.stderr.write(line)
self.rerr = self.__parseString(line)
Modified: grass/trunk/gui/wxpython/gui_modules/globalvar.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/globalvar.py 2008-03-07 17:53:58 UTC (rev 30500)
+++ grass/trunk/gui/wxpython/gui_modules/globalvar.py 2008-03-07 23:56:14 UTC (rev 30501)
@@ -62,15 +62,25 @@
Create list of all available GRASS commands to use when
parsing string from the command line
"""
- gcmdlst = []
gisbase = os.environ['GISBASE']
+ binlst = []
if bin is True:
- gcmdlst = os.listdir(os.path.join(gisbase, 'bin'))
+ binlst = os.listdir(os.path.join(gisbase, 'bin'))
+ if subprocess.mswindows:
+ for idx in range(len(binlst)):
+ binlst[idx] = binlst[idx].replace(EXT_BIN, '')
+ binlst[idx] = binlst[idx].replace(EXT_SCT, '')
+ sctlst = []
if scripts is True:
- gcmdlst = gcmdlst + os.listdir(os.path.join(gisbase, 'scripts'))
+ sctlst = sctlst + os.listdir(os.path.join(gisbase, 'scripts'))
+ if subprocess.mswindows:
+ for idx in range(len(binlst)):
+ binlst[idx] = binlst[idx].replace(EXT_BIN, '')
+ binlst[idx] = binlst[idx].replace(EXT_SCT, '')
+
# self.gcmdlst = self.gcmdlst + os.listdir(os.path.join(gisbase,'etc','gm','script'))
- return gcmdlst
+ return binlst + sctlst
"""@brief Collected GRASS-relared binaries/scripts"""
grassCmd = {}
@@ -78,4 +88,4 @@
grassCmd['script'] = __getGRASSCmds(bin=False)
"""@Toolbar icon size"""
-toolbarSize = (24, 24)
\ No newline at end of file
+toolbarSize = (24, 24)
More information about the grass-commit
mailing list