def _method_callback(self, invocation, interface_name, method_name, parameters): """The callback for a DBus call. :param invocation: an invocation of the DBus call :param interface_name: a DBus interface name :param method_name: a DBus method name :param parameters: a variant of DBus arguments """ try: member = self._find_member_spec( interface_name, method_name ) result = self._handle_call( interface_name, method_name, *unwrap_variant(parameters) ) except Exception as error: # pylint: disable=broad-except self._handle_method_error( invocation, interface_name, method_name, error ) else: self._handle_method_result( invocation, member, result )
def _get_property_value(self, property_spec): """Get a value of the DBus property.""" variant = self._call_method("org.freedesktop.DBus.Properties", "Get", "(ss)", "(v)", property_spec.interface_name, property_spec.name) return unwrap_variant(variant)
def set_data_variant(self, obj, variant): """Set the data attribute from a variant. :param obj: a data object :param variant: a variant """ self.set_data(obj, unwrap_variant(variant))
def _test_native(self, variants, values): """Test native values of variants.""" for variant, value in zip(variants, values): self.assertEqual(get_native(variant), value) self.assertEqual(get_native(tuple(variants)), tuple(values)) self.assertEqual(get_native(list(variants)), list(values)) self.assertEqual(get_native(dict(enumerate(variants))), dict(enumerate(values))) variant = get_variant(Tuple[Variant, Variant, Variant, Variant], tuple(variants)) self.assertEqual(unwrap_variant(variant), tuple(variants)) variant = get_variant(List[Variant], list(variants)) self.assertEqual(unwrap_variant(variant), list(variants)) variant = get_variant(Dict[Int, Variant], dict(enumerate(variants))) self.assertEqual(unwrap_variant(variant), dict(enumerate(variants)))
def get_devices(self): if self.adapter is None: return {"devices":[], "scanning": False } om = self.bus.get_proxy(service_name="org.bluez", object_path="/", interface_name=OBJECT_MANAGER_INTERFACE) objs = om.GetManagedObjects() devices = [] for path in objs: obj = objs[path] if DEVICE_INTERFACE in obj: dev = obj[DEVICE_INTERFACE] devices.append({ "path" : path, "address" : dt.unwrap_variant(dev["Address"]), "alias": dt.unwrap_variant(dev["Alias"]), "paired": dt.unwrap_variant(dev["Paired"]), "trusted": dt.unwrap_variant(dev["Trusted"]), "connected": dt.unwrap_variant(dev["Connected"]), "host" : INPUT_HOST_INTERFACE in obj }) return {"devices": devices, "scanning":self.adapter.Discovering}
def _set_property(self, interface_name, property_name, property_value): """The default handler of the Set method. :param interface_name: an interface name :param property_name: a property name :param property_value: a variant with a property value """ member = self._find_member_spec(interface_name, property_name) if not member.writable: raise AttributeError("The property {}.{} is not writable.".format( interface_name, property_name)) setattr(self._object, property_name, unwrap_variant(property_value))
def _do_check(self): self.clear_errors() StorageCheckHandler.errors = [] StorageCheckHandler.warnings = [] try: log.debug("Generating updated storage configuration") task_path = self._partitioning.ConfigureWithTask() task_proxy = STORAGE.get_proxy(task_path) sync_run_task(task_proxy) except BootloaderConfigurationError as e: log.error("Storage configuration failed: %s", e) StorageCheckHandler.errors = [str(e)] reset_bootloader() else: log.debug("Checking storage configuration...") task_path = self._partitioning.ValidateWithTask() task_proxy = STORAGE.get_proxy(task_path) sync_run_task(task_proxy) result = unwrap_variant(task_proxy.GetResult()) report = ValidationReport.from_structure(result) log.debug("Validation has been completed: %s", report) StorageCheckHandler.errors = report.error_messages StorageCheckHandler.warnings = report.warning_messages if report.is_valid(): self._storage_module.ApplyPartitioning( get_object_path(self._partitioning)) if self.errors: self.set_warning( _("Error checking storage configuration. <a href=\"\">Click for details</a> or press Done again to continue." )) elif self.warnings: self.set_warning( _("Warning checking storage configuration. <a href=\"\">Click for details</a> or press Done again to continue." )) # on_info_bar_clicked requires self._error to be set, so set it to the # list of all errors and warnings that storage checking found. self._error = "\n".join(self.errors + self.warnings) return self._error == ""
def _handle_method_result(self, result): """Handle a result of a DBus call. :param result: a variant tuple """ # Unwrap a variant tuple. values = unwrap_variant(result) # Return None if there are no values. if not values: return None # Return one value. if len(values) == 1: return values[0] # Return multiple values. return values
def _test_variant(self, type_hint, expected_string, value): """Create a variant.""" # Create a variant from a type hint. v1 = get_variant(type_hint, value) self.assertTrue(isinstance(v1, Variant)) self.assertEqual(v1.format_string, expected_string) self.assertEqual(v1.unpack(), value) self.assertEqual(unwrap_variant(v1), value) v2 = Variant(expected_string, value) self.assertTrue(v2.equal(v1)) self.assertEqual(get_native(v1), value) self.assertEqual(get_native(v1), get_native(v2)) self.assertEqual(get_native(value), value) # Create a variant from a type string. v3 = get_variant(expected_string, value) self.assertTrue(isinstance(v3, Variant)) self.assertTrue(v2.equal(v3))
def apply_partitioning(partitioning, show_message_cb, reset_storage_cb): """Apply the given partitioning. :param partitioning: a DBus proxy of a partitioning :param show_message_cb: a callback for showing a message :param reset_storage_cb: a callback for resetting the storage :return: an instance of ValidationReport """ log.debug("Applying partitioning") report = ValidationReport() try: show_message_cb(_("Saving storage configuration...")) task_path = partitioning.ConfigureWithTask() task_proxy = STORAGE.get_proxy(task_path) sync_run_task(task_proxy) except StorageConfigurationError as e: show_message_cb(_("Failed to save storage configuration")) report.error_messages.append(str(e)) reset_bootloader() reset_storage_cb() except BootloaderConfigurationError as e: show_message_cb(_("Failed to save boot loader configuration")) report.error_messages.append(str(e)) reset_bootloader() else: show_message_cb(_("Checking storage configuration...")) task_path = partitioning.ValidateWithTask() task_proxy = STORAGE.get_proxy(task_path) sync_run_task(task_proxy) result = unwrap_variant(task_proxy.GetResult()) report = ValidationReport.from_structure(result) log.debug("Validation has been completed: %s", report) if report.is_valid(): storage_proxy = STORAGE.get_proxy() storage_proxy.ApplyPartitioning(get_object_path(partitioning)) log.debug("Partitioning has been applied.") return report
def process_discovery_result(self, task_proxy): """Process the result of the task. :param task_proxy: a task """ # Stop the spinner. self._discoverySpinner.stop() self._cancelButton.set_sensitive(True) try: # Finish the task task_proxy.Finish() except StorageDiscoveryError as e: # Discovery has failed, show the error. self._set_configure_sensitive(True) self._discoveryErrorLabel.set_text(str(e)) self._conditionNotebook.set_current_page(2) else: nodes = unwrap_variant(task_proxy.GetResult()) # Discovery succeeded. # Populate the node store. self._discovered_nodes = Node.from_structure_list(nodes) for node in self._discovered_nodes: portal = "%s:%s" % (node.address, node.port) self._store.append( [False, True, node.name, node.net_ifacename, portal]) # We should select the first node by default. self._store[0][0] = True # Kick the user on over to that subscreen. self._iscsiNotebook.set_current_page(1) # If some form of login credentials were used for discovery, # default to using the same for login. if self._authTypeCombo.get_active() != 0: self._loginAuthTypeCombo.set_active(3)
def _signal_callback(self, parameters, callback): """A callback that is called when a DBus signal is emitted.""" callback(*unwrap_variant(parameters))