Esempio n. 1
0
def get_hardware_data():
    """
    Collects hardware data about the different drives to be analyzed.
    Different methods for Linux, Windows and Mac OS used.
    """
    drives = []
    if sys.platform in ('Windows',  'win32', 'cygwin', 'nt'):  # windows approach
        drive_list = win32api.GetLogicalDriveStrings()
        drive_list = drive_list.split('\000')[:-1]
        for founddrive in drive_list:
            this_drive = Drive()
            drive_info = windows_disk_look(founddrive)
            this_drive.disk_code = founddrive
            this_drive.size = drive_info[0]  # EACH OF THESE STORED IN MEGABYTES
            this_drive.free = drive_info[1]
            this_drive.used = drive_info[0] - drive_info[1]
            drives.append(this_drive)

    elif sys.platform in ('linux',  'linux2', 'linux3', 'darwin'):  # POSIX approach
        system_drive_string = ""
        df = subprocess.Popen(["df", "-H"], stdout=subprocess.PIPE)  # use df to get disk info
        df_results = df.communicate()[0].decode("utf-8")
        df_results = df_results.replace(',', '.')
        df_array = df_results.splitlines()

        if sys.platform in ('linux',  'linux2',  'linux3'):
            system_drive_string = "/dev/sd"  # linux disk prefix
        elif sys.platform in 'darwin':
            system_drive_string = "/dev/disk"  # mac disk prefix
Esempio n. 2
0
    elif sys.platform in ('linux',  'linux2', 'linux3', 'darwin'):  # POSIX approach
        system_drive_string = ""
        df = subprocess.Popen(["df", "-H"], stdout=subprocess.PIPE)  # use df to get disk info
        df_results = df.communicate()[0].decode("utf-8")
        df_results = df_results.replace(',', '.')
        df_array = df_results.splitlines()

        if sys.platform in ('linux',  'linux2',  'linux3'):
            system_drive_string = "/dev/sd"  # linux disk prefix
        elif sys.platform in 'darwin':
            system_drive_string = "/dev/disk"  # mac disk prefix

for line in df_array:
            if system_drive_string in line:
                this_drive = Drive()
                values = line.split(" ")
                newvalues = []

                for v in values:
                    if (len(v) > 0):
                        newvalues.append(v)

                this_drive.disk_code = newvalues[0]
                rawsizestring = newvalues[1]
                rawusedstring = newvalues[2]
                rawfreestring = newvalues[3]

                if len(rawsizestring) > 1:
                    sizefloat = float(rawsizestring[:-1])
                    if ('T' in rawsizestring) or ('t' in rawsizestring):  # EACH OF THESE STORED IN MEGABYTES