Exemplo n.º 1
0
    def _ProcessOutput(self, line, prog):
        """Takes care of child process output.

    @type line: string
    @param line: Child output line
    @type prog: number
    @param prog: Program from which the line originates

    """
        force_update = False
        forward_line = line

        if prog == PROG_SOCAT:
            level = None
            parts = line.split(None, 4)

            if len(parts) == 5:
                (_, _, _, level, msg) = parts

                force_update = self._ProcessSocatOutput(
                    self._status_file, level, msg)

                if self._debug or (level and level not in SOCAT_LOG_IGNORE):
                    forward_line = "socat: %s %s" % (level, msg)
                else:
                    forward_line = None
            else:
                forward_line = "socat: %s" % line

        elif prog == PROG_DD:
            (should_forward, force_update) = self._ProcessDdOutput(line)

            if should_forward or self._debug:
                forward_line = "dd: %s" % line
            else:
                forward_line = None

        elif prog == PROG_DD_PID:
            if self._dd_pid:
                raise RuntimeError("dd PID reported more than once")
            logging.debug("Received dd PID %r", line)
            self._dd_pid = int(line)
            forward_line = None

        elif prog == PROG_EXP_SIZE:
            logging.debug("Received predicted size %r", line)
            forward_line = None

            if line:
                try:
                    exp_size = utils.BytesToMebibyte(int(line))
                except (ValueError, TypeError), err:
                    logging.error(
                        "Failed to convert predicted size %r to number: %s",
                        line, err)
                    exp_size = None
            else:
                exp_size = None

            self._exp_size = exp_size
Exemplo n.º 2
0
    def _ProcessDdOutput(self, line):
        """Interprets a line of dd(1)'s output.

    """
        m = DD_INFO_RE.match(line)
        if m:
            seconds = float(m.group("seconds"))
            mbytes = utils.BytesToMebibyte(int(m.group("bytes")))
            self._UpdateDdProgress(seconds, mbytes)
            return (False, True)

        m = DD_STDERR_IGNORE.match(line)
        if m:
            # Ignore
            return (False, False)

        # Forward line
        return (True, False)