#! /usr/bin/env python import sys try: import xml.etree.cElementTree as etree except: import xml.etree.ElementTree as etree def child (elem, name): for e in elem.getchildren(): if e.tag == name: return e return None def children (elem, name=None): l = elem.getchildren() if name: l = [e for e in l if e.tag == name] return l xml = etree.parse(sys.argv[1]) for schema in child(xml.getroot(), "schemalist").getchildren(): e = child(schema, "short") if e is not None: schema.remove(e) e = child(schema, "long") if e is not None: schema.remove(e) for locale in children(schema, "locale"): # One locale must exist so leave C locale... a = locale.attrib.get("name") if a == 'C': continue e = child(locale, "default") if e is None: schema.remove(locale) else: e = child(locale, "short") if e is not None: locale.remove(e) e = child(locale, "long") if e is not None: locale.remove(e) From c4436fd42f2936e5fb0f95434d06e45aa9959ca0 Mon Sep 17 00:00:00 2001 From: Simon Busch <simon.busch@lge.com> Date: Wed, 9 Apr 2014 13:18:33 +0200 Subject: [PATCH] Add functionality to add own objects to internal object list In some case the tests might want to create dynamically dbus objects which extended functionality from own class definitions within templates. In such cases we need to register those objects with the internal object manager of dbusmock. Signed-off-by: Simon Busch <simon.busch@lge.com> --- dbusmock/__init__.py | 4 ++-- dbusmock/mockobject.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dbusmock/__init__.py b/dbusmock/__init__.py index 8a482ab..3d5d71a 100644 --- a/dbusmock/__init__.py +++ b/dbusmock/__init__.py @@ -14,8 +14,8 @@ __license__ = 'LGPL 3+' __version__ = '0.16.7' from dbusmock.mockobject import (DBusMockObject, MOCK_IFACE, - OBJECT_MANAGER_IFACE, get_object, get_objects) + OBJECT_MANAGER_IFACE, get_object, get_objects, add_object) from dbusmock.testcase import DBusTestCase __all__ = ['DBusMockObject', 'MOCK_IFACE', 'OBJECT_MANAGER_IFACE', - 'DBusTestCase', 'get_object', 'get_objects'] + 'DBusTestCase', 'get_object', 'get_objects', 'add_object'] diff --git a/dbusmock/mockobject.py b/dbusmock/mockobject.py index 586dbad..e4f130f 100644 --- a/dbusmock/mockobject.py +++ b/dbusmock/mockobject.py @@ -688,6 +688,14 @@ dbus.service._method_lookup = _dbusmock_method_lookup # Helper API for templates # +def add_object(path, obj): + if path in objects: + raise dbus.exceptions.DBusException( + 'org.freedesktop.DBus.Mock.NameError', + 'object %s already exists' % path) + + objects[path] = obj + def get_objects(): '''Return all existing object paths'''
From c4436fd42f2936e5fb0f95434d06e45aa9959ca0 Mon Sep 17 00:00:00 2001 From: Simon Busch <simon.busch@lge.com> Date: Wed, 9 Apr 2014 13:18:33 +0200 Subject: [PATCH] Add functionality to add own objects to internal object list In some case the tests might want to create dynamically dbus objects which extended functionality from own class definitions within templates. In such cases we need to register those objects with the internal object manager of dbusmock. Signed-off-by: Simon Busch <simon.busch@lge.com> --- dbusmock/__init__.py | 4 ++-- dbusmock/mockobject.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dbusmock/__init__.py b/dbusmock/__init__.py index 8a482ab..3d5d71a 100644 --- a/dbusmock/__init__.py +++ b/dbusmock/__init__.py @@ -14,8 +14,8 @@ __license__ = 'LGPL 3+' __version__ = '0.16.7' from dbusmock.mockobject import (DBusMockObject, MOCK_IFACE, - OBJECT_MANAGER_IFACE, get_object, get_objects) + OBJECT_MANAGER_IFACE, get_object, get_objects, add_object) from dbusmock.testcase import DBusTestCase __all__ = ['DBusMockObject', 'MOCK_IFACE', 'OBJECT_MANAGER_IFACE', - 'DBusTestCase', 'get_object', 'get_objects'] + 'DBusTestCase', 'get_object', 'get_objects', 'add_object'] diff --git a/dbusmock/mockobject.py b/dbusmock/mockobject.py index 586dbad..e4f130f 100644 --- a/dbusmock/mockobject.py +++ b/dbusmock/mockobject.py @@ -688,6 +688,14 @@ dbus.service._method_lookup = _dbusmock_method_lookup # Helper API for templates # +def add_object(path, obj): + if path in objects: + raise dbus.exceptions.DBusException( + 'org.freedesktop.DBus.Mock.NameError', + 'object %s already exists' % path) + + objects[path] = obj + def get_objects(): '''Return all existing object paths'''