Python将混合格式文本文件的输出解析为键值对字典

时间:2017-03-29 21:12:31

标签: python python-2.7 parsing dictionary

我正在尝试解析来自EMC OneFS CLI的命令输出。我们正在尝试收集广告资源数据,因为我们使用旧版本的API,所以我们无法使用REST SDK。

相反,我们决定这样做" hacky"方法并解析CLI命令的输出。

考虑到不同的文本格式,我如何在Python中可靠地解析这些数据?请注意不同数量的空白区域,以及其中一些空格由:分隔,而其他空格由=分隔。

我有一个不错的开始,我能够将每一行拆分成一个列表并处理=符号嵌套在括号内的情况。

我仍然坚持其他部分:

  • 将第一列作为"主机名"
  • 为包含所有键值对的每个主机名构建单独的字典(一些由:分隔,其他由=分隔)

需要分配的RAW输出:

visi-91:   SerNo: S123456789P
visi-91:  Config: 912-111-231
visi-91:   Class: storage
visi-91:  Series: x_series
visi-91: Product: IQ 32000x-ssd
visi-91: Comps:  Chassis CPU     Motherboard     NVRam   FlashDrive      Disk_Controller Disk_Expander   Power_Supplies 
visi-91:   HWGen: MaunaLoa (MaunaLoa Hardware)
visi-91: Chassis: ISI36 (Isilon (CIDesigns) 36-Bay Chassis)
visi-91:     CPU: GenuineIntel (2.33GHz, stepping 0x0001067a)
visi-91:    PROC: Dual-proc, Quad-core
visi-91:     RAM: 17150812160 Bytes
visi-91:    Mobo: SupMicX7DBU (SuperMicro X7DBU Motherboard)
visi-91:   NVRam: MT25208 (Mellanox 25208 based Card) (492MB card) (size 515899392B)
visi-91: FlshDrv: None (No physical dongle supported) ((null))
visi-91:  DskCtl: LSI3081E-HBA (LSI SAS3081E SAS Controller -- HBA) (8 ports)
visi-91:  DskExp: VIT7156 (Vitesse 7156 Disk Expander)
visi-91: PwrSupl: PS1 (type=Emerson, fw=v.01.00.00)
visi-91: PwrSupl: PS2 (type=Emerson, fw=v.01.00.00)
visi-91: ChasCnt: 1 (Single-Chassis System)
visi-91:   NetIF: em*4,ib*2 (4x Intel, 2x IB)
visi-91:  IBType: ISI25208 (Isilon MT25208-based IB Card)
visi-91:  LCDver: NoriVFD (Noritake VFD)
visi-91:     IMB: Board Version 0x20f
visi-91: Power Supplies OK
visi-91: CPU Operation (raw 0x882F0000)  = Normal
visi-91: CPU Speed Limit                 = 100.00%
visi-91: Chassis Fan1 (ISI F1)           = 7469
visi-91: Chassis Fan2 (ISI F2)           = 7552
visi-91: Chassis Fan3 (ISI F3)           = 7387
visi-91: Power Supply 1 Fan              = 5504
visi-91: Power Supply 2 Fan              = 5792
visi-91: Temp Until CPU Throttle (CPU 0) = 46.0
visi-91: Temp Until CPU Throttle (CPU 1) = 42.0
visi-91: Temp Front Panel                = 17.0
visi-91: Temp Chassis 2 (ISI T2)         = 22.0
visi-91: Temp System                     = 25.0
visi-92:   SerNo: S123456785K
visi-92:  Config: 912-111-231
visi-92:   Class: storage
visi-92:  Series: x_series
visi-92: Product: IQ 32000x-ssd
visi-92: Comps:  Chassis CPU     Motherboard     NVRam   FlashDrive      Disk_Controller Disk_Expander   Power_Supplies 
visi-92:   HWGen: MaunaLoa (MaunaLoa Hardware)
visi-92: Chassis: ISI36 (Isilon (CIDesigns) 36-Bay Chassis)
visi-92:     CPU: GenuineIntel (2.33GHz, stepping 0x0001067a)
visi-92:    PROC: Dual-proc, Quad-core
visi-92:     RAM: 17150812160 Bytes
visi-92:    Mobo: SupMicX7DBU (SuperMicro X7DBU Motherboard)
visi-92:   NVRam: MT25208 (Mellanox 25208 based Card) (492MB card) (size 515899392B)
visi-92: FlshDrv: None (No physical dongle supported) ((null))
visi-92:  DskCtl: LSI3081E-HBA (LSI SAS3081E SAS Controller -- HBA) (8 ports)
visi-92:  DskExp: VIT7156 (Vitesse 7156 Disk Expander)
visi-92: PwrSupl: PS1 (type=Emerson, fw=v.01.00.00)
visi-92: PwrSupl: PS2 (type=Emerson, fw=v.01.00.00)
visi-92: ChasCnt: 1 (Single-Chassis System)
visi-92:   NetIF: em*4,ib*2 (4x Intel, 2x IB)
visi-92:  IBType: ISI25208 (Isilon MT25208-based IB Card)
visi-92:  LCDver: NoriVFD (Noritake VFD)
visi-92:     IMB: Board Version 0x20f
visi-92: Power Supplies OK
visi-92: CPU Operation (raw 0x882E0000)  = Normal
visi-92: CPU Speed Limit                 = 100.00%
visi-92: Chassis Fan1 (ISI F1)           = 7268
visi-92: Chassis Fan2 (ISI F2)           = 7307
visi-92: Chassis Fan3 (ISI F3)           = 7190
visi-92: Power Supply 1 Fan              = 5376
visi-92: Power Supply 2 Fan              = 5696
visi-92: Temp Until CPU Throttle (CPU 0) = 46.0
visi-92: Temp Until CPU Throttle (CPU 1) = 46.0
visi-92: Temp Front Panel                = 17.2
visi-92: Temp Chassis 2 (ISI T2)         = 24.0
visi-92: Temp System                     = 27.0
visi-93:   SerNo: S987654321P
visi-93:  Config: 912-111-231
visi-93:   Class: storage
visi-93:  Series: x_series
visi-93: Product: IQ 32000x-ssd
visi-93: Comps:  Chassis CPU     Motherboard     NVRam   FlashDrive      Disk_Controller Disk_Expander   Power_Supplies 
visi-93:   HWGen: MaunaLoa (MaunaLoa Hardware)
visi-93: Chassis: ISI36 (Isilon (CIDesigns) 36-Bay Chassis)
visi-93:     CPU: GenuineIntel (2.33GHz, stepping 0x0001067a)
visi-93:    PROC: Dual-proc, Quad-core
visi-93:     RAM: 17150812160 Bytes
visi-93:    Mobo: SupMicX7DBU (SuperMicro X7DBU Motherboard)
visi-93:   NVRam: MT25208 (Mellanox 25208 based Card) (492MB card) (size 515899392B)
visi-93: FlshDrv: None (No physical dongle supported) ((null))
visi-93:  DskCtl: LSI3081E-HBA (LSI SAS3081E SAS Controller -- HBA) (8 ports)
visi-93:  DskExp: VIT7156 (Vitesse 7156 Disk Expander)
visi-93: PwrSupl: PS1 (type=Emerson, fw=v.03.05.00)
visi-93: PwrSupl: PS2 (type=Emerson, fw=v.03.05.00)
visi-93: ChasCnt: 1 (Single-Chassis System)
visi-93:   NetIF: em*4,ib*2 (4x Intel, 2x IB)
visi-93:  IBType: ISI25208 (Isilon MT25208-based IB Card)
visi-93:  LCDver: NoriVFD (Noritake VFD)
visi-93:     IMB: Board Version 0x20f
visi-93: Power Supplies OK
visi-93: CPU Operation (raw 0x88250000)  = Normal
visi-93: CPU Speed Limit                 = 100.00%
visi-93: Chassis Fan1 (ISI F1)           = 7387
visi-93: Chassis Fan2 (ISI F2)           = 7152
visi-93: Chassis Fan3 (ISI F3)           = 7152
visi-93: Power Supply 1 Fan              = 8512
visi-93: Power Supply 2 Fan              = 8512
visi-93: Temp Until CPU Throttle (CPU 0) = 37.0
visi-93: Temp Until CPU Throttle (CPU 1) = 38.0
visi-93: Temp Front Panel                = 17.4
visi-93: Temp Chassis 2 (ISI T2)         = 25.0
visi-93: Temp System                     = 28.0

