Change in pysim[master]: pySim-read: Migrate over to use shared argparse from transport

laforge gerrit-no-reply at lists.osmocom.org
Sun Apr 11 10:35:34 UTC 2021


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


Change subject: pySim-read: Migrate over to use shared argparse from transport
......................................................................

pySim-read: Migrate over to use shared argparse from transport

Now that we have a shared argparse definition for all reader related
options in the transport module, use that.

Change-Id: I12ca1a484a5d6e84820d9761c9701f8a94381f66
---
M docs/legacy.rst
M pySim-read.py
2 files changed, 12 insertions(+), 53 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/pysim refs/changes/22/23722/1

diff --git a/docs/legacy.rst b/docs/legacy.rst
index dad83d8..ec3ddfc 100644
--- a/docs/legacy.rst
+++ b/docs/legacy.rst
@@ -84,18 +84,9 @@
  * EF.IST
 
 
-::
+pySim-read usage
+~~~~~~~~~~~~~~~~
 
-  Usage: pySim-read.py [options]
-
-  Options:
-    -h, --help            show this help message and exit
-    -d DEV, --device=DEV  Serial Device for SIM access [default: /dev/ttyUSB0]
-    -b BAUD, --baud=BAUD  Baudrate used for SIM access [default: 9600]
-    -p PCSC, --pcsc-device=PCSC
-                          Which PC/SC reader number for SIM access
-    --modem-device=DEV    Serial port of modem for Generic SIM Access (3GPP TS
-                          27.007)
-    --modem-baud=BAUD     Baudrate used for modem's port [default: 115200]
-    --osmocon=PATH        Socket path for Calypso (e.g. Motorola C1XX) based
-                          reader (via OsmocomBB)
+.. argparse::
+   :module: pySim-read
+   :func: option_parser
diff --git a/pySim-read.py b/pySim-read.py
index 59c5762..9f32627 100755
--- a/pySim-read.py
+++ b/pySim-read.py
@@ -23,7 +23,7 @@
 #
 
 import hashlib
-from optparse import OptionParser
+import argparse
 import os
 import random
 import re
@@ -33,53 +33,21 @@
 from pySim.ts_31_103 import EF_IST_map, EF_ISIM_ADF_map
 
 from pySim.commands import SimCardCommands
-from pySim.transport import init_reader
+from pySim.transport import init_reader, argparse_add_reader_args
 from pySim.cards import card_detect, Card, UsimCard, IsimCard
 from pySim.utils import h2b, swap_nibbles, rpad, dec_imsi, dec_iccid, dec_msisdn
 from pySim.utils import format_xplmn_w_act, dec_spn, dec_st, dec_addr_tlv
 from pySim.utils import h2s, format_ePDGSelection
 
-def parse_options():
-
-	parser = OptionParser(usage="usage: %prog [options]")
-
-	parser.add_option("-d", "--device", dest="device", metavar="DEV",
-			help="Serial Device for SIM access [default: %default]",
-			default="/dev/ttyUSB0",
-		)
-	parser.add_option("-b", "--baud", dest="baudrate", type="int", metavar="BAUD",
-			help="Baudrate used for SIM access [default: %default]",
-			default=9600,
-		)
-	parser.add_option("-p", "--pcsc-device", dest="pcsc_dev", type='int', metavar="PCSC",
-			help="Which PC/SC reader number for SIM access",
-			default=None,
-		)
-	parser.add_option("--modem-device", dest="modem_dev", metavar="DEV",
-			help="Serial port of modem for Generic SIM Access (3GPP TS 27.007)",
-			default=None,
-		)
-	parser.add_option("--modem-baud", dest="modem_baud", type="int", metavar="BAUD",
-			help="Baudrate used for modem's port [default: %default]",
-			default=115200,
-		)
-	parser.add_option("--osmocon", dest="osmocon_sock", metavar="PATH",
-			help="Socket path for Calypso (e.g. Motorola C1XX) based reader (via OsmocomBB)",
-			default=None,
-		)
-
-	(options, args) = parser.parse_args()
-
-	if args:
-		parser.error("Extraneous arguments")
-
-	return options
-
+option_parser = argparse.ArgumentParser(prog='pySim-read',
+                        description='Legacy tool for reading some parts of a SIM card',
+                        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
+argparse_add_reader_args(option_parser)
 
 if __name__ == '__main__':
 
 	# Parse options
-	opts = parse_options()
+	opts = option_parser.parse_args()
 
 	# Init card reader driver
 	sl = init_reader(opts)

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

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I12ca1a484a5d6e84820d9761c9701f8a94381f66
Gerrit-Change-Number: 23722
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210411/dbca779a/attachment.htm>


More information about the gerrit-log mailing list