From b0af95fa2b621432afd3de8d6dfb8b4aa2f16a25 Mon Sep 17 00:00:00 2001 From: Wojtek Porczyk Date: Wed, 23 Sep 2015 15:31:08 +0200 Subject: [PATCH] qvm-prefs: support resetting values --- doc/manpages/qvm-prefs.rst | 10 +++++++--- qubes/tools/qvm_prefs.py | 30 ++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/doc/manpages/qvm-prefs.rst b/doc/manpages/qvm-prefs.rst index c55c5b70..7f0320e0 100644 --- a/doc/manpages/qvm-prefs.rst +++ b/doc/manpages/qvm-prefs.rst @@ -6,7 +6,7 @@ Synopsis -------- -:command:`qvm-prefs` qvm-prefs [-h] [--xml *XMLFILE*] [--verbose] [--quiet] [--force-root] [--help-properties] *VMNAME* [*PROPERTY* [*VALUE*]] +:command:`qvm-prefs` qvm-prefs [-h] [--xml *XMLFILE*] [--verbose] [--quiet] [--force-root] [--help-properties] *VMNAME* [*PROPERTY* [*VALUE*\|--delete]] Options ------- @@ -35,6 +35,10 @@ Options Force to run as root. +.. option:: --unset, --default, --delete, -D + + Unset the property. If is has default value, it will be used instead. + Common properties ================= @@ -54,11 +58,11 @@ include_in_backups works only in qubes-manager). You can always manually select or deselect any VM for backup. - pcidevs +pcidevs PCI devices assigned to the VM. Should be edited using :manpage:`qvm-pci(1)` tool. - pci_strictreset +pci_strictreset Accepted values: ``True``, ``False`` Control whether prevent assigning to VM a device which does not support any diff --git a/qubes/tools/qvm_prefs.py b/qubes/tools/qvm_prefs.py index 287e76c1..96252887 100644 --- a/qubes/tools/qvm_prefs.py +++ b/qubes/tools/qvm_prefs.py @@ -22,7 +22,7 @@ # # TODO list properties for all classes -# TODO indicate default values +# TODO list only non-default properties from __future__ import print_function @@ -72,9 +72,7 @@ class _HelpPropertiesAction(argparse.Action): parser = qubes.tools.get_parser_base(want_force_root=True) -#parser.add_argument('--property', '--prop', '-p', -# action=qubes.tools.PropertyAction, -# help='set domain\'s property (may be given multiple times)') +parser.add_argument('--help-properties', action=_HelpPropertiesAction) parser.add_argument('name', metavar='VMNAME', help='name of the domain to change') @@ -83,11 +81,17 @@ parser.add_argument('property', metavar='PROPERTY', nargs='?', help='name of the property to show or change') -parser.add_argument('value', metavar='VALUE', +parser_value = parser.add_mutually_exclusive_group() + +parser_value.add_argument('value', metavar='VALUE', nargs='?', help='new value of the property') -parser.add_argument('--help-properties', action=_HelpPropertiesAction) +parser.add_argument('--unset', '--default', '--delete', '-D', + dest='delete', + action='store_true', + help='unset the property; if property has default value, it will be used' + ' instead') def main(): @@ -123,12 +127,18 @@ def main(): return True - if args.value is None: - print(str(getattr(domain, args.property))) + if args.value is not None: + setattr(domain, args.property, args.value) + app.save() return True - setattr(domain, args.property, args.value) - app.save() + if args.delete: + delattr(domain, args.property) + app.save() + return True + + + print(str(getattr(domain, args.property))) return True