From 4ffd44da496b681a4f28f1775205de16483ff19c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 9 Mar 2017 01:39:55 +0100 Subject: [PATCH] tools/qvm-prefs: handle invalid properties by catching AttributeError This may avoid unneded qubesd call (listing properties). --- qubesmgmt/tools/qvm_prefs.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/qubesmgmt/tools/qvm_prefs.py b/qubesmgmt/tools/qvm_prefs.py index c0f9df5..1b3a1bb 100644 --- a/qubesmgmt/tools/qvm_prefs.py +++ b/qubesmgmt/tools/qvm_prefs.py @@ -98,21 +98,24 @@ def process_actions(parser, args, target): else: args.property = args.property.replace('-', '_') - if args.property not in [prop.__name__ - for prop in target.property_list()]: - parser.error('no such property: {!r}'.format(args.property)) - if args.value is not None: - setattr(target, args.property, args.value) - args.app.save() + try: + setattr(target, args.property, args.value) + except AttributeError: + parser.error('no such property: {!r}'.format(args.property)) return 0 if args.delete: - delattr(target, args.property) - args.app.save() + try: + delattr(target, args.property) + except AttributeError: + parser.error('no such property: {!r}'.format(args.property)) return 0 - print(str(getattr(target, args.property))) + try: + print(str(getattr(target, args.property))) + except AttributeError: + parser.error('no such property: {!r}'.format(args.property)) return 0