Skip to content

Instantly share code, notes, and snippets.

@v6ak
Created May 18, 2021 08:51
Show Gist options
  • Save v6ak/23c6b5f84238e314a8a751c8ac6de48d to your computer and use it in GitHub Desktop.
Save v6ak/23c6b5f84238e314a8a751c8ac6de48d to your computer and use it in GitHub Desktop.
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