qvm-prefs: support resetting values

This commit is contained in:
Wojtek Porczyk 2015-09-23 15:31:08 +02:00
parent af1a6a49bd
commit b0af95fa2b
2 changed files with 27 additions and 13 deletions

View File

@ -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

View File

@ -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