label.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # -*- encoding: utf8 -*-
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2017 Marek Marczykowski-Górecki
  6. # <marmarek@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU Lesser General Public License as published by
  10. # the Free Software Foundation; either version 2.1 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Lesser General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public License along
  19. # with this program; if not, see <http://www.gnu.org/licenses/>.
  20. '''VM Labels'''
  21. import qubesmgmt.exc
  22. class Label(object):
  23. '''Label definition for virtual machines
  24. Label specifies colour of the padlock displayed next to VM's name.
  25. :param str color: colour specification as in HTML (``#abcdef``)
  26. :param str name: label's name like "red" or "green"
  27. '''
  28. def __init__(self, app, name):
  29. self.app = app
  30. self._name = name
  31. self._color = None
  32. self._index = None
  33. @property
  34. def color(self):
  35. '''color specification as in HTML (``#abcdef``)'''
  36. if self._color is None:
  37. try:
  38. qubesd_response = self.app.qubesd_call(
  39. 'dom0', 'mgmt.label.Get', self._name, None)
  40. except qubesmgmt.exc.QubesDaemonNoResponseError:
  41. raise AttributeError
  42. self._color = qubesd_response.decode()
  43. return self._color
  44. @property
  45. def name(self):
  46. '''label's name like "red" or "green"'''
  47. return self._name
  48. @property
  49. def icon(self):
  50. '''freedesktop icon name, suitable for use in
  51. :py:meth:`PyQt4.QtGui.QIcon.fromTheme`'''
  52. return 'appvm-' + self.name
  53. @property
  54. def index(self):
  55. '''color specification as in HTML (``#abcdef``)'''
  56. if self._index is None:
  57. try:
  58. qubesd_response = self.app.qubesd_call(
  59. 'dom0', 'mgmt.label.Index', self._name, None)
  60. except qubesmgmt.exc.QubesDaemonNoResponseError:
  61. raise AttributeError
  62. self._index = int(qubesd_response.decode())
  63. return self._index
  64. def __str__(self):
  65. return self._name