qubes: unify PropertyHolder API
get_props_list() -> property_list() _init_property() -> _property_init()
This commit is contained in:
parent
6798790e1f
commit
8c437f4053
@ -636,7 +636,7 @@ class property(object): # pylint: disable=redefined-builtin,invalid-name
|
|||||||
else:
|
else:
|
||||||
instance.fire_event_pre('property-pre-set:' + self.__name__, value)
|
instance.fire_event_pre('property-pre-set:' + self.__name__, value)
|
||||||
|
|
||||||
instance._init_property(self, value) # pylint: disable=protected-access
|
instance._property_init(self, value) # pylint: disable=protected-access
|
||||||
|
|
||||||
if has_oldvalue:
|
if has_oldvalue:
|
||||||
instance.fire_event(
|
instance.fire_event(
|
||||||
@ -816,7 +816,7 @@ class PropertyHolder(qubes.events.Emitter):
|
|||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_props_list(cls, load_stage=None):
|
def property_list(cls, load_stage=None):
|
||||||
'''List all properties attached to this VM's class
|
'''List all properties attached to this VM's class
|
||||||
|
|
||||||
:param load_stage: Filter by load stage
|
:param load_stage: Filter by load stage
|
||||||
@ -834,7 +834,7 @@ class PropertyHolder(qubes.events.Emitter):
|
|||||||
key=lambda prop: (prop.load_stage, prop.order, prop.__name__))
|
key=lambda prop: (prop.load_stage, prop.order, prop.__name__))
|
||||||
|
|
||||||
|
|
||||||
def _init_property(self, prop, value):
|
def _property_init(self, prop, value):
|
||||||
'''Initialise property to a given value, without side effects.
|
'''Initialise property to a given value, without side effects.
|
||||||
|
|
||||||
:param qubes.property prop: property object of particular interest
|
:param qubes.property prop: property object of particular interest
|
||||||
@ -842,7 +842,7 @@ class PropertyHolder(qubes.events.Emitter):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
setattr(self, self.get_property_def(prop)._attr_name, value)
|
setattr(self, self.property_get_def(prop)._attr_name, value)
|
||||||
|
|
||||||
|
|
||||||
def property_is_default(self, prop):
|
def property_is_default(self, prop):
|
||||||
@ -858,11 +858,11 @@ class PropertyHolder(qubes.events.Emitter):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
return hasattr(self, self.get_property_def(prop)._attr_name)
|
return hasattr(self, self.property_get_def(prop)._attr_name)
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_property_def(cls, prop):
|
def property_get_def(cls, prop):
|
||||||
'''Return property definition object.
|
'''Return property definition object.
|
||||||
|
|
||||||
If prop is already :py:class:`qubes.property` instance, return the same
|
If prop is already :py:class:`qubes.property` instance, return the same
|
||||||
@ -876,7 +876,7 @@ class PropertyHolder(qubes.events.Emitter):
|
|||||||
if isinstance(prop, qubes.property):
|
if isinstance(prop, qubes.property):
|
||||||
return prop
|
return prop
|
||||||
|
|
||||||
for p in cls.get_props_list():
|
for p in cls.property_list():
|
||||||
if p.__name__ == prop:
|
if p.__name__ == prop:
|
||||||
return p
|
return p
|
||||||
|
|
||||||
@ -894,7 +894,7 @@ class PropertyHolder(qubes.events.Emitter):
|
|||||||
|
|
||||||
self.events_enabled = False
|
self.events_enabled = False
|
||||||
all_names = set(
|
all_names = set(
|
||||||
prop.__name__ for prop in self.get_props_list(load_stage))
|
prop.__name__ for prop in self.property_list(load_stage))
|
||||||
for node in self.xml.xpath('./properties/property'):
|
for node in self.xml.xpath('./properties/property'):
|
||||||
name = node.get('name')
|
name = node.get('name')
|
||||||
value = node.get('ref') or node.text
|
value = node.get('ref') or node.text
|
||||||
@ -921,7 +921,7 @@ class PropertyHolder(qubes.events.Emitter):
|
|||||||
|
|
||||||
properties = lxml.etree.Element('properties')
|
properties = lxml.etree.Element('properties')
|
||||||
|
|
||||||
for prop in self.get_props_list():
|
for prop in self.property_list():
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
try:
|
try:
|
||||||
value = getattr(
|
value = getattr(
|
||||||
@ -954,22 +954,22 @@ class PropertyHolder(qubes.events.Emitter):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
if proplist is None:
|
if proplist is None:
|
||||||
proplist = self.get_props_list()
|
proplist = self.property_list()
|
||||||
else:
|
else:
|
||||||
proplist = [prop for prop in self.get_props_list()
|
proplist = [prop for prop in self.property_list()
|
||||||
if prop.__name__ in proplist or prop in proplist]
|
if prop.__name__ in proplist or prop in proplist]
|
||||||
|
|
||||||
for prop in self.proplist():
|
for prop in self.property_list():
|
||||||
try:
|
try:
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
self._init_property(prop, getattr(src, prop._attr_name))
|
self._property_init(prop, getattr(src, prop._attr_name))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self.fire_event('cloned-properties', src, proplist)
|
self.fire_event('cloned-properties', src, proplist)
|
||||||
|
|
||||||
|
|
||||||
def require_property(self, prop, allow_none=False, hard=False):
|
def property_require(self, prop, allow_none=False, hard=False):
|
||||||
'''Complain badly when property is not set.
|
'''Complain badly when property is not set.
|
||||||
|
|
||||||
:param prop: property name or object
|
:param prop: property name or object
|
||||||
@ -1219,11 +1219,11 @@ class Qubes(PropertyHolder):
|
|||||||
|
|
||||||
# stage 5: misc fixups
|
# stage 5: misc fixups
|
||||||
|
|
||||||
self.require_property('default_fw_netvm', allow_none=True)
|
self.property_require('default_fw_netvm', allow_none=True)
|
||||||
self.require_property('default_netvm', allow_none=True)
|
self.property_require('default_netvm', allow_none=True)
|
||||||
self.require_property('default_template')
|
self.property_require('default_template')
|
||||||
self.require_property('clockvm')
|
self.property_require('clockvm')
|
||||||
self.require_property('updatevm')
|
self.property_require('updatevm')
|
||||||
|
|
||||||
# Disable ntpd in ClockVM - to not conflict with ntpdate (both are
|
# Disable ntpd in ClockVM - to not conflict with ntpdate (both are
|
||||||
# using 123/udp port)
|
# using 123/udp port)
|
||||||
|
@ -73,7 +73,7 @@ class EmitterMeta(type):
|
|||||||
cls.__handlers__ = collections.defaultdict(set)
|
cls.__handlers__ = collections.defaultdict(set)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
propnames = set(prop.__name__ for prop in cls.get_props_list())
|
propnames = set(prop.__name__ for prop in cls.property_list())
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
propnames = set()
|
propnames = set()
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ class BaseVM(qubes.PropertyHolder):
|
|||||||
|
|
||||||
self.events_enabled = False
|
self.events_enabled = False
|
||||||
all_names = set(prop.__name__
|
all_names = set(prop.__name__
|
||||||
for prop in self.get_props_list(load_stage=2))
|
for prop in self.property_list(load_stage=2))
|
||||||
for key in list(kwargs.keys()):
|
for key in list(kwargs.keys()):
|
||||||
if not key in all_names:
|
if not key in all_names:
|
||||||
raise AttributeError(
|
raise AttributeError(
|
||||||
@ -289,7 +289,7 @@ class BaseVM(qubes.PropertyHolder):
|
|||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
proprepr = []
|
proprepr = []
|
||||||
for prop in self.get_props_list():
|
for prop in self.property_list():
|
||||||
try:
|
try:
|
||||||
proprepr.append('{}={!r}'.format(
|
proprepr.append('{}={!r}'.format(
|
||||||
prop.__name__, getattr(self, prop.__name__)))
|
prop.__name__, getattr(self, prop.__name__)))
|
||||||
|
Loading…
Reference in New Issue
Block a user