Change in pysim[master]: pySim-shell: tree/export: catch errors during DF selection

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/.

dexter gerrit-no-reply at lists.osmocom.org
Fri Apr 9 19:20:12 UTC 2021


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


Change subject: pySim-shell: tree/export: catch errors during DF selection
......................................................................

pySim-shell: tree/export: catch errors during DF selection

When a DF is selected, then the method walk() does not catch the
related execption, which causes the command to stop immediately. Lets
also catch those exceptions and generate appropriate error messages
during export.

Change-Id: I24ccf64965e7b0756c3db77eb2084b22c357a570
Related: OS#4963
---
M pySim-shell.py
1 file changed, 31 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/86/23686/1

diff --git a/pySim-shell.py b/pySim-shell.py
index 3059f3f..29138cc 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -176,10 +176,26 @@
 					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)
+				skip_df=False
+				try:
+					fcp_dec = self._cmd.rs.select(f, self._cmd)
+				except Exception as e:
+					skip_df=True
+					df = self._cmd.rs.selected_file
+					df_path_list = df.fully_qualified_path(True)
+					df_skip_reason_str = '/'.join(df_path_list) + "/" + str(f) + ", " + str(e)
+					if context:
+						context['DF_SKIP'] += 1
+						context['DF_SKIP_REASON'].append(df_skip_reason_str)
+
+				# If the DF was skipped, we never have entered the directory
+				# below, so we must not move up.
+				if skip_df == False:
+					self.walk(indent + 1, action, context)
+					fcp_dec = self._cmd.rs.select("..", self._cmd)
+
 			elif action:
 				df_before_action = self._cmd.rs.selected_file
 				action(f, context)
@@ -251,7 +267,7 @@
 	@cmd2.with_argparser(export_parser)
 	def do_export(self, opts):
 		"""Export files to script that can be imported back later"""
-		context = {'ERR':0, 'COUNT':0, 'BAD':[]}
+		context = {'ERR':0, 'COUNT':0, 'BAD':[], 'DF_SKIP':0, 'DF_SKIP_REASON':[]}
 		if opts.filename:
 			self.export(opts.filename, context)
 		else:
@@ -260,8 +276,17 @@
 		self._cmd.poutput("# bad files:           %u" % context['ERR'])
 		for b in context['BAD']:
 			self._cmd.poutput("#  " + b)
-		if context['ERR']:
-			raise RuntimeError("unable to export %i file(s)" % context['ERR'])
+
+		self._cmd.poutput("# skipped dedicated files(s): %u" % context['DF_SKIP'])
+		for b in context['DF_SKIP_REASON']:
+			self._cmd.poutput("#  " + b)
+
+		if context['ERR'] and context['DF_SKIP']:
+			raise RuntimeError("unable to export %i elementry file(s) and %i dedicated file(s)" % (context['ERR'], context['DF_SKIP']))
+		elif context['ERR']:
+			raise RuntimeError("unable to export %i elementry file(s)" % context['ERR'])
+		elif context['DF_SKIP']:
+			raise RuntimeError("unable to export %i dedicated files(s)" % context['ERR'])
 
 
 @with_default_category('ISO7816 Commands')

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

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I24ccf64965e7b0756c3db77eb2084b22c357a570
Gerrit-Change-Number: 23686
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210409/961f00fb/attachment.htm>


More information about the gerrit-log mailing list