From 2503bd6faa30b8580547800ac1c6d8592789330f Mon Sep 17 00:00:00 2001 From: Brad Bishop Date: Wed, 16 Dec 2015 17:56:12 -0500 Subject: Add schema endpoint Navigate to //schema to get a dbus introspection dump of . --- obmc-rest | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/obmc-rest b/obmc-rest index c5ba8dc..7c8e21a 100644 --- a/obmc-rest +++ b/obmc-rest @@ -306,6 +306,36 @@ class PropertyHandler(RouteHandler): continue return prop, i +class SchemaHandler(RouteHandler): + verbs = ['GET'] + rules = '/schema' + + def __init__(self, app, bus): + super(SchemaHandler, self).__init__( + app, bus, self.verbs, self.rules) + + def find(self, path): + return self.try_mapper_call( + self.mapper.get_object, + path = path) + + def setup(self, path): + request.route_data['map'] = self.find(path) + + def do_get(self, path): + schema = {} + for x in request.route_data['map'].iterkeys(): + obj = self.bus.get_object( + x, path, introspect = False) + iface = dbus.Interface(obj, dbus.INTROSPECTABLE_IFACE) + data = iface.Introspect() + parser = IntrospectionNodeParser( + ElementTree.fromstring(data)) + for x,y in parser.get_interfaces().iteritems(): + schema[x] = y + + return schema + class InstanceHandler(RouteHandler): verbs = ['GET', 'PUT', 'DELETE'] rules = '' @@ -544,6 +574,7 @@ class RestApp(Bottle): self.list_handler = ListHandler(self, self.bus) self.method_handler = MethodHandler(self, self.bus) self.property_handler = PropertyHandler(self, self.bus) + self.schema_handler = SchemaHandler(self, self.bus) self.instance_handler = InstanceHandler(self, self.bus) def install_handlers(self): @@ -552,6 +583,7 @@ class RestApp(Bottle): self.list_handler.install() self.method_handler.install() self.property_handler.install() + self.schema_handler.install() # this has to come last, since it matches everything self.instance_handler.install() -- cgit v1.2.1