Remove find_dbus_interfaces
Waffling yet again on where this should be located. Move back
to the mapper to discourage other applications from introspection
and encourage use of the mapper.
Change-Id: I78dc815baeb46d6b2d155d02318fba230d7420d2
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/obmc/dbuslib/introspection.py b/obmc/dbuslib/introspection.py
index 805197d..9ec9c05 100644
--- a/obmc/dbuslib/introspection.py
+++ b/obmc/dbuslib/introspection.py
@@ -16,7 +16,6 @@
import xml.etree.ElementTree as ET
import dbus
-import obmc.dbuslib.enums
class IntrospectionNodeParser:
@@ -135,105 +134,3 @@
items.update(callback(path + k, parser))
return items
-
-
-def find_dbus_interfaces(conn, service, path, match):
- class _FindInterfaces(object):
- def __init__(self):
- self.results = {}
-
- @staticmethod
- def _get_object(path):
- try:
- return conn.get_object(service, path, introspect=False)
- except dbus.exceptions.DBusException, e:
- if e.get_dbus_name() in [
- obmc.dbuslib.enums.DBUS_UNKNOWN_SERVICE,
- obmc.dbuslib.enums.DBUS_NO_REPLY]:
- print "Warning: Introspection failure: " \
- "service `%s` is not running" % (service)
- return None
- raise
-
- @staticmethod
- def _invoke_method(path, iface, method, *args):
- obj = _FindInterfaces._get_object(path)
- if not obj:
- return None
-
- iface = dbus.Interface(obj, iface)
- try:
- f = getattr(iface, method)
- return f(*args)
- except dbus.exceptions.DBusException, e:
- if e.get_dbus_name() in [
- obmc.dbuslib.enums.DBUS_UNKNOWN_SERVICE,
- obmc.dbuslib.enums.DBUS_NO_REPLY]:
- print "Warning: Introspection failure: " \
- "service `%s` did not reply to "\
- "method call on %s" % (service, path)
- return None
- raise
-
- @staticmethod
- def _introspect(path):
- return _FindInterfaces._invoke_method(
- path,
- dbus.INTROSPECTABLE_IFACE,
- 'Introspect')
-
- @staticmethod
- def _get_managed_objects(om):
- return _FindInterfaces._invoke_method(
- om,
- dbus.BUS_DAEMON_IFACE + '.ObjectManager',
- 'GetManagedObjects')
-
- @staticmethod
- def _to_path(elements):
- return '/' + '/'.join(elements)
-
- @staticmethod
- def _to_path_elements(path):
- return filter(bool, path.split('/'))
-
- def __call__(self, path):
- self.results = {}
- self._find_interfaces(path)
- return self.results
-
- @staticmethod
- def _match(iface):
- return iface == dbus.BUS_DAEMON_IFACE + '.ObjectManager' \
- or match(iface)
-
- def _find_interfaces(self, path):
- path_elements = self._to_path_elements(path)
- path = self._to_path(path_elements)
- data = self._introspect(path)
- if data is None:
- return
-
- root = ET.fromstring(data)
- ifaces = filter(
- self._match,
- [x.attrib.get('name') for x in root.findall('interface')])
- self.results[path] = ifaces
-
- if dbus.BUS_DAEMON_IFACE + '.ObjectManager' in ifaces:
- objs = self._get_managed_objects(path)
- for k, v in objs.iteritems():
- self.results[k] = v
- else:
- children = filter(
- bool,
- [x.attrib.get('name') for x in root.findall('node')])
- children = [
- self._to_path(
- path_elements + self._to_path_elements(x))
- for x in sorted(children)]
- for child in children:
- if child not in self.results:
- self._find_interfaces(child)
-
- return _FindInterfaces()(path)