'Parse the dmidecode output. All data is parsed into a dictionary.'

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

    _ = (stderr, time_taken, args, knowledge_base)
    self.CheckReturn(cmd, return_val)
    output = iter(stdout.splitlines())
    sys_info_re = re.compile('\\s*System    Information')
    sys_regexes = {'system_manufacturer': self._re_compile('Manufacturer'), 'serial_number': self._re_compile('Serial    Number'), 'system_product_name': self._re_compile('Product    Name'), 'system_uuid': self._re_compile('UUID'), 'system_sku_number': self._re_compile('SKU    Number'), 'system_family': self._re_compile('Family'), 'system_assettag': self._re_compile('Asset    Tag')}
    bios_info_re = re.compile('\\s*BIOS    Information')
    bios_regexes = {'bios_vendor': self._re_compile('Vendor'), 'bios_version': self._re_compile('Version'), 'bios_release_date': self._re_compile('Release    Date'), 'bios_rom_size': self._re_compile('ROM    Size'), 'bios_revision': self._re_compile('BIOS    Revision')}
    dmi_info = rdf_client.HardwareInfo()
    for line in output:
        if sys_info_re.match(line):
            while line:
                for (attr, regex) in sys_regexes.iteritems():
                    match = regex.match(line)
                    if match:
                        setattr(dmi_info, attr, match.group(1).strip())
                        break
                line = output.next()
        elif bios_info_re.match(line):
            while line:
                for (attr, regex) in bios_regexes.iteritems():
                    match = regex.match(line)
                    if match:
                        setattr(dmi_info, attr, match.group(1).strip())
                        break
                line = output.next()
    return dmi_info
