From 7f16e0a73bbe7073d8f8dc8da6573f36553f973a Mon Sep 17 00:00:00 2001 From: Wojtek Porczyk Date: Wed, 24 Jun 2015 15:02:49 +0200 Subject: [PATCH] qubes: disable events by default not to interfere with loading from XML --- qubes/__init__.py | 6 ++++-- qubes/events.py | 5 ++++- qubes/tests/events.py | 2 ++ qubes/vm/__init__.py | 2 -- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/qubes/__init__.py b/qubes/__init__.py index ff8d0d1d..0fa12756 100644 --- a/qubes/__init__.py +++ b/qubes/__init__.py @@ -450,6 +450,7 @@ class VMCollection(object): 'name={!r} ({!r})'.format(value.name, self[value.name])) self._dict[value.qid] = value + value.events_enabled = True self.app.fire_event('domain-added', value) @@ -799,6 +800,7 @@ class PropertyHolder(qubes.events.Emitter): ''' def __init__(self, xml, **kwargs): + super(PropertyHolder, self).__init__() self.xml = xml for key, value in kwargs.items(): @@ -810,8 +812,6 @@ class PropertyHolder(qubes.events.Emitter): continue setattr(self, key, kwargs.pop(key)) - super(PropertyHolder, self).__init__(**kwargs) - @classmethod def property_list(cls, load_stage=None): @@ -1141,6 +1141,8 @@ class Qubes(PropertyHolder): if load: self.load() + self.events_enabled = True + def load(self): '''Open qubes.xml diff --git a/qubes/events.py b/qubes/events.py index 093f0fb9..8c17867c 100644 --- a/qubes/events.py +++ b/qubes/events.py @@ -93,13 +93,16 @@ class EmitterMeta(type): class Emitter(object): '''Subject that can emit events. + + By default all events are disabled not to interfere with loading from XML. + To enable event dispatch, set :py:attr:`events_enabled` to :py:obj:`True`. ''' __metaclass__ = EmitterMeta def __init__(self, *args, **kwargs): super(Emitter, self).__init__(*args, **kwargs) - self.events_enabled = True + self.events_enabled = False @classmethod diff --git a/qubes/tests/events.py b/qubes/tests/events.py index bff9ca38..753dbf19 100644 --- a/qubes/tests/events.py +++ b/qubes/tests/events.py @@ -37,6 +37,7 @@ class TC_00_Emitter(qubes.tests.QubesTestCase): emitter = qubes.events.Emitter() emitter.add_handler('testevent', on_testevent) + emitter.events_enabled = True emitter.fire_event('testevent') self.assertTrue(testevent_fired[0]) @@ -53,5 +54,6 @@ class TC_00_Emitter(qubes.tests.QubesTestCase): self.testevent_fired = True emitter = TestEmitter() + emitter.events_enabled = True emitter.fire_event('testevent') self.assertTrue(emitter.testevent_fired) diff --git a/qubes/vm/__init__.py b/qubes/vm/__init__.py index f8c94e84..d58a6fec 100644 --- a/qubes/vm/__init__.py +++ b/qubes/vm/__init__.py @@ -148,8 +148,6 @@ class BaseVM(qubes.PropertyHolder): def __init__(self, app, xml, services=None, devices=None, tags=None, **kwargs): # pylint: disable=redefined-outer-name - - self.events_enabled = False super(BaseVM, self).__init__(xml, **kwargs) #: mother :py:class:`qubes.Qubes` object