96
class SubprocessReturnCodeProtocol(protocol.ProcessProtocol):
99
def __init__(self, command=""):
100
self.command = command
102
def connectionMade(self):
103
self.returnCodeDeferred = defer.Deferred()
105
def processEnded(self, reason):
106
self.returnCodeDeferred.callback(reason.value.exitCode)
108
def outReceived(self, data):
109
log.msg("Got process results: %s" % data)
111
def errReceived(self, data):
112
log.err("Got non-zero exit code for process: %s" % (
113
" ".join(self.command),))
96
117
def import_gpg_key(pub_key):
99
gpg = protocol.ProcessProtocol()
120
cmd = ["gpg", "--import", pub_key]
121
gpg = SubprocessReturnCodeProtocol(cmd)
100
122
gpg.deferred = defer.Deferred()
101
cmd = ["gpg", "--import", pub_key]
102
process = reactor.spawnProcess(
103
gpg, cmd[0], cmd, env=None, childFDs={
104
0: "w", 1: "r", 2: 2, 3: "w", 4: "r"})
123
process = reactor.spawnProcess(gpg, cmd[0], cmd, env=None)
105
124
return gpg.deferred