Merge pull request #992 from mwhudson/generalize-_one-_all

make two FilesystemModel helper methods slightly more general
This commit is contained in:
Michael Hudson-Doyle 2021-06-29 10:56:03 +12:00 committed by GitHub
commit cf75408e46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 8 deletions

View File

@ -1232,24 +1232,22 @@ class FilesystemModel(object):
self._probe_data = probe_data
self.reset()
def _matcher(self, type, kw):
def _matcher(self, kw):
for a in self._actions:
if a.type != type:
continue
for k, v in kw.items():
if getattr(a, k) != v:
break
else:
yield a
def _one(self, *, type, **kw):
def _one(self, **kw):
try:
return next(self._matcher(type, kw))
return next(self._matcher(kw))
except StopIteration:
return None
def _all(self, *, type, **kw):
return list(self._matcher(type, kw))
def _all(self, **kw):
return list(self._matcher(kw))
def all_mounts(self):
return self._all(type='mount')

View File

@ -234,7 +234,7 @@ class FilesystemController(SubiquityController, FilesystemManipulator):
async def guided_POST(self, choice: Optional[GuidedChoice]) \
-> StorageResponse:
if choice is not None:
disk = self.model._one(type='disk', id=choice.disk_id)
disk = self.model._one(id=choice.disk_id)
if choice.use_lvm:
lvm_options = None
if choice.password is not None: