<p>laforge <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/pysim/+/23208">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">pySim-shell: add functionality to walk through the fs recursively<br><br>We might add functionality that may require to walk through the entire<br>filesystem tree to perform an action to all files at once. Lets add a<br>generic walker that gets a function pointer that can carray out a file<br>specific action then. Also add another command that just displays the<br>whole filesystem tree.<br><br>Change-Id: If93d24dfb80c83eda39303c936910fa1fa7f48f8<br>Related: OS#4963<br>---<br>M pySim-shell.py<br>1 file changed, 25 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/pySim-shell.py b/pySim-shell.py</span><br><span>index 407204f..481bfc8 100755</span><br><span>--- a/pySim-shell.py</span><br><span>+++ b/pySim-shell.py</span><br><span>@@ -41,7 +41,7 @@</span><br><span> from pySim.utils import dec_st, init_reader, sanitize_pin_adm, tabulate_str_list</span><br><span> from pySim.card_handler import card_handler</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-from pySim.filesystem import CardMF, RuntimeState</span><br><span style="color: hsl(120, 100%, 40%);">+from pySim.filesystem import CardMF, RuntimeState, CardDF, CardADF</span><br><span> from pySim.ts_51_011 import CardProfileSIM, DF_TELECOM, DF_GSM</span><br><span> from pySim.ts_102_221 import CardProfileUICC</span><br><span> from pySim.ts_31_102 import ADF_USIM</span><br><span>@@ -142,6 +142,30 @@</span><br><span>           self._cmd.poutput(directory_str)</span><br><span>             self._cmd.poutput("%d files" % len(selectables))</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+        def walk(self, indent = 0, action = None, context = None):</span><br><span style="color: hsl(120, 100%, 40%);">+            """Recursively walk through the file system, starting at the currently selected DF"""</span><br><span style="color: hsl(120, 100%, 40%);">+           files = self._cmd.rs.selected_file.get_selectables(flags = ['FNAMES', 'ANAMES'])</span><br><span style="color: hsl(120, 100%, 40%);">+              for f in files:</span><br><span style="color: hsl(120, 100%, 40%);">+                       if not action:</span><br><span style="color: hsl(120, 100%, 40%);">+                                output_str = "  " * indent + str(f) + (" " * 250)</span><br><span style="color: hsl(120, 100%, 40%);">+                         output_str = output_str[0:25]</span><br><span style="color: hsl(120, 100%, 40%);">+                         if isinstance(files[f], CardADF):</span><br><span style="color: hsl(120, 100%, 40%);">+                                     output_str += " " + str(files[f].aid)</span><br><span style="color: hsl(120, 100%, 40%);">+                               else:</span><br><span style="color: hsl(120, 100%, 40%);">+                                 output_str += " " + str(files[f].fid)</span><br><span style="color: hsl(120, 100%, 40%);">+                               output_str += " " + str(files[f].desc)</span><br><span style="color: hsl(120, 100%, 40%);">+                              self._cmd.poutput(output_str)</span><br><span style="color: hsl(120, 100%, 40%);">+                 if isinstance(files[f], CardDF):</span><br><span style="color: hsl(120, 100%, 40%);">+                              fcp_dec = self._cmd.rs.select(f, self._cmd)</span><br><span style="color: hsl(120, 100%, 40%);">+                           self.walk(indent + 1, action, context)</span><br><span style="color: hsl(120, 100%, 40%);">+                                fcp_dec = self._cmd.rs.select("..", self._cmd)</span><br><span style="color: hsl(120, 100%, 40%);">+                      elif action:</span><br><span style="color: hsl(120, 100%, 40%);">+                          action(f, context)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  def do_tree(self, opts):</span><br><span style="color: hsl(120, 100%, 40%);">+              """Display a filesystem-tree with all selectable files"""</span><br><span style="color: hsl(120, 100%, 40%);">+               self.walk()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> </span><br><span> </span><br><span> @with_default_category('USIM Commands')</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/pysim/+/23208">change 23208</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/pysim/+/23208"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: pysim </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: If93d24dfb80c83eda39303c936910fa1fa7f48f8 </div>
<div style="display:none"> Gerrit-Change-Number: 23208 </div>
<div style="display:none"> Gerrit-PatchSet: 5 </div>
<div style="display:none"> Gerrit-Owner: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-CC: dexter <pmaier@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>