Change in pysim[master]: filesystem: add flags to filter selectables

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Wed Mar 3 07:51:42 UTC 2021


laforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/pysim/+/23204 )


Change subject: filesystem: add flags to filter selectables
......................................................................

filesystem: add flags to filter selectables

When requesting what DF/EF/ADF are selectable it is useful to have some
control of what we do not want in the resulting list.

Change-Id: Idb50a512bfdbfdf2e98f2ce0e89928cb0ff19f5e
Related: OS#4963
---
M pySim/filesystem.py
1 file changed, 36 insertions(+), 25 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/04/23204/1

diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index 2bcbe10..a9f2318 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -86,33 +86,38 @@
             node = node.parent
         return node
 
-    def _get_self_selectables(self, alias=None):
+    def _get_self_selectables(self, alias=None, flags = []):
         """Return a dict of {'identifier': self} tuples"""
         sels = {}
         if alias:
             sels.update({alias: self})
-        if self.fid:
+        if self.fid and (flags == [] or 'FIDS' in flags):
             sels.update({self.fid: self})
-        if self.name:
+        if self.name and (flags == [] or 'NAMES' in flags):
             sels.update({self.name: self})
         return sels
 
-    def get_selectables(self):
+    def get_selectables(self, flags = []):
         """Return a dict of {'identifier': File} that is selectable from the current file."""
+        sels = {}
         # we can always select ourself
-        sels = self._get_self_selectables('.')
+        if flags == [] or 'SELF' in flags:
+            sels = self._get_self_selectables('.', flags)
         # we can always select our parent
-        sels = self.parent._get_self_selectables('..')
+        if flags == [] or 'PARENT' in flags:
+            sels = self.parent._get_self_selectables('..', flags)
         # if we have a MF, we can always select its applications
-        mf = self.get_mf()
-        if mf:
-            sels.update(mf._get_self_selectables())
-            sels.update(mf.get_app_selectables())
+        if flags == [] or 'MF' in flags:
+            mf = self.get_mf()
+            if mf:
+                sels.update(mf._get_self_selectables(flags = flags))
+                if flags == [] or 'APPS' in flags:
+                    sels.update(mf.get_app_selectables(flags))
         return sels
 
-    def get_selectable_names(self):
+    def get_selectable_names(self, flags = []):
         """Return a list of strings for all identifiers that are selectable from the current file."""
-        sels = self.get_selectables()
+        sels = self.get_selectables(flags)
         return sels.keys()
 
     def decode_select_response(self, data_hex):
@@ -158,12 +163,14 @@
         for child in children:
             self.add_file(child, ignore_existing)
 
-    def get_selectables(self):
+    def get_selectables(self, flags = []):
         """Get selectable (DF/EF names) from current DF"""
         # global selectables + our children
-        sels = super().get_selectables()
-        sels.update({x.fid: x for x in self.children.values() if x.fid})
-        sels.update({x.name: x for x in self.children.values() if x.name})
+        sels = super().get_selectables(flags)
+        if flags == [] or 'FIDS' in flags:
+                sels.update({x.fid: x for x in self.children.values() if x.fid})
+        if flags == [] or 'NAMES' in flags:
+                sels.update({x.name: x for x in self.children.values() if x.name})
         return sels
 
     def lookup_file_by_name(self, name):
@@ -216,16 +223,20 @@
         """Get list of completions (AID names)"""
         return [x.name for x in self.applications]
 
-    def get_selectables(self):
+    def get_selectables(self, flags = []):
         """Get list of completions (DF/EF/ADF names) from current DF"""
-        sels = super().get_selectables()
-        sels.update(self.get_app_selectables())
+        sels = super().get_selectables(flags)
+        if flags == [] or 'APPS' in flags:
+                sels.update(self.get_app_selectables(flags))
         return sels
 
-    def get_app_selectables(self):
-        # applications by AID + name
-        sels = {x.aid: x for x in self.applications.values()}
-        sels.update({x.name: x for x in self.applications.values() if x.name})
+    def get_app_selectables(self, flags = []):
+        """Get applications by AID + name"""
+        sels = {}
+        if flags == [] or 'FIDS' in flags:
+                sels.update({x.aid: x for x in self.applications.values()})
+        if flags == [] or 'NAMES' in flags:
+                sels.update({x.name: x for x in self.applications.values() if x.name})
         return sels
 
     def decode_select_response(self, data_hex):
@@ -261,10 +272,10 @@
     def __str__(self):
         return "EF(%s)" % (super().__str__())
 
-    def get_selectables(self):
+    def get_selectables(self, flags = []):
         """Get list of completions (EF names) from current DF"""
         #global selectable names + those of the parent DF
-        sels = super().get_selectables()
+        sels = super().get_selectables(flags)
         sels.update({x.name:x for x in self.parent.children.values() if x != self})
         return sels
 

-- 
To view, visit https://gerrit.osmocom.org/c/pysim/+/23204
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Idb50a512bfdbfdf2e98f2ce0e89928cb0ff19f5e
Gerrit-Change-Number: 23204
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210303/35ad8a94/attachment.htm>


More information about the gerrit-log mailing list