import os


class Disk:
    def __init__(self, model, serial, firmware_rev, size):
        self.model = model
        self.serial = serial
        self.firmware_rev = firmware_rev
        self.size = int(size * 512 / 1024 / 1024 / 1024)


disk_path = "/sys/block"


def get():
    disks = []
    for root, dirs, files in os.walk(disk_path):
        for dir in dirs:
            if "loop" in dir:
                continue
            else:
                size = None
                model = None
                serial = None
                firmware_rev = None
                size_f = os.path.join(root, dir, "size")
                model_f = os.path.join(root, dir, "device", "model")
                serial_f = os.path.join(root, dir, "device", "serial")
                firmware_rev_f = os.path.join(root, dir, "device", "firmware_rev")
                sata_firmware_rev_f = os.path.join(root, dir, "device", "rev")

                if os.path.exists(size_f):
                    with open(size_f) as f:
                        size = int(f.readline().strip())
                if os.path.exists(model_f):
                    with open(model_f) as f:
                        model = f.readline().strip()
                if os.path.exists(serial_f):
                    with open(serial_f) as f:
                        serial = f.readline().strip()
                if os.path.exists(firmware_rev_f):
                    with open(firmware_rev_f) as f:
                        firmware_rev = f.readline().strip()
                else:
                    with open(sata_firmware_rev_f) as f:
                        firmware_rev = f.readline().strip()

                disks.append(Disk(model, serial, firmware_rev, size))
    return disks
