qvm-ls: fix listing domains and labels

This commit is contained in:
Wojtek Porczyk 2015-09-26 00:13:30 +02:00
parent b0be1ad584
commit ce60915fb0
2 changed files with 4 additions and 19 deletions

View File

@ -99,7 +99,7 @@ class Column(object):
Return value to put in a table cell. Return value to put in a table cell.
:param qubes.vm.qubesvm.QubesVM: Domain to get a value from. :param qubes.vm.qubesvm.QubesVM: Domain to get a value from.
:returns: Value to put, or :py:obj:`None` if no value . :returns: Value to put, or :py:obj:`None` if no value.
:rtype: str or None :rtype: str or None
''' '''
@ -185,23 +185,11 @@ class PropertyColumn(Column):
super(PropertyColumn, self).__init__( super(PropertyColumn, self).__init__(
head=holder.ls_head, head=holder.ls_head,
width=holder.ls_width, width=holder.ls_width,
attr=holder.__name__,
fmt=getattr(holder, 'ls_fmt', None),
doc=holder.__doc__) doc=holder.__doc__)
self.holder = holder self.holder = holder
def format(self, vm):
try:
value = getattr(vm, self.holder.__name__)
except AttributeError:
return None
if not hasattr(self.holder, 'ls_fmt') or self.holder.ls_fmt is None:
return value
return self.holder.ls_fmt.format(
getattr(vm, self.holder.__name__)).ljust(
self.ls_width)
def __repr__(self): def __repr__(self):
return '{}(head={!r}, width={!r} holder={!r})'.format( return '{}(head={!r}, width={!r} holder={!r})'.format(
self.__class__.__name__, self.__class__.__name__,
@ -409,10 +397,6 @@ class StatusColumn(Column):
# todo maxmem # todo maxmem
Column('LABEL', width=14,
attr='label.name',
doc='Colour of the label.')
Column('GATEWAY', width=15, Column('GATEWAY', width=15,
attr='netvm.gateway', attr='netvm.gateway',
doc='Network gateway.') doc='Network gateway.')

View File

@ -138,6 +138,7 @@ class QubesVM(qubes.vm.BaseVM):
label = qubes.property('label', label = qubes.property('label',
setter=_setter_label, setter=_setter_label,
saver=(lambda self, prop, value: 'label-{}'.format(value.index)), saver=(lambda self, prop, value: 'label-{}'.format(value.index)),
ls_width=14,
doc='''Colourful label assigned to VM. This is where the colour of the doc='''Colourful label assigned to VM. This is where the colour of the
padlock is set.''') padlock is set.''')