qvm_prefs.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/python2
  2. # -*- encoding: utf8 -*-
  3. #
  4. # The Qubes OS Project, http://www.qubes-os.org
  5. #
  6. # Copyright (C) 2010-2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
  7. # Copyright (C) 2015 Wojtek Porczyk <woju@invisiblethingslab.com>
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License along
  20. # with this program; if not, write to the Free Software Foundation, Inc.,
  21. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. #
  23. # TODO list properties for all classes
  24. # TODO list only non-default properties
  25. from __future__ import print_function
  26. import sys
  27. import qubes
  28. import qubes.tools
  29. import qubes.utils
  30. import qubes.vm
  31. parser = qubes.tools.QubesArgumentParser(
  32. want_force_root=True,
  33. vmname_nargs=1)
  34. parser.add_argument('--help-properties',
  35. action=qubes.tools.HelpPropertiesAction,
  36. klass=qubes.vm.qubesvm.QubesVM)
  37. parser.add_argument('property', metavar='PROPERTY',
  38. nargs='?',
  39. help='name of the property to show or change')
  40. parser_value = parser.add_mutually_exclusive_group()
  41. parser_value.add_argument('value', metavar='VALUE',
  42. nargs='?',
  43. help='new value of the property')
  44. parser.add_argument('--unset', '--default', '--delete', '-D',
  45. dest='delete',
  46. action='store_true',
  47. help='unset the property; if property has default value, it will be used'
  48. ' instead')
  49. def main(args=None):
  50. args = parser.parse_args(args)
  51. args.domain = args.domains.pop()
  52. if args.property is None:
  53. properties = args.domain.property_list()
  54. width = max(len(prop.__name__) for prop in properties)
  55. for prop in sorted(properties):
  56. try:
  57. value = getattr(args.domain, prop.__name__)
  58. except AttributeError:
  59. print('{name:{width}s} U'.format(
  60. name=prop.__name__, width=width))
  61. continue
  62. if args.domain.property_is_default(prop):
  63. print('{name:{width}s} D {value!s}'.format(
  64. name=prop.__name__, width=width, value=value))
  65. else:
  66. print('{name:{width}s} - {value!s}'.format(
  67. name=prop.__name__, width=width, value=value))
  68. return 0
  69. if args.property not in [prop.__name__
  70. for prop in args.domain.property_list()]:
  71. parser.error('no such property: {!r}'.format(args.property))
  72. if args.value is not None:
  73. setattr(args.domain, args.property, args.value)
  74. args.app.save()
  75. return 0
  76. if args.delete:
  77. delattr(args.domain, args.property)
  78. args.app.save()
  79. return 0
  80. print(str(getattr(args.domain, args.property)))
  81. return 0
  82. if __name__ == '__main__':
  83. sys.exit(main())