class Popen4(Popen3): """Popen object that joins the stdout and stderr streams into a single output stream.""" childerr = None def __init__(self, cmd, bufsize=-1): Popen3.__init__(self, cmd, 1, bufsize) self.closed = Vector() # use a vector for synchronization close() self.fromchild = self._join(self._fromchild, self._childerr, bufsize) 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) def _close(self): """Must be closed twice (once for each of the two joined pipes)""" self.closed.add(None) if self.closed.size() > 1: self._pipeOut.close()
def _add_nodes(self, curTop, dir): """ Recursive implementation to fill the tree with filenames and directories :param curTop: current top directory :param dir: next directory :return: None """ curPath = dir.getPath() if os.path.isdir(curPath): nodePath = os.path.basename(curPath) curDir = DefaultMutableTreeNode(nodePath) if curTop != None: # should only be null at root curTop.add(curDir) ol = Vector() tmp = dir.list() for i in xrange(0, len(tmp)): ol.addElement(tmp[i]) thisObject = None files = Vector() # Make two passes, one for Dirs and one for Files. This is #1. for i in xrange(0, ol.size()): thisObject = ol.elementAt(i) if curPath == self._dir: newPath = thisObject else: newPath = os.path.join(curPath, thisObject) f = File(newPath) if f.isDirectory(): self._add_nodes(curDir, f) else: files.addElement(thisObject) # Pass two: for files. Collections.sort(files) for i in xrange(0, files.size()): f = files.elementAt(i) #if f.split('.')[-1] != 'html': curDir.add(DefaultMutableTreeNode(files.elementAt(i))) return curDir
class Popen4(Popen3): """Popen object that joins the stdout and stderr streams into a single output stream.""" childerr = None def __init__(self, cmd, bufsize=-1): Popen3.__init__( self, cmd, 1, bufsize ) self.closed = Vector() # use a vector for synchronization close() self.fromchild = self._join( self._fromchild, self._childerr, bufsize ) 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 FileUtil.wrap(joinedStream) def _close( self ): """Must be closed twice (once for each of the two joined pipes)""" self.closed.add( None ) if self.closed.size() > 1: self._pipeOut.close()
class ContDist(object): def __init__(self, varName): self.varName = varName self.v = Vector() self.pdf = OpdfGaussian() def addExample(self, d): value = d[self.varName] self.v.add(ObservationReal(value)) def finish(self): if self.v.size() == 0: self.pdf = OpdfGaussian(0.5, 0.05) return try: self.pdf.fit(self.v) self.pdf.distribution.variance += 0.05 except: self.pdf = OpdfGaussian(self.v.get(0).value, 0.05) def density(self, v): return self.pdf.probability(ObservationReal(v))