Пример #1
0
    def __init__(self, cmd, capturestderr=0, bufsize=-1):
        """The parameter 'cmd' is the shell command to execute in a
        sub-process.  Can be either a sequence of executable
        and arguments, or a shell command.
        The 'capturestderr' flag, if true, specifies that
        the object should capture standard error output of the child process.
        The default is false.  If the 'bufsize' parameter is specified, it
        specifies the size of the I/O buffers to/from the child process.
        """
        self.process = shellexecute(cmd)
        self._tochild = self.process.getOutputStream()
        self._fromchild = self.process.getInputStream()
        if capturestderr:
            self._childerr = self.process.getErrorStream()
        else:
            self._childerr = None
        import threading
        self.childWaiterLock = threading.Lock()

        if bufsize > 0:
            self._tochild = BufferedOutputStream(self._tochild, bufsize)
            self._fromchild = BufferedInputStream(self._fromchild, bufsize)
            if self._childerr:
                self._childerr = BufferedInputStream(self._childerr, bufsize)

        self.tochild = PyFile(self._tochild)
        self.fromchild = PyFile(self._fromchild)
        if self._childerr:
            self.childerr = PyFile(self._childerr)
Пример #2
0
 def serialEvent(self, args):
     pFile = PyFile(self.inStream)
     dataLine = pFile.readline()
     print 'datatLine = ', dataLine
     self.outFile.write(dataLine)
     self.outFile.flush()
     splitStr = self.scParser.parseData(dataLine)
     print 'after parser', splitStr
     timeStamp = self.scParser.findTimestamp(splitStr[4], splitStr[5])
     print 'timestamp = ', timeStamp
     print 'splitStr = ', splitStr[0:4]
     self.dts.insertData(timeStamp, splitStr[0:4])
 def serialEvent ( self, args):
     pFile =  PyFile (self.inStream)
     dataLine = pFile.readline()
     print 'datatLine = ', dataLine
     self.outFile.write(dataLine)
     self.outFile.flush()
     splitStr = self.scParser.parseData(dataLine)
     print 'after parser', splitStr
     timeStamp = self.scParser.findTimestamp(splitStr[4], splitStr[5])
     print 'timestamp = ', timeStamp
     print 'splitStr = ', splitStr[0:4]
     self.dts.insertData(timeStamp, splitStr[0:4])
Пример #4
0
class _ProcessFile:
    """Python file object that returns the process exit status from
    the close method.
    """
    def __init__(self, stream, process, name):
        self._file = PyFile(stream, "'%s'" % name)
        self._process = process

    def __getattr__(self, name):
        return getattr(self._file, name)

    def __repr__(self):
        return ` self._file `

    def close(self):
        self._file.close()
        return self._process.waitFor() or None
Пример #5
0
class _ProcessFile:
    """Python file object that returns the process exit status from
    the close method.
    """
    def __init__(self, stream, process, name):
        self._file = PyFile(stream, "'%s'" % name)
        self._process = process

    def __getattr__(self, name):
        return getattr(self._file, name)

    def __repr__(self):
        return `self._file`
        
    def close(self):
        self._file.close()
        return self._process.waitFor() or None
Пример #6
0
 def _join(self, stdout, stderr, bufsize):
     """create a stream that joins two output streams"""
     self._pipeOut = PipedOutputStream()
     joinedStream = PipedInputStream(self._pipeOut)
     self._outReader = _makeReaderThread(stdout, self._pipeOut.write,
                                         bufsize,
                                         "%s-stdout" % self.process,
                                         self._close)
     self._errReader = _makeReaderThread(stderr, self._pipeOut.write,
                                         bufsize,
                                         "%s-stderr" % self.process,
                                         self._close)
     return PyFile(joinedStream)
Пример #7
0
 def _testCmds(self, _shellEnv, testCmds, whichEnv):
     """test commands (key) and compare output to expected output (value).
     this actually executes all the commands twice, testing the return
     code by calling system(), and testing some of the output by calling
     execute()
     """
     for cmd, pattern in testCmds:
         dprint("\nExecuting '%s' with %s environment" % (cmd, whichEnv))
         p = javashell.shellexecute(cmd)
         line = PyFile(p.getInputStream()).readlines()[0]
         assert re.match( pattern, line ), \
                 "expected match for %s, got %s" % ( pattern, line )
         dprint("waiting for", cmd, "to complete")
         assert not p.waitFor(), \
                 "%s failed with %s environment" % (cmd, whichEnv)
Пример #8
0
 def __init__(self, stream, process, name):
     self._file = PyFile(stream, "'%s'" % name)
     self._process = process
Пример #9
0
 def set_wsgi_streams(self, req, resp, dict):
     try:
         dict["wsgi.input"] = PyFile(req.getInputStream())
         dict["wsgi.errors"] = PyFile(System.err)
     except IOException, iox:
         raise ModjyIOException(iox)
Пример #10
0
 def __init__(self, stream, process, name):
     self._file = PyFile(stream, "'%s'" % name)
     self._process = process