Преглед изворни кода

qvm-prefs: support resetting values

Wojtek Porczyk пре 9 година
родитељ
комит
b0af95fa2b
2 измењених фајлова са 27 додато и 13 уклоњено
  1. 7 3
      doc/manpages/qvm-prefs.rst
  2. 20 10
      qubes/tools/qvm_prefs.py

+ 7 - 3
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

+ 20 - 10
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