def list_disks(self): ds = disks.get_disks() # Do not refresh the list of disks if nothing has changed, because it de-selects the selection if ds != self.old_ds: self.disk_listwidget.clear() for d in ds: di = disks.get_disk(d) # print(di) # print(di.get("descr")) # print(di.keys()) # Only show disks that are above minimum_target_disk_size and are writable available_bytes = int(di.get("mediasize").split(" ")[0]) # For now, we don't show cd* but once we add burning capabilities we may want to un-blacklist them # TODO: Identify the disk the Live system is running from, and don't offer that if (available_bytes >= wizard.required_mib_on_disk) and di.get("geomname").startswith("cd") == False: # item.setTextAlignment() title = "%s on %s (%s GiB)" % (di.get("descr"), di.get("geomname"), f"{(available_bytes // (2 ** 30)):,}") if di.get("geomname").startswith("cd") == True: # TODO: Add burning powers item = QtWidgets.QListWidgetItem(QtGui.QIcon.fromTheme('drive-optical'), title) else: item = QtWidgets.QListWidgetItem(QtGui.QIcon.fromTheme('drive-harddisk'), title) # TODO: drive-removable-media for removable drives; how to detect these? self.disk_listwidget.addItem(item) self.old_ds = ds
def list_disks(self): ds = disks.get_disks() # Do not refresh the list of disks if nothing has changed, because it de-selects the selection if ds != self.old_ds: self.disk_listwidget.clear() for d in ds: di = disks.get_disk(d) # print(di) # print(di.get("descr")) # print(di.keys()) available_bytes = int(di.get("mediasize").split(" ")[0]) if di.get("geomname").startswith("cd") == False: # item.setTextAlignment() title = "%s on %s (%s GiB)" % ( di.get("descr"), di.get("geomname"), f"{(available_bytes // (2 ** 30)):,}") if di.get("geomname").startswith("cd") == True: # TODO: Add burning powers item = QtWidgets.QListWidgetItem( QtGui.QIcon.fromTheme('drive-optical'), title) elif di.get("geomname").startswith("da") == True: item = QtWidgets.QListWidgetItem( QtGui.QIcon.fromTheme('drive-removable-media'), title) else: item = QtWidgets.QListWidgetItem( QtGui.QIcon.fromTheme('drive-harddisk'), title) self.disk_listwidget.addItem(item) self.old_ds = ds
def main(): threading.Timer(SENT_INTERVAL, main).start() device = [{ 'id': DEVICE_FRIENDLY_NAME, 'sensors': get_memory() + get_disks() + get_battery() + get_networks() + get_internet_speed() + get_ohm_sensors() }] connection = http.client.HTTPSConnection(UBEAC_URL) connection.request('POST', GATEWAY_URL, json.dumps(device)) response = connection.getresponse() print(response.read().decode())
def populate_geom_tree(self): ds = disks.get_disks() for d in ds: di = disks.get_disk(d) print(di) print(di.get("descr")) item = QTreeWidgetItem() item.setText(0, di["descr"]) item.__setattr__("di", di) if di.get("geomname").startswith("cd") == True: item.setIcon(0, QIcon.fromTheme('drive-optical')) elif di.get("geomname").startswith("da") == True: item.setIcon(0, QIcon.fromTheme('drive-removable-media')) else: item.setIcon(0, QIcon.fromTheme('drive-harddisk')) self.geomTreeWidget.addTopLevelItem(item) # Add the partitions that are on the hardware devices as children partitions = disks.get_partitions(di["name"]) if len(partitions) > 0: partitions.pop(0) for p in partitions: if p.name == None: continue child = QTreeWidgetItem() child.setText(0, (p.name + " " + p.type_or_label)) child.setFlags( Qt.ItemIsSelectable) # Make it greyed out here for now item.addChild(child) # In addition to hardware devices, also show ZFS zpools # Not entirely sure if this is the best place to do this in the UI,# # but zpools are neither strictly a child nor a parent of hardware devices... zpools = disks.get_zpools() if len(zpools) > 0: for zp in zpools: item = QTreeWidgetItem() item.setText(0, zp.name) if zp.health == "ONLINE": item.setIcon(0, QIcon.fromTheme('emblem-colors-green')) else: item.setIcon(0, QIcon.fromTheme('emblem-colors-white')) self.geomTreeWidget.addTopLevelItem(item) # Show the datasets (volumes, snapshots, file systems) on the zpool datasets = disks.get_datasets(zp.name) for dataset in datasets: child = QTreeWidgetItem() child.setText(0, (dataset)) child.setFlags( Qt.ItemIsSelectable) # Make it greyed out here for now item.addChild(child)
def isComplete(self): if wizard.user_agreed_to_erase == True: ds = disks.get_disks() # Given a clear text label, get back the rdX for d in self.old_ds: di = disks.get_disk(d) searchstring = " on " + str(di.get("geomname")) + " " print(searchstring) if len(self.disk_listwidget.selectedItems()) < 1: return False if searchstring in self.disk_listwidget.selectedItems()[0].text(): wizard.selected_disk_device = str(di.get("geomname")) self.timer.stop() # FIXME: This does not belong here, but cleanupPage() gets called only # if the user goes back, not when they go forward... return True selected_disk_device = None return False
def isComplete(self): ds = disks.get_disks() # Given a clear text label, get back the rdX # TODO: Use __setattr__() and __getattribute__() instead; see above for an example on how to use those for d in self.old_ds: di = disks.get_disk(d) searchstring = " on " + str(di.get("geomname")) + " " print(searchstring) if len(self.disk_listwidget.selectedItems()) < 1: return False if searchstring in self.disk_listwidget.selectedItems()[0].text(): wizard.selected_disk_device = str(di.get("geomname")) self.timer.stop( ) # FIXME: This does not belong here, but cleanupPage() gets called only # if the user goes back, not when they go forward... return True selected_disk_device = None return False
def get_sensors_data(self): self.sensors_data = { "cpu_load": str(get_cpus()[0]['data']) + '%', "temperature": get_temperatures()[0]['data']['Current'], "network_speed": get_networks()[0]['data'], "memory_space": { 'Usage': str(get_memory()[1]['data']) + '%', 'Total': str(get_memory()[0]['data']['Total'] / 1000) + 'GB', 'Used': str(get_memory()[0]['data']['Used'] / 1000) + 'GB', 'Available': str(get_memory()[0]['data']['Available'] / 1000) + 'GB', }, "swap_space": { 'Usage': str(get_memory()[3]['data']) + '%', 'Total': str(get_memory()[2]['data']['Total'] / 1000) + 'GB', 'Used': str(get_memory()[2]['data']['Used'] / 1000) + 'GB', 'Free': str(get_memory()[2]['data']['Free'] / 1000) + 'GB' }, "disk_usage": get_disks() } return self.sensors_data
def list_disks(self): ds = disks.get_disks() if "/dev/" + wizard.selected_disk_device not in ds: print("Device was unplugged, exiting") self.timer.stop() sys.exit(0)
#!/usr/local/bin/python2.7 import os import sys import subprocess from pprint import pprint from disks import get_disks MAX_THREADS = 4 if len(sys.argv) < 2: raise SystemExit('Usage: %s OUTPUT_DIR' % sys.argv[0]) out_dir = sys.argv[1] def backup_geli_metadata(disk, serial): try: subprocess.check_output(['geli', 'backup', '/dev/%sp2' % disk, '%s' % os.path.join(out_dir, 'geli_%s.meta' % serial)]) except: try: subprocess.check_output(['geli', 'backup', '/dev/%sp1' % disk, '%s' % os.path.join(out_dir, 'geli_%s.meta' % serial)]) except: pass disks = get_disks() _ = [backup_geli_metadata(disk, serial) for disk, serial in disks.iteritems()]
TIMEOUT = 10 # minutes CAMCONTROL = '/sbin/camcontrol' # PK2234P9JT4Y5Y parser = argparse.ArgumentParser( description='Run badblocks and smart tests on spares') parser.add_argument('spares', metavar='SERIAL', nargs='+', help='the serial number of a spare') args = parser.parse_args() spares = set(args.spares) disks = [disk for disk, serial in get_disks().iteritems() if serial in spares] procs = [ (subprocess.Popen(['smartctl', '-n', 'standby', '-a', '/dev/%s' % disk], stdout=subprocess.PIPE), disk) for disk in disks ] for proc, disk in procs: out = proc.communicate()[0].strip() #print proc.returncode #print out.split('\n')[-1].lower() if (not (proc.returncode & 0x2) or not out.split('\n') [-1].lower().startswith('device is in standby mode')): subprocess.check_call( [CAMCONTROL, 'standby',