'Parse the dpkg output.'

def Parse(self, cmd, args, stdout, stderr, return_val, time_taken, knowledge_base):

    _ = (stderr, time_taken, args, knowledge_base)
    self.CheckReturn(cmd, return_val)
    column_lengths = []
    i = 0
    for (i, line) in enumerate(stdout.splitlines()):
        if line.startswith('+++-'):
            for col in line.split('-')[1:]:
                if (not re.match('=*', col)):
                    raise parsers.ParseError(('Invalid    header    parsing    for    %s    at    line    %s' % (cmd, i)))
                column_lengths.append(len(col))
            break
    if column_lengths:
        remaining_lines = stdout.splitlines()[(i + 1):]
        for (i, line) in enumerate(remaining_lines):
            cols = line.split(None, len(column_lengths))
            if (len(column_lengths) == 4):
                (status, name, version, arch, desc) = cols
            elif (len(column_lengths) == 3):
                (status, name, version, desc) = cols
                arch = None
            else:
                raise RuntimeError(('Bad    number    of    columns    in    dpkg    --list    output:    %s' % len(column_lengths)))
            if (status[1] == 'i'):
                status = rdf_client.SoftwarePackage.InstallState.INSTALLED
            else:
                status = rdf_client.SoftwarePackage.InstallState.UNKNOWN
            (yield rdf_client.SoftwarePackage(name=name, description=desc, version=version, architecture=arch, install_state=status))
