Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions qubes/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
`device-list-change:class` event.
'''
import asyncio
from collections import OrderedDict
from typing import Optional

import qubes.utils

Expand Down Expand Up @@ -343,8 +345,8 @@ def assignments(self, persistent=None):
: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.
:param Optional[bool] persistent: only include devices which are or are
not attached persistently.
'''

try:
Expand All @@ -355,24 +357,19 @@ def assignments(self, persistent=None):
self._bus))
if persistent is True:
# don't break app.save()
return self._set
return list(self._set)
raise
result = set()
for dev, options in devices:
if dev in self._set and not persistent:
continue
if dev in self._set:
result.add(self._set.get(dev))
elif dev not in self._set and persistent:
continue
else:
result.add(
DeviceAssignment(
backend_domain=dev.backend_domain,
ident=dev.ident, options=options,
bus=self._bus))
if persistent is not False:
result.update(self._set)
result = []
if persistent is not False: # None or True
result.extend(self._set)
if not persistent: # None or False
for dev, options in devices:
if dev not in self._set:
result.append(
DeviceAssignment(
backend_domain=dev.backend_domain,
ident=dev.ident, options=options,
bus=self._bus))
return result

def available(self):
Expand Down Expand Up @@ -437,7 +434,7 @@ class PersistentCollection:
'''

def __init__(self):
self._dict = {}
self._dict = OrderedDict()

def add(self, assignment: DeviceAssignment):
''' Add assignment to collection '''
Expand Down