def spawnChannel3(name, ch3_receiver, protocol, executable, args=(), env={}, path=None, uid=None, gid=None, usePTY=0): """ Spawn a process with Channel3 logging enabled. @param name: Name of the process as will appear in logs. @param ch3_receiver: A function of one argument that will accept L{Messages<ch3.Message>}. @param protocol: C{ProcessProtocol} instance that will handle stdin/out/err. @param **kwargs: See C{reactor.spawnProcess}. """ p = Channel3Protocol(name, ch3_receiver, protocol) # XXX this ought to be configurable. I guess it is if you spawn the # process yourself. p.done.addErrback(lambda x:None) # log it log_kwargs = _spawnDefaultArgs(executable,args,env,path,uid,gid,usePTY) ch3_receiver(ch3.spawnProcess(name, **log_kwargs)) # spawn it childFDs = { 0: 'w', 1: 'r', 2: 'r', 3: 'r', } reactor.spawnProcess(p, executable, args, env, path, uid, gid, usePTY, childFDs) return p
def test_basic(self): """ You can spawn a process """ proto = MagicMock() history = [] p = spawnChannel3('jim', history.append, proto, '/bin/ls', ['ls', '-al']) kwargs = _spawnDefaultArgs('/bin/ls', ['ls', '-al']) self.assertEqual(history[0], ch3.spawnProcess('jim', **kwargs), "Should indicate the arguments used to spawn") def check(status): self.assertEqual(status.value.exitCode, 0) for x in history: log.msg(x) print 'hello?' return p.done.addErrback(check)
def test_basic(self): """ You can indicate that a process was spawned """ self.assertEqual(spawnProcess('joe', 'executable', args=['foo', 'bar'], env={'something': 'here'}, path='some path', uid='userid', gid='groupid', usePTY='foo'), Message('joe', 'spawn', { 'executable': 'executable', 'args': ['foo', 'bar'], 'env': {'something': 'here'}, 'path': 'some path', 'uid': 'userid', 'gid': 'groupid', 'usePTY': 'foo', }) )