Changeset 30501


Ignore:
Timestamp:
Mar 7, 2008, 3:56:14 PM (16 years ago)
Author:
martinl
Message:

wxGUI (gcmd) MS Windows related fixes

Location:
grass/trunk/gui/wxpython/gui_modules
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • grass/trunk/gui/wxpython/gui_modules/gcmd.py

    r30486 r30501  
    77 * GException
    88 * DigitError
    9  * Popen
     9 * Popen (from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440554)
    1010 * Command
    1111 * CommandThread
     
    128128    def kill(self):
    129129        """Try to kill running process"""
    130         try:
     130        if subprocess.mswindows:
     131            import win32api
     132            handle = win32api.OpenProcess(1, 0, self.pid)
     133            return (0 != win32api.TerminateProcess(handle, 0))
     134        else:
    131135            os.kill(-self.pid, signal.SIGTERM) # kill whole group
    132         except OSError:
    133             pass
    134136
    135137    if subprocess.mswindows:
     
    213215                if not conn.closed:
    214216                    fcntl.fcntl(conn, fcntl.F_SETFL, flags)
     217
     218message = "Other end disconnected!"
     219
     220def recv_some(p, t=.1, e=1, tr=5, stderr=0):
     221    if tr < 1:
     222        tr = 1
     223    x = time.time()+t
     224    y = []
     225    r = ''
     226    pr = p.recv
     227    if stderr:
     228        pr = p.recv_err
     229    while time.time() < x or r:
     230        r = pr()
     231        if r is None:
     232            if e:
     233                raise Exception(message)
     234            else:
     235                break
     236        elif r:
     237            y.append(r)
     238        else:
     239            time.sleep(max((x-time.time())/tr, 0))
     240    return ''.join(y)
     241   
     242def send_all(p, data):
     243    while len(data):
     244        sent = p.send(data)
     245        if sent is None:
     246            raise Exception(message)
     247        data = buffer(data, sent)
    215248
    216249# Define notification event for thread completion
     
    529562                return
    530563            if self.stdout:
    531                 line = self.__read_all(self.module.stdout)
     564                # line = self.__read_all(self.module.stdout)
     565                line = recv_some(self.module, e=0, stderr=0)
    532566                self.stdout.write(line)
    533567            if self.stderr:
    534                 line = self.__read_all(self.module.stderr)
     568                # line = self.__read_all(self.module.stderr)
     569                line = recv_some(self.module, e=0, stderr=1)
    535570                self.stderr.write(line)
    536571
    537572        # get the last output
    538573        if self.stdout:
    539             line = self.__read_all(self.module.stdout)
     574            # line = self.__read_all(self.module.stdout)
     575            line = recv_some(self.module, e=0, stderr=0)
    540576            self.stdout.write(line)
    541577        if self.stderr:
    542             line = self.__read_all(self.module.stderr)
     578            # line = self.__read_all(self.module.stderr)
     579            line = recv_some(self.module, e=0, stderr=1)
    543580            self.stderr.write(line)
    544581
  • grass/trunk/gui/wxpython/gui_modules/globalvar.py

    r30419 r30501  
    6363    parsing string from the command line
    6464    """
    65     gcmdlst = []
    6665    gisbase = os.environ['GISBASE']
     66    binlst = []
    6767    if bin is True:
    68         gcmdlst = os.listdir(os.path.join(gisbase, 'bin'))
     68        binlst = os.listdir(os.path.join(gisbase, 'bin'))
     69        if subprocess.mswindows:
     70            for idx in range(len(binlst)):
     71                binlst[idx] = binlst[idx].replace(EXT_BIN, '')
     72                binlst[idx] = binlst[idx].replace(EXT_SCT, '')
     73    sctlst = []
    6974    if scripts is True:
    70         gcmdlst = gcmdlst + os.listdir(os.path.join(gisbase, 'scripts'))
     75        sctlst = sctlst + os.listdir(os.path.join(gisbase, 'scripts'))
     76        if subprocess.mswindows:
     77            for idx in range(len(binlst)):
     78                binlst[idx] = binlst[idx].replace(EXT_BIN, '')
     79                binlst[idx] = binlst[idx].replace(EXT_SCT, '')
     80
    7181    # self.gcmdlst = self.gcmdlst + os.listdir(os.path.join(gisbase,'etc','gm','script'))
    7282
    73     return gcmdlst
     83    return binlst + sctlst
    7484
    7585"""@brief Collected GRASS-relared binaries/scripts"""
Note: See TracChangeset for help on using the changeset viewer.