qubes: disable events by default not to interfere with loading from XML

This commit is contained in:
Wojtek Porczyk 2015-06-24 15:02:49 +02:00
parent f2d9d628c4
commit 7f16e0a73b
4 changed files with 10 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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