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