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 ('M' in rawusedstring) or ('m' in rawusedstring):
         this_drive.used = usedfloat
     elif ('K' in rawusedstring) or ('k' in rawusedstring):
         this_drive.used = usedfloat / 1024
     else:
         this_drive.used = -2
 else:
     if rawusedstring == "0":
         this_drive.used = 0
     else:
         this_drive.used = -2
 
 if len(rawfreestring) > 1:
     freefloat = float(rawfreestring[:-1])
     if ('T' in rawfreestring) or ('t' in rawfreestring):
         this_drive.free = freefloat * 1024 * 1024
     elif ('G' in rawfreestring) or ('g' in rawfreestring):
         this_drive.free = freefloat * 1024
     elif ('M' in rawfreestring) or ('m' in rawfreestring):
         this_drive.free = freefloat
     elif ('K' in rawfreestring) or ('k' in rawfreestring):
         this_drive.free = freefloat / 1024
     else:
         this_drive.free = -2
 else:
     if rawfreestring == "0":
         this_drive.free = 0
     else:
         this_drive.free = -2
 
 drives.append(this_drive)