我的代码很远:

#Read text file
file = open("test_itry.txt", "r")
lines = file.readlines()
file.close()

for line in lines:
    #Remove whitespaces
    line = line.replace(' ','')
    #Remove newlines
    line = line.replace('\n','')
    #Handler values that have equals signs nested within parenthesis
    #If line has closed parenthesis and equals sign
    if line.count(")") > 0 and line.count("=") > 0:
        #Get first position of open parenthesis
        poscp = line.find(")")
        #Get first position of equals sign
        poseq = line.find("=")
        #If position of equals sign comes before position of first parenthesis
        if poscp < poseq:
            #Split by first equals sign
            line = line.split("=", 1)
    #If line doesn't have closed parenthesis and an equals sign
    else:
        line = line.split("=", 1)
    #If line has not been split into a list yet create a list
    if isinstance(line, str):
        line = line.split() 
    print(line)

我的代码输出如此远:

['visi-91:SerNo:S123456789P']
['visi-91:Config:912-111-231']
['visi-91:Class:storage']
['visi-91:Series:x_series']
['visi-91:Product:IQ32000x-ssd']
['visi-91:Comps:ChassisCPUMotherboardNVRamFlashDriveDisk_ControllerDisk_ExpanderPower_Supplies']
['visi-91:HWGen:MaunaLoa(MaunaLoaHardware)']
['visi-91:Chassis:ISI36(Isilon(CIDesigns)36-BayChassis)']
['visi-91:CPU:GenuineIntel(2.33GHz,stepping0x0001067a)']
['visi-91:PROC:Dual-proc,Quad-core']
['visi-91:RAM:17150812160Bytes']
['visi-91:Mobo:SupMicX7DBU(SuperMicroX7DBUMotherboard)']
['visi-91:NVRam:MT25208(Mellanox25208basedCard)(492MBcard)(size515899392B)']
['visi-91:FlshDrv:None(Nophysicaldonglesupported)((null))']
['visi-91:DskCtl:LSI3081E-HBA(LSISAS3081ESASController--HBA)(8ports)']
['visi-91:DskExp:VIT7156(Vitesse7156DiskExpander)']
['visi-91:PwrSupl:PS1(type=Emerson,fw=v.01.00.00)']
['visi-91:PwrSupl:PS2(type=Emerson,fw=v.01.00.00)']
['visi-91:ChasCnt:1(Single-ChassisSystem)']
['visi-91:NetIF:em*4,ib*2(4xIntel,2xIB)']
['visi-91:IBType:ISI25208(IsilonMT25208-basedIBCard)']
['visi-91:LCDver:NoriVFD(NoritakeVFD)']
['visi-91:IMB:BoardVersion0x20f']
['visi-91:PowerSuppliesOK']
['visi-91:CPUOperation(raw0x882F0000)', 'Normal']
['visi-91:CPUSpeedLimit', '100.00%']
['visi-91:ChassisFan1(ISIF1)', '7469']
['visi-91:ChassisFan2(ISIF2)', '7552']
['visi-91:ChassisFan3(ISIF3)', '7387']
['visi-91:PowerSupply1Fan', '5504']
['visi-91:PowerSupply2Fan', '5792']
['visi-91:TempUntilCPUThrottle(CPU0)', '46.0']
['visi-91:TempUntilCPUThrottle(CPU1)', '42.0']
['visi-91:TempFrontPanel', '17.0']
['visi-91:TempChassis2(ISIT2)', '22.0']
['visi-91:TempSystem', '25.0']
['visi-92:SerNo:S123456785K']
['visi-92:Config:912-111-231']
['visi-92:Class:storage']
['visi-92:Series:x_series']
['visi-92:Product:IQ32000x-ssd']
['visi-92:Comps:ChassisCPUMotherboardNVRamFlashDriveDisk_ControllerDisk_ExpanderPower_Supplies']
['visi-92:HWGen:MaunaLoa(MaunaLoaHardware)']
['visi-92:Chassis:ISI36(Isilon(CIDesigns)36-BayChassis)']
['visi-92:CPU:GenuineIntel(2.33GHz,stepping0x0001067a)']
['visi-92:PROC:Dual-proc,Quad-core']
['visi-92:RAM:17150812160Bytes']
['visi-92:Mobo:SupMicX7DBU(SuperMicroX7DBUMotherboard)']
['visi-92:NVRam:MT25208(Mellanox25208basedCard)(492MBcard)(size515899392B)']
['visi-92:FlshDrv:None(Nophysicaldonglesupported)((null))']
['visi-92:DskCtl:LSI3081E-HBA(LSISAS3081ESASController--HBA)(8ports)']
['visi-92:DskExp:VIT7156(Vitesse7156DiskExpander)']
['visi-92:PwrSupl:PS1(type=Emerson,fw=v.01.00.00)']
['visi-92:PwrSupl:PS2(type=Emerson,fw=v.01.00.00)']
['visi-92:ChasCnt:1(Single-ChassisSystem)']
['visi-92:NetIF:em*4,ib*2(4xIntel,2xIB)']
['visi-92:IBType:ISI25208(IsilonMT25208-basedIBCard)']
['visi-92:LCDver:NoriVFD(NoritakeVFD)']
['visi-92:IMB:BoardVersion0x20f']
['visi-92:PowerSuppliesOK']
['visi-92:CPUOperation(raw0x882E0000)', 'Normal']
['visi-92:CPUSpeedLimit', '100.00%']
['visi-92:ChassisFan1(ISIF1)', '7268']
['visi-92:ChassisFan2(ISIF2)', '7307']
['visi-92:ChassisFan3(ISIF3)', '7190']
['visi-92:PowerSupply1Fan', '5376']
['visi-92:PowerSupply2Fan', '5696']
['visi-92:TempUntilCPUThrottle(CPU0)', '46.0']
['visi-92:TempUntilCPUThrottle(CPU1)', '46.0']
['visi-92:TempFrontPanel', '17.2']
['visi-92:TempChassis2(ISIT2)', '24.0']
['visi-92:TempSystem', '27.0']
['visi-93:SerNo:S987654321P']
['visi-93:Config:912-111-231']
['visi-93:Class:storage']
['visi-93:Series:x_series']
['visi-93:Product:IQ32000x-ssd']
['visi-93:Comps:ChassisCPUMotherboardNVRamFlashDriveDisk_ControllerDisk_ExpanderPower_Supplies']
['visi-93:HWGen:MaunaLoa(MaunaLoaHardware)']
['visi-93:Chassis:ISI36(Isilon(CIDesigns)36-BayChassis)']
['visi-93:CPU:GenuineIntel(2.33GHz,stepping0x0001067a)']
['visi-93:PROC:Dual-proc,Quad-core']
['visi-93:RAM:17150812160Bytes']
['visi-93:Mobo:SupMicX7DBU(SuperMicroX7DBUMotherboard)']
['visi-93:NVRam:MT25208(Mellanox25208basedCard)(492MBcard)(size515899392B)']
['visi-93:FlshDrv:None(Nophysicaldonglesupported)((null))']
['visi-93:DskCtl:LSI3081E-HBA(LSISAS3081ESASController--HBA)(8ports)']
['visi-93:DskExp:VIT7156(Vitesse7156DiskExpander)']
['visi-93:PwrSupl:PS1(type=Emerson,fw=v.03.05.00)']
['visi-93:PwrSupl:PS2(type=Emerson,fw=v.03.05.00)']
['visi-93:ChasCnt:1(Single-ChassisSystem)']
['visi-93:NetIF:em*4,ib*2(4xIntel,2xIB)']
['visi-93:IBType:ISI25208(IsilonMT25208-basedIBCard)']
['visi-93:LCDver:NoriVFD(NoritakeVFD)']
['visi-93:IMB:BoardVersion0x20f']
['visi-93:PowerSuppliesOK']
['visi-93:CPUOperation(raw0x88250000)', 'Normal']
['visi-93:CPUSpeedLimit', '100.00%']
['visi-93:ChassisFan1(ISIF1)', '7387']
['visi-93:ChassisFan2(ISIF2)', '7152']
['visi-93:ChassisFan3(ISIF3)', '7152']
['visi-93:PowerSupply1Fan', '8512']
['visi-93:PowerSupply2Fan', '8512']
['visi-93:TempUntilCPUThrottle(CPU0)', '37.0']
['visi-93:TempUntilCPUThrottle(CPU1)', '38.0']
['visi-93:TempFrontPanel', '17.4']
['visi-93:TempChassis2(ISIT2)', '25.0']
['visi-93:TempSystem', '28.0']

