def drivesToJson()

in fiosynth_lib/fiosynth.py [0:0]


def drivesToJson(dut):
    drives = {}
    TYPE = 5
    DEVICE = 0
    maxcol = max(TYPE, DEVICE)
    output = None
    if dut.inLocalMode():
        proc = subprocess.Popen(["/bin/lsblk", "-rnbp"], stdout=subprocess.PIPE)
        output = proc.stdout.read()
        output = output.decode("utf-8")
    else:
        sshProc = getSshProc(dut)
        output, err = sshProc.communicate("/bin/lsblk -rnbp\n")
    for line in output.splitlines():
        bits = line.split()
        if len(bits) > maxcol:
            # drive_type = bits[TYPE].decode("utf-8")
            drive_type = bits[TYPE]
            # drive_device = bits[DEVICE].decode("utf-8")
            drive_device = bits[DEVICE]
            drives.setdefault(drive_type, [])
            drives[drive_type].append(drive_device)
    return json.dumps(drives)