label: add index and icon

This commit is contained in:
Marek Marczykowski-Górecki 2017-04-14 13:26:05 +02:00
parent 785706af2f
commit d0e8c0515e
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 35 additions and 0 deletions

View File

@ -22,6 +22,7 @@
import qubesmgmt.exc
class Label(object):
'''Label definition for virtual machines
@ -35,6 +36,7 @@ class Label(object):
self.app = app
self._name = name
self._color = None
self._index = None
@property
def color(self):
@ -53,5 +55,23 @@ class Label(object):
'''label's name like "red" or "green"'''
return self._name
@property
def icon(self):
'''freedesktop icon name, suitable for use in
:py:meth:`PyQt4.QtGui.QIcon.fromTheme`'''
return 'appvm-' + self.name
@property
def index(self):
'''color specification as in HTML (``#abcdef``)'''
if self._index is None:
try:
qubesd_response = self.app.qubesd_call(
'dom0', 'mgmt.label.Index', self._name, None)
except qubesmgmt.exc.QubesDaemonNoResponseError:
raise AttributeError
self._index = int(qubesd_response.decode())
return self._index
def __str__(self):
return self._name

View File

@ -51,3 +51,18 @@ class TC_00_Label(qubesmgmt.tests.QubesTestCase):
label = self.app.labels['green']
self.assertEqual(label.color, '0x00FF00')
def test_012_get_index(self):
self.app.expected_calls[
('dom0', 'mgmt.label.List', None, None)] = \
b'0\x00green\nred\nblack\n'
self.app.expected_calls[
('dom0', 'mgmt.label.Index', 'green', None)] = b'0\x003'
label = self.app.labels['green']
self.assertEqual(label.index, 3)
def test_024_get_icon(self):
self.app.expected_calls[
('dom0', 'mgmt.label.List', None, None)] = \
b'0\x00green\nred\nblack\n'
label = self.app.labels['green']
self.assertEqual(label.icon, 'appvm-green')