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._probe_data = probe_data
self.reset() self.reset()
def _matcher(self, type, kw): def _matcher(self, kw):
for a in self._actions: for a in self._actions:
if a.type != type:
continue
for k, v in kw.items(): for k, v in kw.items():
if getattr(a, k) != v: if getattr(a, k) != v:
break break
else: else:
yield a yield a
def _one(self, *, type, **kw): def _one(self, **kw):
try: try:
return next(self._matcher(type, kw)) return next(self._matcher(kw))
except StopIteration: except StopIteration:
return None return None
def _all(self, *, type, **kw): def _all(self, **kw):
return list(self._matcher(type, kw)) return list(self._matcher(kw))
def all_mounts(self): def all_mounts(self):
return self._all(type='mount') return self._all(type='mount')

View File

@ -234,7 +234,7 @@ class FilesystemController(SubiquityController, FilesystemManipulator):
async def guided_POST(self, choice: Optional[GuidedChoice]) \ async def guided_POST(self, choice: Optional[GuidedChoice]) \
-> StorageResponse: -> StorageResponse:
if choice is not None: 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: if choice.use_lvm:
lvm_options = None lvm_options = None
if choice.password is not None: if choice.password is not None: