qubes/vm: fixed __repr__ for BaseVM

Previously it could fail with AttributeError when any of the properties was unset.
This commit is contained in:
Wojtek Porczyk 2014-12-17 13:32:58 +01:00
parent ef4f00dac0
commit f149c7b59b

View File

@ -285,11 +285,16 @@ class BaseVM(qubes.PropertyHolder):
return element
def __repr__(self):
return '<{} object at {:#x} {}>'.format(
self.__class__.__name__, id(self),
' '.join('{}={}'.format(prop.__name__, getattr(self, prop.__name__))
for prop in self.get_props_list()))
proprepr = []
for prop in self.get_props_list():
try:
proprepr.append('{}={!r}'.format(
prop.__name__, getattr(self, prop.__name__)))
except AttributeError:
continue
return '<{} object at {:#x} {}>'.format(
self.__class__.__name__, id(self), ' '.join(proprepr))
@classmethod
def add_hook(cls, event, f):