Change in pysim[master]: pySim-shell: add functionality to walk through the fs recursively

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
Fri Mar 19 07:13:49 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/23208 )

Change subject: pySim-shell: add functionality to walk through the fs recursively
......................................................................

pySim-shell: add functionality to walk through the fs recursively

We might add functionality that may require to walk through the entire
filesystem tree to perform an action to all files at once. Lets add a
generic walker that gets a function pointer that can carray out a file
specific action then. Also add another command that just displays the
whole filesystem tree.

Change-Id: If93d24dfb80c83eda39303c936910fa1fa7f48f8
Related: OS#4963
---
M pySim-shell.py
1 file changed, 25 insertions(+), 1 deletion(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved



diff --git a/pySim-shell.py b/pySim-shell.py
index 407204f..481bfc8 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -41,7 +41,7 @@
 from pySim.utils import dec_st, init_reader, sanitize_pin_adm, tabulate_str_list
 from pySim.card_handler import card_handler
 
-from pySim.filesystem import CardMF, RuntimeState
+from pySim.filesystem import CardMF, RuntimeState, CardDF, CardADF
 from pySim.ts_51_011 import CardProfileSIM, DF_TELECOM, DF_GSM
 from pySim.ts_102_221 import CardProfileUICC
 from pySim.ts_31_102 import ADF_USIM
@@ -142,6 +142,30 @@
 		self._cmd.poutput(directory_str)
 		self._cmd.poutput("%d files" % len(selectables))
 
+	def walk(self, indent = 0, action = None, context = None):
+		"""Recursively walk through the file system, starting at the currently selected DF"""
+		files = self._cmd.rs.selected_file.get_selectables(flags = ['FNAMES', 'ANAMES'])
+		for f in files:
+			if not action:
+				output_str = "  " * indent + str(f) + (" " * 250)
+				output_str = output_str[0:25]
+				if isinstance(files[f], CardADF):
+					output_str += " " + str(files[f].aid)
+				else:
+					output_str += " " + str(files[f].fid)
+				output_str += " " + str(files[f].desc)
+				self._cmd.poutput(output_str)
+			if isinstance(files[f], CardDF):
+				fcp_dec = self._cmd.rs.select(f, self._cmd)
+				self.walk(indent + 1, action, context)
+				fcp_dec = self._cmd.rs.select("..", self._cmd)
+			elif action:
+				action(f, context)
+
+	def do_tree(self, opts):
+		"""Display a filesystem-tree with all selectable files"""
+		self.walk()
+
 
 
 @with_default_category('USIM Commands')

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

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: If93d24dfb80c83eda39303c936910fa1fa7f48f8
Gerrit-Change-Number: 23208
Gerrit-PatchSet: 5
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-CC: dexter <pmaier at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210319/9491adbc/attachment.htm>


More information about the gerrit-log mailing list