def jsonify()

in pcicrawler/cli.py [0:0]


def jsonify(dev, hexify=False, vpd=False, aer=False):
    jd = dev._asdict()
    exptype = dev.express_type
    explink = dev.express_link
    slot = dev.express_slot
    location = dev.location
    del jd['device_name']
    jd['addr'] = dev.device_name
    if exptype:
        jd['express_type'] = str(exptype)
    if explink:
        jd.update(explink._asdict())
    if slot:
        jd.update(slot._asdict())
    if location:
        jd['location'] = location
    path = [d.device_name for d in dev.get_path()[1:]]
    jd['path'] = path
    if hexify:
        for pad, key in (
                (4, 'vendor_id'),
                (4, 'device_id'),
                (4, 'subsystem_vendor'),
                (4, 'subsystem_device'),
                (6, 'class_id')):
            jd[key] = '{:0{pad}x}'.format(jd[key], pad=pad)
    if vpd:
        if dev.vpd:
            jd['vpd'] = dev.vpd
    if aer:
        aer_info = dev.express_aer
        if aer_info:
            jd['aer'] = aer_info
    return jd