tools/qvm-prefs: handle invalid properties by catching AttributeError

This may avoid unneded qubesd call (listing properties).
This commit is contained in:
Marek Marczykowski-Górecki 2017-03-09 01:39:55 +01:00
parent e4c2294ce0
commit 4ffd44da49
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724

View File

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