app: use suppress() in simple cases
This commit is contained in:
parent
7159f206a5
commit
9b6d082673
21
qubes/app.py
21
qubes/app.py
@ -33,6 +33,7 @@ import tempfile
|
||||
import time
|
||||
import traceback
|
||||
import uuid
|
||||
from contextlib import suppress
|
||||
|
||||
import asyncio
|
||||
import jinja2
|
||||
@ -280,11 +281,9 @@ class QubesHost:
|
||||
|
||||
self.app.log.debug('QubesHost: no_cpus={} memory_total={}'.format(
|
||||
self.no_cpus, self.memory_total))
|
||||
try:
|
||||
with suppress(NotImplementedError):
|
||||
self.app.log.debug('QubesHost: xen_free_memory={}'.format(
|
||||
self.get_free_xen_memory()))
|
||||
except NotImplementedError:
|
||||
pass
|
||||
|
||||
@property
|
||||
def memory_total(self):
|
||||
@ -1324,10 +1323,8 @@ class Qubes(qubes.PropertyHolder):
|
||||
"""
|
||||
|
||||
# first search for index, verbatim
|
||||
try:
|
||||
with suppress(KeyError):
|
||||
return self.labels[label]
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
# then search for name
|
||||
for i in self.labels.values():
|
||||
@ -1335,10 +1332,8 @@ class Qubes(qubes.PropertyHolder):
|
||||
return i
|
||||
|
||||
# last call, if label is a number represented as str, search in indices
|
||||
try:
|
||||
with suppress(KeyError, ValueError):
|
||||
return self.labels[int(label)]
|
||||
except (KeyError, ValueError):
|
||||
pass
|
||||
|
||||
raise qubes.exc.QubesLabelNotFoundError(label)
|
||||
|
||||
@ -1477,7 +1472,7 @@ class Qubes(qubes.PropertyHolder):
|
||||
# allow removed VM to reference itself
|
||||
continue
|
||||
for prop in obj.property_list():
|
||||
try:
|
||||
with suppress(AttributeError):
|
||||
if isinstance(prop, qubes.vm.VMProperty) and \
|
||||
getattr(obj, prop.__name__) == vm:
|
||||
self.log.error(
|
||||
@ -1489,8 +1484,6 @@ class Qubes(qubes.PropertyHolder):
|
||||
'see /var/log/qubes/qubes.log in dom0 for '
|
||||
'details'.format(
|
||||
vm.name))
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
assignments = vm.get_provided_assignments()
|
||||
if assignments:
|
||||
@ -1512,11 +1505,9 @@ class Qubes(qubes.PropertyHolder):
|
||||
'updatevm',
|
||||
'default_template',
|
||||
):
|
||||
try:
|
||||
with suppress(AttributeError):
|
||||
if getattr(self, propname) == vm:
|
||||
delattr(self, propname)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
@qubes.events.handler('property-pre-set:clockvm')
|
||||
def on_property_pre_set_clockvm(self, event, name, newvalue, oldvalue=None):
|
||||
|
Loading…
Reference in New Issue
Block a user