DESIRED OUTPUT - 字典键/值对,第一个单词作为主机名。 每个主机名单独的词典:

{'hostname':'visi-91', 'SerNo':'S123456789P', 'Config':'912-111-231', 'Class':'storage', 'Series':'x_series', 'PwrSupl':'PS1(type=Emerson,fw=v.01.00.00)', 'Chassis':'ISI36(Isilon(CIDesigns)36-BayChassis)', 'NetIF':'em*4,ib*2(4xIntel,2xIB)', 'IBType':'ISI25208(IsilonMT25208-basedIBCard)'} //etc...

{'hostname':'visi-92', 'SerNo':'S123456785K', 'Config':'912-111-231', 'Class':'storage', 'Series':'x_series', 'PwrSupl':'PS1(type=Emerson,fw=v.01.00.00)' 'Chassis':'ISI36(Isilon(CIDesigns)36-BayChassis)', 'NetIF':'em*4,ib*2(4xIntel,2xIB)', 'IBType':'ISI25208(IsilonMT25208-basedIBCard)'}  //etc...

2 个答案:

答案 0 :(得分:1)

您需要以冒号分割这些行。 将第一个作为“主机名”放入字典中,然后成对处理剩余的一个。类似的东西:

fields = line.split(':')
my_dict["hostname"] = field[0]
for pos in range(1, len(fields), 2):
    my_dict[field(pos)] = field(pos+1)

