dexter has uploaded this change for review. (
https://gerrit.osmocom.org/c/pysim/+/38008?usp=email )
Change subject: pySim-shell: use upper case letters for positional arguments
......................................................................
pySim-shell: use upper case letters for positional arguments
When we define positional arguments for the argument parser, we usually
use upper case letters only. However, there are some code locations that
use lower case letters. Let's translate those to capital letters to
have a consistent appeariance.
Related: OS#6531
Change-Id: Iec1ff8262bc6e9cf87c3cbf7b32fa5f753b7e574
---
M pySim-shell.py
M pySim/filesystem.py
M pySim/ts_102_221.py
M pySim/ts_31_102.py
M pySim/ts_51_011.py
5 files changed, 36 insertions(+), 37 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/08/38008/1
diff --git a/pySim-shell.py b/pySim-shell.py
index 52e78d4..e0e0812 100755
--- a/pySim-shell.py
+++ b/pySim-shell.py
@@ -346,8 +346,7 @@
return -1
bulk_script_parser = argparse.ArgumentParser()
- bulk_script_parser.add_argument(
- 'script_path', help="path to the script file")
+ bulk_script_parser.add_argument('SCRIPT_PATH', help="path to the script
file")
bulk_script_parser.add_argument('--halt_on_error', help='stop card
handling if an exeption occurs',
action='store_true')
bulk_script_parser.add_argument('--tries', type=int, default=2,
@@ -363,7 +362,7 @@
"""Run script on multiple cards (bulk provisioning)"""
# Make sure that the script file exists and that it is readable.
- if not os.access(opts.script_path, os.R_OK):
+ if not os.access(opts.SCRIPT_PATH, os.R_OK):
self.poutput("Invalid script file!")
return
@@ -388,7 +387,7 @@
os.system(opts.pre_card_action)
# process the card
- rc = self._process_card(first, opts.script_path)
+ rc = self._process_card(first, opts.SCRIPT_PATH)
if rc == 0:
success_count = success_count + 1
self._show_success_sign()
@@ -440,13 +439,13 @@
first = False
echo_parser = argparse.ArgumentParser()
- echo_parser.add_argument('string', help="string to echo on the shell",
nargs='+')
+ echo_parser.add_argument('STRING', help="string to echo on the shell",
nargs='+')
@cmd2.with_argparser(echo_parser)
@cmd2.with_category(CUSTOM_CATEGORY)
def do_echo(self, opts):
"""Echo (print) a string on the console"""
- self.poutput(' '.join(opts.string))
+ self.poutput(' '.join(opts.STRING))
@cmd2.with_category(CUSTOM_CATEGORY)
def do_version(self, opts):
diff --git a/pySim/filesystem.py b/pySim/filesystem.py
index b166bc2..df6b59e 100644
--- a/pySim/filesystem.py
+++ b/pySim/filesystem.py
@@ -626,19 +626,19 @@
upd_bin_parser = argparse.ArgumentParser()
upd_bin_parser.add_argument(
'--offset', type=auto_uint16, default=0, help='Byte offset for
start of read')
- upd_bin_parser.add_argument('data', type=is_hexstr, help='Data bytes
(hex format) to write')
+ upd_bin_parser.add_argument('DATA', type=is_hexstr, help='Data bytes
(hex format) to write')
@cmd2.with_argparser(upd_bin_parser)
def do_update_binary(self, opts):
"""Update (Write) data of a transparent EF"""
- (data, _sw) = self._cmd.lchan.update_binary(opts.data, opts.offset)
+ (data, _sw) = self._cmd.lchan.update_binary(opts.DATA, opts.offset)
if data:
self._cmd.poutput(data)
upd_bin_dec_parser = argparse.ArgumentParser()
upd_bin_dec_parser.add_argument('--json-path', type=str,
help='JSON path to modify specific
element of file only')
- upd_bin_dec_parser.add_argument('data', help='Abstract data (JSON
format) to write')
+ upd_bin_dec_parser.add_argument('DATA', help='Abstract data (JSON
format) to write')
@cmd2.with_argparser(upd_bin_dec_parser)
def do_update_binary_decoded(self, opts):
@@ -646,9 +646,9 @@
if opts.json_path:
(data_json, _sw) = self._cmd.lchan.read_binary_dec()
js_path_modify(data_json, opts.json_path,
- json.loads(opts.data))
+ json.loads(opts.DATA))
else:
- data_json = json.loads(opts.data)
+ data_json = json.loads(opts.DATA)
(data, _sw) = self._cmd.lchan.update_binary_dec(data_json)
if data:
self._cmd.poutput_json(data)
@@ -841,13 +841,13 @@
read_rec_parser.add_argument(
'--count', type=auto_uint8, default=1, help='Number of records to
be read, beginning at record_nr')
read_rec_parser.add_argument(
- 'record_nr', type=auto_uint8, help='Number of record to be read')
+ 'RECORD_NR', type=auto_uint8, help='Number of record to be read')
@cmd2.with_argparser(read_rec_parser)
def do_read_record(self, opts):
"""Read one or multiple records from a record-oriented EF"""
for r in range(opts.count):
- recnr = opts.record_nr + r
+ recnr = opts.RECORD_NR + r
(data, _sw) = self._cmd.lchan.read_record(recnr)
if len(data) > 0:
recstr = str(data)
@@ -859,12 +859,12 @@
read_rec_dec_parser.add_argument('--oneline', action='store_true',
help='No JSON pretty-printing, dump
as a single line')
read_rec_dec_parser.add_argument(
- 'record_nr', type=auto_uint8, help='Number of record to be read')
+ 'RECORD_NR', type=auto_uint8, help='Number of record to be read')
@cmd2.with_argparser(read_rec_dec_parser)
def do_read_record_decoded(self, opts):
"""Read + decode a record from a record-oriented EF"""
- (data, _sw) = self._cmd.lchan.read_record_dec(opts.record_nr)
+ (data, _sw) = self._cmd.lchan.read_record_dec(opts.RECORD_NR)
self._cmd.poutput_json(data, opts.oneline)
read_recs_parser = argparse.ArgumentParser()
@@ -898,13 +898,13 @@
upd_rec_parser = argparse.ArgumentParser()
upd_rec_parser.add_argument(
- 'record_nr', type=auto_uint8, help='Number of record to be read')
- upd_rec_parser.add_argument('data', type=is_hexstr, help='Data bytes
(hex format) to write')
+ 'RECORD_NR', type=auto_uint8, help='Number of record to be read')
+ upd_rec_parser.add_argument('DATA', type=is_hexstr, help='Data bytes
(hex format) to write')
@cmd2.with_argparser(upd_rec_parser)
def do_update_record(self, opts):
"""Update (write) data to a record-oriented EF"""
- (data, _sw) = self._cmd.lchan.update_record(opts.record_nr,
opts.data)
+ (data, _sw) = self._cmd.lchan.update_record(opts.RECORD_NR,
opts.DATA)
if data:
self._cmd.poutput(data)
@@ -912,31 +912,31 @@
upd_rec_dec_parser.add_argument('--json-path', type=str,
help='JSON path to modify specific
element of record only')
upd_rec_dec_parser.add_argument(
- 'record_nr', type=auto_uint8, help='Number of record to be read')
+ 'RECORD_NR', type=auto_uint8, help='Number of record to be read')
upd_rec_dec_parser.add_argument('data', help='Abstract data (JSON
format) to write')
@cmd2.with_argparser(upd_rec_dec_parser)
def do_update_record_decoded(self, opts):
"""Encode + Update (write) data to a record-oriented EF"""
if opts.json_path:
- (data_json, _sw) =
self._cmd.lchan.read_record_dec(opts.record_nr)
+ (data_json, _sw) =
self._cmd.lchan.read_record_dec(opts.RECORD_NR)
js_path_modify(data_json, opts.json_path,
json.loads(opts.data))
else:
data_json = json.loads(opts.data)
(data, _sw) = self._cmd.lchan.update_record_dec(
- opts.record_nr, data_json)
+ opts.RECORD_NR, data_json)
if data:
self._cmd.poutput(data)
edit_rec_dec_parser = argparse.ArgumentParser()
edit_rec_dec_parser.add_argument(
- 'record_nr', type=auto_uint8, help='Number of record to be edited')
+ 'RECORD_NR', type=auto_uint8, help='Number of record to be edited')
@cmd2.with_argparser(edit_rec_dec_parser)
def do_edit_record_decoded(self, opts):
"""Edit the JSON representation of one record in an editor."""
- (orig_json, _sw) = self._cmd.lchan.read_record_dec(opts.record_nr)
+ (orig_json, _sw) = self._cmd.lchan.read_record_dec(opts.RECORD_NR)
with tempfile.TemporaryDirectory(prefix='pysim_') as dirname:
filename = '%s/file' % dirname
# write existing data as JSON to file
@@ -950,7 +950,7 @@
self._cmd.poutput("Data not modified, skipping write")
else:
(data, _sw) = self._cmd.lchan.update_record_dec(
- opts.record_nr, edited_json)
+ opts.RECORD_NR, edited_json)
if data:
self._cmd.poutput_json(data)
@@ -1302,12 +1302,12 @@
retrieve_data_parser = argparse.ArgumentParser()
retrieve_data_parser.add_argument(
- 'tag', type=auto_int, help='BER-TLV Tag of value to retrieve')
+ 'TAG', type=auto_int, help='BER-TLV Tag of value to retrieve')
@cmd2.with_argparser(retrieve_data_parser)
def do_retrieve_data(self, opts):
"""Retrieve (Read) data from a BER-TLV EF"""
- (data, _sw) = self._cmd.lchan.retrieve_data(opts.tag)
+ (data, _sw) = self._cmd.lchan.retrieve_data(opts.TAG)
self._cmd.poutput(data)
def do_retrieve_tags(self, _opts):
@@ -1317,24 +1317,24 @@
set_data_parser = argparse.ArgumentParser()
set_data_parser.add_argument(
- 'tag', type=auto_int, help='BER-TLV Tag of value to set')
+ 'TAG', type=auto_int, help='BER-TLV Tag of value to set')
set_data_parser.add_argument('data', type=is_hexstr, help='Data bytes
(hex format) to write')
@cmd2.with_argparser(set_data_parser)
def do_set_data(self, opts):
"""Set (Write) data for a given tag in a BER-TLV EF"""
- (data, _sw) = self._cmd.lchan.set_data(opts.tag, opts.data)
+ (data, _sw) = self._cmd.lchan.set_data(opts.TAG, opts.data)
if data:
self._cmd.poutput(data)
del_data_parser = argparse.ArgumentParser()
del_data_parser.add_argument(
- 'tag', type=auto_int, help='BER-TLV Tag of value to set')
+ 'TAG', type=auto_int, help='BER-TLV Tag of value to set')
@cmd2.with_argparser(del_data_parser)
def do_delete_data(self, opts):
"""Delete data for a given tag in a BER-TLV EF"""
- (data, _sw) = self._cmd.lchan.set_data(opts.tag, None)
+ (data, _sw) = self._cmd.lchan.set_data(opts.TAG, None)
if data:
self._cmd.poutput(data)
diff --git a/pySim/ts_102_221.py b/pySim/ts_102_221.py
index 9e0db68..15307a1 100644
--- a/pySim/ts_102_221.py
+++ b/pySim/ts_102_221.py
@@ -905,14 +905,14 @@
'Negotiated Duration: %u secs, Token: %s, SW: %s' % (duration,
token, sw))
resume_uicc_parser = argparse.ArgumentParser()
- resume_uicc_parser.add_argument('token', type=str, help='Token
provided during SUSPEND')
+ resume_uicc_parser.add_argument('TOKEN', type=str, help='Token
provided during SUSPEND')
@cmd2.with_argparser(resume_uicc_parser)
def do_resume_uicc(self, opts):
"""Perform the REUSME UICC operation. Only supported on some UICC.
Also: A power-cycle
of the card is required between SUSPEND and RESUME, and only very
few non-RESUME
commands are permitted between SUSPEND and RESUME. See TS 102 221
Section 11.1.22."""
- self._cmd.card._scc.resume_uicc(opts.token)
+ self._cmd.card._scc.resume_uicc(opts.TOKEN)
term_cap_parser = argparse.ArgumentParser()
# power group
diff --git a/pySim/ts_31_102.py b/pySim/ts_31_102.py
index c82cd2f..4161ad8 100644
--- a/pySim/ts_31_102.py
+++ b/pySim/ts_31_102.py
@@ -1706,14 +1706,14 @@
@with_default_category('Application-Specific Commands')
class AddlShellCommands(CommandSet):
authenticate_parser = argparse.ArgumentParser()
- authenticate_parser.add_argument('rand', type=is_hexstr, help='Random
challenge')
- authenticate_parser.add_argument('autn', type=is_hexstr,
help='Authentication Nonce')
+ authenticate_parser.add_argument('RAND', type=is_hexstr, help='Random
challenge')
+ authenticate_parser.add_argument('AUTN', type=is_hexstr,
help='Authentication Nonce')
#authenticate_parser.add_argument('--context', help='Authentication
context', default='3G')
@cmd2.with_argparser(authenticate_parser)
def do_authenticate(self, opts):
"""Perform Authentication and Key Agreement (AKA)."""
- (data, _sw) = self._cmd.lchan.scc.authenticate(opts.rand,
opts.autn)
+ (data, _sw) = self._cmd.lchan.scc.authenticate(opts.RAND,
opts.AUTN)
self._cmd.poutput_json(data)
term_prof_parser = argparse.ArgumentParser()
diff --git a/pySim/ts_51_011.py b/pySim/ts_51_011.py
index f6bd3cc..6d834f0 100644
--- a/pySim/ts_51_011.py
+++ b/pySim/ts_51_011.py
@@ -1072,12 +1072,12 @@
super().__init__()
authenticate_parser = argparse.ArgumentParser()
- authenticate_parser.add_argument('rand', type=is_hexstr, help='Random
challenge')
+ authenticate_parser.add_argument('RAND', type=is_hexstr, help='Random
challenge')
@cmd2.with_argparser(authenticate_parser)
def do_authenticate(self, opts):
"""Perform GSM Authentication."""
- (data, sw) = self._cmd.lchan.scc.run_gsm(opts.rand)
+ (data, sw) = self._cmd.lchan.scc.run_gsm(opts.RAND)
self._cmd.poutput_json(data)
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/38008?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Iec1ff8262bc6e9cf87c3cbf7b32fa5f753b7e574
Gerrit-Change-Number: 38008
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <[email protected]>