diff options
Diffstat (limited to 'distbuild-helper')
-rwxr-xr-x | distbuild-helper | 80 |
1 files changed, 5 insertions, 75 deletions
diff --git a/distbuild-helper b/distbuild-helper index d77fcaea..76a39d5f 100755 --- a/distbuild-helper +++ b/distbuild-helper @@ -32,78 +32,6 @@ import urlparse import distbuild -class FileReadable(object): - - def __init__(self, request_id, p, f): - self.request_id = request_id - self.process = p - self.file = f - - -class FileWriteable(object): - - def __init__(self, request_id, p, f): - self.request_id = request_id - self.process = p - self.file = f - - -class SubprocessEventSource(distbuild.EventSource): - - def __init__(self): - self.procs = [] - self.closed = False - - def get_select_params(self): - r = [] - w = [] - for requst_id, p in self.procs: - if p.stdin_contents is not None: - w.append(p.stdin) - if p.stdout is not None: - r.append(p.stdout) - if p.stderr is not None: - r.append(p.stderr) - return r, w, [], None - - def get_events(self, r, w, x): - events = [] - - for request_id, p in self.procs: - if p.stdin in w: - events.append(FileWriteable(request_id, p, p.stdin)) - if p.stdout in r: - events.append(FileReadable(request_id, p, p.stdout)) - if p.stderr in r: - events.append(FileReadable(request_id, p, p.stderr)) - - return events - - def add(self, request_id, process): - - self.procs.append((request_id, process)) - distbuild.set_nonblocking(process.stdin) - distbuild.set_nonblocking(process.stdout) - distbuild.set_nonblocking(process.stderr) - - def remove(self, process): - self.procs = [t for t in self.procs if t[1] != process] - - def kill_by_id(self, request_id): - logging.debug('SES: Killing all processes for %s', request_id) - for id, process in self.procs: - if id == request_id: - logging.debug('SES: killing %s', repr(process)) - process.kill() - - def close(self): - self.procs = [] - self.closed = True - - def is_finished(self): - return self.closed - - class HelperMachine(distbuild.StateMachine): def __init__(self, conn): @@ -117,7 +45,7 @@ class HelperMachine(distbuild.StateMachine): jm = self.jm = distbuild.JsonMachine(self.conn) self.mainloop.add_state_machine(jm) - p = self.procsrc = SubprocessEventSource() + p = self.procsrc = distbuild.SubprocessEventSource() self.mainloop.add_event_source(p) self.send_helper_ready(jm) @@ -125,8 +53,10 @@ class HelperMachine(distbuild.StateMachine): spec = [ ('waiting', jm, distbuild.JsonNewMessage, 'waiting', self.do), ('waiting', jm, distbuild.JsonEof, None, self._eofed), - ('waiting', p, FileReadable, 'waiting', self._relay_exec_output), - ('waiting', p, FileWriteable, 'waiting', self._feed_stdin), + ('waiting', p, distbuild.FileReadable, 'waiting', + self._relay_exec_output), + ('waiting', p, distbuild.FileWriteable, 'waiting', + self._feed_stdin), ] self.add_transitions(spec) |