这是基本策略;我将把实施细节留给您。 : - )

答案 1 :(得分:1)

我认为最好的方法是使用re.match()

#!/usr/bin/env python2.7

import re

results = {}

with open('in.txt', 'r') as f:
    for line in [ l.rstrip() for l in f.readlines() ]:
        match = re.match('^(?P<hostname>[^:]+): +(?P<key>[^:=]+?)(?: *[:=] *(?P<value>.+?) *)?$', line)

        if match is None:
            # skip failed matches
            #print(line)
            continue

        hostname, key, value = match.groups()

        if key == 'Comps':
            value = [ x.strip() for x in re.sub('  +',' ',value).split(' ') ]
        else:
            try:
                value = float(value)
            except:
                pass

        if hostname not in results:
            results[hostname] = {}

        if key in results[hostname]:
            old_value = results[hostname][key]
            if isinstance(old_value, list):
                old_value.append(value)
            else:
                results[hostname][key] = [ old_value, value ]
        else:
            results[hostname][key] = value

from pprint import pprint
pprint(results)

我也采取了一些自由:

  • 建议替代结果格式results[hostname][key]
  • 'Comps'数据转换为数组
  • 将任何将转换为float的内容转换为数字

输出是这样的:

{'visi-91': {'CPU': 'GenuineIntel (2.33GHz, stepping 0x0001067a)',
             'CPU Operation (raw 0x882F0000)': 'Normal',
             'CPU Speed Limit': '100.00%',
             'ChasCnt': '1 (Single-Chassis System)',
             'Chassis': 'ISI36 (Isilon (CIDesigns) 36-Bay Chassis)',
             'Chassis Fan1 (ISI F1)': 7469.0,
             'Chassis Fan2 (ISI F2)': 7552.0,
             'Chassis Fan3 (ISI F3)': 7387.0,
             'Class': 'storage',
             'Comps': ['Chassis',
                       'CPU',
                       'Motherboard',
                       'NVRam',
                       'FlashDrive',
                       'Disk_Controller',
                       'Disk_Expander',
                       'Power_Supplies'],
             'Config': '912-111-231',
             'DskCtl': 'LSI3081E-HBA (LSI SAS3081E SAS Controller -- HBA) (8 ports)',
             'DskExp': 'VIT7156 (Vitesse 7156 Disk Expander)',
             'FlshDrv': 'None (No physical dongle supported) ((null))',
             'HWGen': 'MaunaLoa (MaunaLoa Hardware)',
             'IBType': 'ISI25208 (Isilon MT25208-based IB Card)',
             'IMB': 'Board Version 0x20f',
             'LCDver': 'NoriVFD (Noritake VFD)',
             'Mobo': 'SupMicX7DBU (SuperMicro X7DBU Motherboard)',
             'NVRam': 'MT25208 (Mellanox 25208 based Card) (492MB card) (size 515899392B)',
             'NetIF': 'em*4,ib*2 (4x Intel, 2x IB)',
             'PROC': 'Dual-proc, Quad-core',
             'Power Supplies OK': None,
             'Power Supply 1 Fan': 5504.0,
             'Power Supply 2 Fan': 5792.0,
             'Product': 'IQ 32000x-ssd',
             'PwrSupl': ['PS1 (type=Emerson, fw=v.01.00.00)',
                         'PS2 (type=Emerson, fw=v.01.00.00)'],
             'RAM': '17150812160 Bytes',
             'SerNo': 'S123456789P',
             'Series': 'x_series',
             'Temp Chassis 2 (ISI T2)': 22.0,
             'Temp Front Panel': 17.0,
             'Temp System': 25.0,
             'Temp Until CPU Throttle (CPU 0)': 46.0,
             'Temp Until CPU Throttle (CPU 1)': 42.0},
 'visi-92': {'CPU': 'GenuineIntel (2.33GHz, stepping 0x0001067a)',
             'CPU Operation (raw 0x882E0000)': 'Normal',
             'CPU Speed Limit': '100.00%',
             'ChasCnt': '1 (Single-Chassis System)',
             'Chassis': 'ISI36 (Isilon (CIDesigns) 36-Bay Chassis)',
             'Chassis Fan1 (ISI F1)': 7268.0,
             'Chassis Fan2 (ISI F2)': 7307.0,
             'Chassis Fan3 (ISI F3)': 7190.0,
             'Class': 'storage',
             'Comps': ['Chassis',
                       'CPU',
                       'Motherboard',
                       'NVRam',
                       'FlashDrive',
                       'Disk_Controller',
                       'Disk_Expander',
                       'Power_Supplies'],
             'Config': '912-111-231',
             'DskCtl': 'LSI3081E-HBA (LSI SAS3081E SAS Controller -- HBA) (8 ports)',
             'DskExp': 'VIT7156 (Vitesse 7156 Disk Expander)',
             'FlshDrv': 'None (No physical dongle supported) ((null))',
             'HWGen': 'MaunaLoa (MaunaLoa Hardware)',
             'IBType': 'ISI25208 (Isilon MT25208-based IB Card)',
             'IMB': 'Board Version 0x20f',
             'LCDver': 'NoriVFD (Noritake VFD)',
             'Mobo': 'SupMicX7DBU (SuperMicro X7DBU Motherboard)',
             'NVRam': 'MT25208 (Mellanox 25208 based Card) (492MB card) (size 515899392B)',
             'NetIF': 'em*4,ib*2 (4x Intel, 2x IB)',
             'PROC': 'Dual-proc, Quad-core',
             'Power Supplies OK': None,
             'Power Supply 1 Fan': 5376.0,
             'Power Supply 2 Fan': 5696.0,
             'Product': 'IQ 32000x-ssd',
             'PwrSupl': ['PS1 (type=Emerson, fw=v.01.00.00)',
                         'PS2 (type=Emerson, fw=v.01.00.00)'],
             'RAM': '17150812160 Bytes',
             'SerNo': 'S123456785K',
             'Series': 'x_series',
             'Temp Chassis 2 (ISI T2)': 24.0,
             'Temp Front Panel': 17.2,
             'Temp System': 27.0,
             'Temp Until CPU Throttle (CPU 0)': 46.0,
             'Temp Until CPU Throttle (CPU 1)': 46.0},
 'visi-93': {'CPU': 'GenuineIntel (2.33GHz, stepping 0x0001067a)',
             'CPU Operation (raw 0x88250000)': 'Normal',
             'CPU Speed Limit': '100.00%',
             'ChasCnt': '1 (Single-Chassis System)',
             'Chassis': 'ISI36 (Isilon (CIDesigns) 36-Bay Chassis)',
             'Chassis Fan1 (ISI F1)': 7387.0,
             'Chassis Fan2 (ISI F2)': 7152.0,
             'Chassis Fan3 (ISI F3)': 7152.0,
             'Class': 'storage',
             'Comps': ['Chassis',
                       'CPU',
                       'Motherboard',
                       'NVRam',
                       'FlashDrive',
                       'Disk_Controller',
                       'Disk_Expander',
                       'Power_Supplies'],
             'Config': '912-111-231',
             'DskCtl': 'LSI3081E-HBA (LSI SAS3081E SAS Controller -- HBA) (8 ports)',
             'DskExp': 'VIT7156 (Vitesse 7156 Disk Expander)',
             'FlshDrv': 'None (No physical dongle supported) ((null))',
             'HWGen': 'MaunaLoa (MaunaLoa Hardware)',
             'IBType': 'ISI25208 (Isilon MT25208-based IB Card)',
             'IMB': 'Board Version 0x20f',
             'LCDver': 'NoriVFD (Noritake VFD)',
             'Mobo': 'SupMicX7DBU (SuperMicro X7DBU Motherboard)',
             'NVRam': 'MT25208 (Mellanox 25208 based Card) (492MB card) (size 515899392B)',
             'NetIF': 'em*4,ib*2 (4x Intel, 2x IB)',
             'PROC': 'Dual-proc, Quad-core',
             'Power Supplies OK': None,
             'Power Supply 1 Fan': 8512.0,
             'Power Supply 2 Fan': 8512.0,
             'Product': 'IQ 32000x-ssd',
             'PwrSupl': ['PS1 (type=Emerson, fw=v.03.05.00)',
                         'PS2 (type=Emerson, fw=v.03.05.00)'],
             'RAM': '17150812160 Bytes',
             'SerNo': 'S987654321P',
             'Series': 'x_series',
             'Temp Chassis 2 (ISI T2)': 25.0,
             'Temp Front Panel': 17.4,
             'Temp System': 28.0,
             'Temp Until CPU Throttle (CPU 0)': 37.0,
             'Temp Until CPU Throttle (CPU 1)': 38.0}}

编辑:现在通过形成一个数组来处理给定“键”的多次出现(例如:PwrSupl)。