def test_dbus_signal(self): """test DBusSignal class""" obj_node = DBusNode(self.name, self.object_path, self.node_info) obj_iface = DBusInterface(obj_node, obj_node.node_info.interfaces[0]) obj_sig = DBusSignal(obj_iface, obj_iface.iface_info.signals[0]) self.assertEqual(obj_sig.name, self.name) self.assertEqual(obj_sig.object_path, self.object_path)
def test_dbus_interface(self): """test DBusInterface class""" obj_node = DBusNode(self.name, self.object_path, self.node_info) obj_iface = DBusInterface(obj_node, obj_node.node_info.interfaces[0]) self.assertEqual(obj_iface.name, self.name) self.assertEqual(obj_iface.object_path, self.object_path) self.assertEqual(len(obj_iface.iface_info.methods), 1) self.assertEqual(len(obj_iface.iface_info.properties), 3) self.assertEqual(len(obj_iface.iface_info.signals), 1)
def __dbus_node_introspect_cb(self, connection, result_async, object_path): """callback when Introspect dbus function call finished""" try: res = connection.call_finish(result_async) except Exception as e: # got an exception (eg dbus timeout). show the exception self.__messagedialog.set_title("DBus Exception") self.__messagedialog.set_property("text", "%s : %s" % (self.name, str(e))) self.__messagedialog.run() self.__messagedialog.destroy() else: # we got a valid result from dbus call! Create nodes and add to treemodel node_info = Gio.DBusNodeInfo.new_for_xml(res[0]) # create a GObject node and add to tree-model tree_iter = None if len(node_info.interfaces) > 0: node_obj = DBusNode(self.name, object_path, node_info) tree_iter = self.__treemodel.append( tree_iter, ["%s" % object_path, node_obj]) # tree_iter = self.__treemodel.append(tree_iter, ["Hallo", None]) # append interfaces to tree model name_iter = self.__treemodel.append( tree_iter, ["<b>Interfaces</b>", None]) iface_member_names = [ "methods", "signals", "properties", "annotations" ] for iface in node_info.interfaces: iface_obj = DBusInterface(node_obj, iface) iface_iter = self.__treemodel.append( name_iter, ["%s" % iface.name, iface_obj]) iface_get_members = partial(getattr, iface) iface_set_members = partial(self.__dbus_set_tree_members, iface, iface_obj, iface_iter) for member in filter(iface_get_members, iface_member_names): iface_set_members(member) # are more nodes left? if len(node_info.nodes) > 0: for node in node_info.nodes: # node_iter = self.__treemodel.append(tree_iter, [node.path, node]) if object_path == "/": object_path = "" object_path_new = object_path + "/" + node.path self.__dbus_node_introspect(object_path_new) else: # no nodes left. we finished the introspection self.__spinner.stop() self.__spinner.set_visible(False) # update name, unique name, ... self.__label_name.set_text(self.name) self.__label_unique_name.set_text(self.unique_name) self.introspect_box.show_all()
def test_dbus_property(self): """test DBusProperty class""" obj_node = DBusNode(self.name, self.object_path, self.node_info) obj_iface = DBusInterface(obj_node, obj_node.node_info.interfaces[0]) obj_prop = DBusProperty(obj_iface, obj_iface.iface_info.properties[0]) self.assertEqual(obj_prop.name, self.name) self.assertEqual(obj_prop.object_path, self.object_path) # get the markup string with value for struct prop (see bgo #702593) obj_prop = DBusProperty(obj_iface, obj_iface.iface_info.properties[2]) obj_prop.value = ("string", 1, 2) self.assertIn("'string', 1, 2", obj_prop.markup_str)
def __dbus_node_introspect_cb(self, connection, result_async, object_path): """callback when Introspect dbus function call finished""" try: res = connection.call_finish(result_async) except Exception as e: # got an exception (eg dbus timeout). show the exception self.__messagedialog.set_title("DBus Exception") self.__messagedialog.set_property("text", "%s : %s" % (self.name, str(e))) self.__messagedialog.run() self.__messagedialog.destroy() else: # we got a valid result from dbus call! Create nodes and add to treemodel node_info = Gio.DBusNodeInfo.new_for_xml(res[0]) # create a GObject node and add to tree-model tree_iter = None if len(node_info.interfaces) > 0: node_obj = DBusNode(self.name, object_path, node_info) tree_iter = self.__treemodel.append( tree_iter, ["%s" % object_path, node_obj]) # tree_iter = self.__treemodel.append(tree_iter, ["Hallo", None]) # append interfaces to tree model name_iter = self.__treemodel.append( tree_iter, ["<b>Interfaces</b>", None]) for iface in node_info.interfaces: iface_obj = DBusInterface(node_obj, iface) iface_iter = self.__treemodel.append( name_iter, ["%s" % iface.name, iface_obj]) # interface methods if len(iface.methods) > 0: iface_methods_iter = self.__treemodel.append( iface_iter, ["<b>Methods</b>", None]) for iface_method in iface.methods: method_obj = DBusMethod(iface_obj, iface_method) self.__treemodel.append( iface_methods_iter, ["%s" % method_obj.markup_str, method_obj]) # interface signals if len(iface.signals) > 0: iface_signals_iter = self.__treemodel.append( iface_iter, ["<b>Signals</b>", None]) for iface_signal in iface.signals: signal_obj = DBusSignal(iface_obj, iface_signal) self.__treemodel.append( iface_signals_iter, ["%s" % signal_obj.markup_str, signal_obj]) # interface properties if len(iface.properties) > 0: iface_properties_iter = self.__treemodel.append( iface_iter, ["<b>Properties</b>", None]) for iface_property in iface.properties: property_obj = DBusProperty( iface_obj, iface_property) self.__treemodel.append( iface_properties_iter, ["%s" % property_obj.markup_str, property_obj]) # interface annotations if len(iface.annotations) > 0: iface_annotations_iter = self.__treemodel.append( iface_iter, ["<b>Annotations</b>", None]) for iface_annotation in iface.annotations: annotation_obj = DBusAnnotation( iface_obj, iface_annotation) self.__treemodel.append(iface_annotations_iter, [ "%s" % (annotation_obj.markup_str), annotation_obj ]) # are more nodes left? if len(node_info.nodes) > 0: for node in node_info.nodes: # node_iter = self.__treemodel.append(tree_iter, [node.path, node]) if object_path == "/": object_path = "" object_path_new = object_path + "/" + node.path self.__dbus_node_introspect(object_path_new) else: # no nodes left. we finished the introspection self.__spinner.stop() self.__spinner.set_visible(False) # update name, unique name, ... self.__label_name.set_text(self.name) self.__label_unique_name.set_text(self.unique_name) self.introspect_box.show_all()
def test_dbus_node_info(self): """test DBusNode class""" obj_node = DBusNode(self.name, self.object_path, self.node_info) self.assertEqual(obj_node.name, self.name) self.assertEqual(obj_node.object_path, self.object_path) self.assertEqual(len(obj_node.node_info.interfaces), 1)