~oubiwann/ubuntu-accomplishments-system/946850-twisted-app

« back to all changes in this revision

Viewing changes to accomplishments/util/__init__.py

  • Committer: Duncan McGreggor
  • Date: 2012-03-20 00:30:38 UTC
  • Revision ID: duncan@dreamhost.com-20120320003038-2ailsg4w7brgasue
* Moved the subprocess protocol into util where it could be used by everyone
  easily.
* Updated the gpg util to use this process protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
93
93
    return options
94
94
 
95
95
 
 
96
class SubprocessReturnCodeProtocol(protocol.ProcessProtocol):
 
97
    """
 
98
    """
 
99
    def __init__(self, command=""):
 
100
        self.command = command
 
101
 
 
102
    def connectionMade(self):
 
103
        self.returnCodeDeferred = defer.Deferred()
 
104
 
 
105
    def processEnded(self, reason):
 
106
        self.returnCodeDeferred.callback(reason.value.exitCode)
 
107
 
 
108
    def outReceived(self, data):
 
109
        log.msg("Got process results: %s" % data)
 
110
 
 
111
    def errReceived(self, data):
 
112
        log.err("Got non-zero exit code for process: %s" % (
 
113
            " ".join(self.command),))
 
114
        log.msg(data)
 
115
 
 
116
 
96
117
def import_gpg_key(pub_key):
97
118
    """
98
119
    """
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