示例#1
0
    def store_drives(raw_drives):
        # takes as input raw_drives from the blkid command
        # Returns a list of Drive objects

        connected_drives = []
        for i in range(len(raw_drives)):
            temp_drive = Drive()
            temp_raw_drive = raw_drives[i].split()
            for attribute in temp_raw_drive:
                if '/dev' in attribute:
                    attribute = list(attribute)
                    attribute.pop()
                    attribute = ''.join(attribute)
                    temp_drive.set_source(attribute)
                elif 'TYPE' in attribute:
                    temp_drive.set_fs(attribute)
            connected_drives.append(temp_drive)
        return connected_drives
示例#2
0
    def __init__(self):
        proc = subprocess.Popen('sudo blkid',
                                stdout=subprocess.PIPE,
                                shell=True)
        (drives, err) = proc.communicate()
        drives = drives.decode('utf-8').split('\n')

        connected_drives = []
        for i in range(len(drives)):
            temp_drive = Drive()
            temp_source = ''
            temp_fs = ''
            temp_raw_drive = drives[i].split()
            for attribute in temp_raw_drive:
                if '/dev' in attribute:
                    attribute = list(attribute)
                    attribute.pop()
                    attribute = ''.join(attribute)
                    temp_drive.set_source(attribute)
                elif 'TYPE' in attribute:
                    temp_drive.set_fs(attribute)
            connected_drives.append(temp_drive)
        self.drives = connected_drives