def save_to_stream(self, stream): from processes import PipeThroughCommand assert not hasattr(self, 'child_run') # No longer supported self.process = PipeThroughCommand(self.command, self.stdin, stream) self.process.wait() self.process = None
class SaveFilter(Saveable): """This Saveable runs a process in the background to generate the save data. Any python streams can be used as the input to and output from the process. The output from the subprocess is saved to the output stream (either directly, for fileno() streams, or via another temporary file). If the process returns a non-zero exit status or writes to stderr, the save fails (messages written to stderr are displayed). """ command = None stdin = None def set_stdin(self, stream): """Use 'stream' as stdin for the process. If stream is not a seekable fileno() stream then it is copied to a temporary file at this point. If None, the child process will get /dev/null on stdin.""" if stream is not None: if hasattr(stream, 'fileno') and hasattr(stream, 'seek'): self.stdin = stream else: import tempfile import shutil self.stdin = tempfile.TemporaryFile() shutil.copyfileobj(stream, self.stdin) else: self.stdin = None def save_to_stream(self, stream): from processes import PipeThroughCommand assert not hasattr(self, 'child_run') # No longer supported self.process = PipeThroughCommand(self.command, self.stdin, stream) self.process.wait() self.process = None def save_cancelled(self): """Send SIGTERM to the child processes.""" if self.process: self.killed = 1 self.process.kill()