Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Conservative adjustment of assignments_list.py
def assignments_list(self, persistent=None):
'''List assignments for devices which are (or may be) attached to the
vm.
Devices may be attached persistently (so they are included in
:file:`qubes.xml`) or not. Device can also be in :file:`qubes.xml`,
but be temporarily detached.
:param bool persistent: only include devices which are or are not
attached persistently.
'''
try:
devices = self._vm.fire_event('device-list-attached:' + self._bus,
persistent=persistent)
except Exception: # pylint: disable=broad-except
self._vm.log.exception('Failed to list {} devices'.format(
self._bus))
if persistent is True:
# don't break app.save()
return list(self._set)
raise
result = []
for dev, options in devices:
if dev in self._set and not persistent:
continue # skipped
if dev in self._set: # and persistent
# add and potentially update later
# could be skipped, as it would be added later
# result.append(self._set.get(dev))
continue
elif dev not in self._set and persistent:
continue # skipped
else: # dev not in self._set and not persistent:
# add final
result.append(
DeviceAssignment(
backend_domain=dev.backend_domain,
ident=dev.ident, options=options,
bus=self._bus))
if persistent is not False:
result.extend(self._set)
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment