qvm-prefs: add --hide-default option

This commit is contained in:
Malte Leip 2019-05-29 20:32:13 +02:00
parent c1be4cd062
commit 32538fa5ec
No known key found for this signature in database
GPG Key ID: 94B1C2BAB08E828E
6 changed files with 26 additions and 7 deletions

View File

@ -19,6 +19,10 @@ Options
List available properties with short descriptions and exit. List available properties with short descriptions and exit.
.. option:: --hide-default
Do not show properties that are set to the default value.
.. option:: --verbose, -v .. option:: --verbose, -v
Increase verbosity. Increase verbosity.

View File

@ -19,6 +19,10 @@ Options
List available properties with short descriptions and exit. List available properties with short descriptions and exit.
.. option:: --hide-default
Do not show properties that are set to the default value.
.. option:: --verbose, -v .. option:: --verbose, -v
Increase verbosity. Increase verbosity.

View File

@ -39,6 +39,11 @@ class TC_00_qubes_prefs(qubesadmin.tests.QubesTestCase):
self.assertEqual(stdout.getvalue(), self.assertEqual(stdout.getvalue(),
'prop1 D value1\n' 'prop1 D value1\n'
'prop2 - value2\n') 'prop2 - value2\n')
with qubesadmin.tests.tools.StdoutBuffer() as stdout:
self.assertEqual(0, qubesadmin.tools.qubes_prefs.main([
'--hide-default'], app=self.app))
self.assertEqual(stdout.getvalue(),
'prop2 - value2\n')
self.assertAllCalled() self.assertAllCalled()
def test_002_set_property(self): def test_002_set_property(self):

View File

@ -44,6 +44,11 @@ class TC_00_qvm_prefs(qubesadmin.tests.QubesTestCase):
self.assertEqual(stdout.getvalue(), self.assertEqual(stdout.getvalue(),
'prop1 D value1\n' 'prop1 D value1\n'
'prop2 - value2\n') 'prop2 - value2\n')
with qubesadmin.tests.tools.StdoutBuffer() as stdout:
self.assertEqual(0, qubesadmin.tools.qvm_prefs.main([
'dom0','--hide-default'], app=self.app))
self.assertEqual(stdout.getvalue(),
'prop2 - value2\n')
self.assertAllCalled() self.assertAllCalled()
def test_001_no_vm(self): def test_001_no_vm(self):

View File

@ -20,8 +20,6 @@
''' Manipulate global properties.''' ''' Manipulate global properties.'''
# TODO list only non-default properties
from __future__ import print_function from __future__ import print_function
import sys import sys

View File

@ -19,7 +19,6 @@
# with this program; if not, see <http://www.gnu.org/licenses/>. # with this program; if not, see <http://www.gnu.org/licenses/>.
''' Manipulate VM properties.''' ''' Manipulate VM properties.'''
# TODO list only non-default properties
from __future__ import print_function from __future__ import print_function
@ -41,6 +40,10 @@ def get_parser(vmname_nargs=1):
action='store_true', action='store_true',
help='list all available properties with short descriptions and exit') help='list all available properties with short descriptions and exit')
parser.add_argument('--hide-default',
action='store_true',
help='Do not show properties that are set to the default value.')
parser.add_argument('--get', '-g', parser.add_argument('--get', '-g',
action='store_true', action='store_true',
help='Ignored; for compatibility with older scripts.') help='Ignored; for compatibility with older scripts.')
@ -101,12 +104,12 @@ def process_actions(parser, args, target):
name=prop, width=width)) name=prop, width=width))
continue continue
if target.property_is_default(prop): if not target.property_is_default(prop):
print('{name:{width}s} D {value!s}'.format(
name=prop, width=width, value=value))
else:
print('{name:{width}s} - {value!s}'.format( print('{name:{width}s} - {value!s}'.format(
name=prop, width=width, value=value)) name=prop, width=width, value=value))
elif not args.hide_default:
print('{name:{width}s} D {value!s}'.format(
name=prop, width=width, value=value))
return 0 return 0
else: else: