mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-16 18:38:32 +03:00
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
This commit is contained in:
committed by
Harald Welte
parent
639806cc5a
commit
398fdd7e8c
@@ -348,8 +348,7 @@ Online manual available at https://downloads.osmocom.org/docs/pysim/master/html/
|
||||
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,
|
||||
@@ -365,7 +364,7 @@ Online manual available at https://downloads.osmocom.org/docs/pysim/master/html/
|
||||
"""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
|
||||
|
||||
@@ -390,7 +389,7 @@ Online manual available at https://downloads.osmocom.org/docs/pysim/master/html/
|
||||
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()
|
||||
@@ -442,13 +441,13 @@ Online manual available at https://downloads.osmocom.org/docs/pysim/master/html/
|
||||
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):
|
||||
|
||||
@@ -627,19 +627,19 @@ class TransparentEF(CardEF):
|
||||
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):
|
||||
@@ -647,9 +647,9 @@ class TransparentEF(CardEF):
|
||||
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)
|
||||
@@ -842,13 +842,13 @@ class LinFixedEF(CardEF):
|
||||
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)
|
||||
@@ -860,12 +860,12 @@ class LinFixedEF(CardEF):
|
||||
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()
|
||||
@@ -899,13 +899,13 @@ class LinFixedEF(CardEF):
|
||||
|
||||
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)
|
||||
|
||||
@@ -913,31 +913,31 @@ class LinFixedEF(CardEF):
|
||||
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
|
||||
@@ -951,7 +951,7 @@ class LinFixedEF(CardEF):
|
||||
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)
|
||||
|
||||
@@ -1303,12 +1303,12 @@ class BerTlvEF(CardEF):
|
||||
|
||||
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):
|
||||
@@ -1318,24 +1318,24 @@ class BerTlvEF(CardEF):
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@@ -906,14 +906,14 @@ class CardProfileUICC(CardProfile):
|
||||
'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
|
||||
|
||||
@@ -1707,14 +1707,14 @@ class ADF_USIM(CardADF):
|
||||
@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()
|
||||
|
||||
@@ -1076,12 +1076,12 @@ class DF_GSM(CardDF):
|
||||
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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user