<p>laforge has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/pysim/+/23210">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">pySim-shell: add filesystem exporter<br><br>add a new command "export" that can either export indidividual files or<br>a whole directory tree. The command will generate a script that contains<br>update_binary and update_record commands along with the file contents.<br>This script can later be used to restore multiple files at once.<br><br>Change-Id: I82f3ce92cd91a5ed3c4884d62f6b22e9589c8a49<br>Related: OS#4963<br>---<br>M pySim-shell.py<br>1 file changed, 38 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/10/23210/1</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 4544220..957b1a5 100755</span><br><span>--- a/pySim-shell.py</span><br><span>+++ b/pySim-shell.py</span><br><span>@@ -148,6 +148,44 @@</span><br><span>            """Display a filesystem-tree with all selectable files"""</span><br><span>              self.walk()</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+       def export(self, filename):</span><br><span style="color: hsl(120, 100%, 40%);">+           path_list_fid = self._cmd.rs.selected_file.fully_qualified_path(True)</span><br><span style="color: hsl(120, 100%, 40%);">+         path_list = self._cmd.rs.selected_file.fully_qualified_path(False)</span><br><span style="color: hsl(120, 100%, 40%);">+            self._cmd.poutput("# directory:%s (%s)" % ('/'.join(path_list_fid), '/'.join(path_list)))</span><br><span style="color: hsl(120, 100%, 40%);">+           try:</span><br><span style="color: hsl(120, 100%, 40%);">+                  fcp_dec = self._cmd.rs.select(filename, self._cmd)</span><br><span style="color: hsl(120, 100%, 40%);">+                    path_list_fid = self._cmd.rs.selected_file.fully_qualified_path(True)</span><br><span style="color: hsl(120, 100%, 40%);">+                 path_list = self._cmd.rs.selected_file.fully_qualified_path(False)</span><br><span style="color: hsl(120, 100%, 40%);">+                    self._cmd.poutput("# file:%s (%s)" % (path_list_fid[-1], path_list[-1]))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                  fd = fcp_dec['file_descriptor']</span><br><span style="color: hsl(120, 100%, 40%);">+                       structure = fd['structure']</span><br><span style="color: hsl(120, 100%, 40%);">+                   self._cmd.poutput("# structure: %s" % str(structure))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+                     if structure == 'transparent':</span><br><span style="color: hsl(120, 100%, 40%);">+                                result = self._cmd.rs.read_binary()</span><br><span style="color: hsl(120, 100%, 40%);">+                           print ("update_binary " + str(result[0]))</span><br><span style="color: hsl(120, 100%, 40%);">+                   if structure == 'cyclic' or structure == 'linear_fixed':</span><br><span style="color: hsl(120, 100%, 40%);">+                              num_of_rec = fd['num_of_rec']</span><br><span style="color: hsl(120, 100%, 40%);">+                         for r in range(1, num_of_rec + 1):</span><br><span style="color: hsl(120, 100%, 40%);">+                                    result = self._cmd.rs.read_record(r)</span><br><span style="color: hsl(120, 100%, 40%);">+                                  print ("update_record %d %s" % (r, str(result[0])))</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%);">+              except Exception as e:</span><br><span style="color: hsl(120, 100%, 40%);">+                        self._cmd.poutput("# bad file:%s, %s" % (str(filename), str(e)))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+          self._cmd.poutput("")</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     export_parser = argparse.ArgumentParser()</span><br><span style="color: hsl(120, 100%, 40%);">+     export_parser.add_argument('--filename', type=str, default=None, help='only export specific file')</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  @cmd2.with_argparser(export_parser)</span><br><span style="color: hsl(120, 100%, 40%);">+   def do_export(self, opts):</span><br><span style="color: hsl(120, 100%, 40%);">+            """Export files to script that can be imported back later"""</span><br><span style="color: hsl(120, 100%, 40%);">+            if opts.filename:</span><br><span style="color: hsl(120, 100%, 40%);">+                     self.export(opts.filename)</span><br><span style="color: hsl(120, 100%, 40%);">+            else:</span><br><span style="color: hsl(120, 100%, 40%);">+                 self.walk(0, self.export)</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/+/23210">change 23210</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/+/23210"/><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: I82f3ce92cd91a5ed3c4884d62f6b22e9589c8a49 </div>
<div style="display:none"> Gerrit-Change-Number: 23210 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>