1 """
2 Methods and classes to run programs described through DataDescriptors
3 within a twisted event loop.
4 """
5
6
7
8
9
10
11
12 import sys
13 import os
14
15 from twisted.internet import protocol
16 from twisted.internet import reactor
17 from twisted.internet import defer
18 from gavo import base
19
20
23
24
26 """is a simple program protocol that writes input to the process and
27 sends the output to the deferred result in one swoop when done.
28 """
29 - def __init__(self, input, result, swallowStderr=False):
33
35 self.transport.write(self.input)
36 self.transport.closeStdin()
37
40
44
50
51
52 -def runWithData(prog, inputString, args, swallowStderr=False):
53 """returns a deferred firing the complete result of running prog with
54 args and inputString.
55 """
56 result = defer.Deferred()
57 fetchOutputProtocol = StdioProtocol(inputString, result, swallowStderr)
58 prog = base.getBinaryName(prog)
59 reactor.spawnProcess(fetchOutputProtocol, prog,
60 args=[str(prog)]+list(str(s) for s in args), path=os.path.dirname(prog))
61 return result
62