def transform(self, **kwargs): from girder_worker.docker.io import ( NamedPipe, NamedPipeWriter ) super(NamedInputPipe, self).transform(**kwargs) pipe = NamedPipe(self.host_path) return NamedPipeWriter(pipe, self.container_path)
def _setup_streams(task_inputs, inputs, task_outputs, outputs, tempdir, job_mgr, progress_pipe): """ Returns a 2 tuple of input and output pipe mappings. The first element is a dict mapping input file descriptors to the corresponding stream adapters, the second is a dict mapping output file descriptors to the corresponding stream adapters. This also handles the special cases of STDIN, STDOUT, and STDERR mappings, and in the case of non-streaming standard IO pipes, will create default bindings for those as well. """ stream_connectors = [] def stream_pipe_path(id, spec, bindings): """ Helper to check for a valid streaming IO specs. If the given spec is not a streaming spec, returns None. If it is, returns the path. """ if spec.get('stream') and id in bindings and spec.get( 'target') == 'filepath': path = spec.get('path', id) if path.startswith('/'): raise Exception('Streaming filepaths must be relative.') path = os.path.join(tempdir, path) return path return None # handle stream inputs for id, spec in task_inputs.iteritems(): path = stream_pipe_path(id, spec, inputs) # We have a streaming input if path is not None: writer = NamedPipeWriter(NamedPipe(path)) connector = FDWriteStreamConnector( make_stream_fetch_adapter(inputs[id]), writer) stream_connectors.append(connector) # Don't open from this side, must be opened for reading first! # handle stream outputs for id, spec in task_outputs.iteritems(): path = stream_pipe_path(id, spec, outputs) if path is not None: reader = NamedPipeReader(NamedPipe(path)) connector = FDReadStreamConnector( reader, make_stream_push_adapter(outputs[id])) stream_connectors.append(connector) # handle special stream output for job progress if progress_pipe and job_mgr: progress_pipe = ProgressPipe(os.path.join(tempdir, '.girder_progress')) stream_connectors.append(progress_pipe.open()) return stream_connectors
def test_NamedPipeWriter_path_is_container_path(stream): path = '/some/test/path/' npr = NamedPipeWriter(stream, container_path=path) assert npr.path() == path
def test_NamedPipeWriter_fileno_is_pipe_fileno(stream): npr = NamedPipeWriter(stream) assert npr.fileno() == stream.fileno()
def test_NamedPipeWriter_open_calls_pipe_open(stream): with mock.patch.object(stream, 'open', create=True) as m: NamedPipeWriter(stream).open() m.assert_called_once()