qubes_prefs.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 merge printing with qvm-prefs
  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. parser = qubes.tools.QubesArgumentParser(
  31. want_force_root=True)
  32. parser.add_argument('--help-properties',
  33. action=qubes.tools.HelpPropertiesAction)
  34. parser.add_argument('property', metavar='PROPERTY',
  35. nargs='?',
  36. help='name of the property to show or change')
  37. parser_value = parser.add_mutually_exclusive_group()
  38. parser_value.add_argument('value', metavar='VALUE',
  39. nargs='?',
  40. help='new value of the property')
  41. parser.add_argument('--unset', '--default', '--delete', '-D',
  42. dest='delete',
  43. action='store_true',
  44. help='unset the property; if property has default value, it will be used'
  45. ' instead')
  46. def main(args=None):
  47. args = parser.parse_args(args)
  48. if args.property is None:
  49. properties = args.app.property_list()
  50. width = max(len(prop.__name__) for prop in properties)
  51. for prop in sorted(properties):
  52. try:
  53. value = getattr(args.app, prop.__name__)
  54. except AttributeError:
  55. print('{name:{width}s} U'.format(
  56. name=prop.__name__, width=width))
  57. continue
  58. if args.app.property_is_default(prop):
  59. print('{name:{width}s} D {value!s}'.format(
  60. name=prop.__name__, width=width, value=value))
  61. else:
  62. print('{name:{width}s} - {value!s}'.format(
  63. name=prop.__name__, width=width, value=value))
  64. return 0
  65. if args.value is not None:
  66. setattr(args.app, args.property, args.value)
  67. args.app.save()
  68. return 0
  69. if args.delete:
  70. delattr(args.app, args.property)
  71. args.app.save()
  72. return 0
  73. print(str(getattr(args.app, args.property)))
  74. return 0
  75. if __name__ == '__main__':
  76. sys.exit(main())