def _get_caller(log_cb=None): def _log_call(*lines): _log(lines, prefix=" ", stream="call") def _log_stdout(*lines): _log(lines, prefix=">", stream="stdout") def _log_stderr(*lines): _log(lines, prefix="!", stream="stderr") def _log(lines, prefix=None, stream=None): if log_cb is None: return log_cb(lines, prefix=prefix, stream=stream) caller = CommandlineCaller() if log_cb is not None: caller.on_log_call = _log_call caller.on_log_stdout = _log_stdout caller.on_log_stderr = _log_stderr return caller
def _do_copy_log(self): # Get the name of the tarball we're going to copy the log # files to. tarball_filename = self.build_tarball_filename() self._log("tarball = <%s>" % tarball_filename) # Get the location where we're going to save the tarball. logpath = self.find_logpath() self._log("logpath = <%s>" % logpath) # Build the full path to the tarball tarball_path = os.path.join(logpath, tarball_filename) self._log("tarball_path = <%s>" % tarball_path) # Get the names of the log files logfiles = self.get_log_file_names() self._log("logfiles = <%s>" % logfiles) # Now build the command. command = "tar cvf %s %s" % (tarball_path, logfiles) self._log("command = <%s>" % command) # Construct a commandline caller to run the tar command. caller = CommandlineCaller() caller.on_log_call = self.display_call_stdout caller.on_log_stdout = self.display_call_stdout caller.on_log_stderr = self.display_stderr # Execute the command. self.display("") caller.call(command) # Finish off with a message stating that the tarball has been # created. done_message = "Logs copied to file \"%s\"" % tarball_path self._log(done_message) self.display("\n" + done_message) self.display("")