diff options
author | Harald Welte <laforge@gnumonks.org> | 2012-08-15 15:26:30 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2012-08-15 15:26:30 +0200 |
commit | 93315bd4663c87856cb5a64c16d7fedcab4a8bb6 (patch) | |
tree | 3b056b62066851e98f4fd2ceabc137101077a182 | |
parent | 69c2ce2525f1d5d8ad53d438a7a5bd433e496cce (diff) |
Introduce a '--dry-run' option to skip actual card access
This can be used for example to batch convert from CSV input to HLR
output without writing cards.
-rwxr-xr-x | pySim-prog.py | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/pySim-prog.py b/pySim-prog.py index d673dba..65b625f 100755 --- a/pySim-prog.py +++ b/pySim-prog.py @@ -138,6 +138,9 @@ def parse_options(): parser.add_option("--write-hlr", dest="write_hlr", metavar="FILE", help="Append generated parameters to OpenBSC HLR sqlite3", ) + parser.add_option("--dry-run", dest="dry_run", + help="Perform a 'dry run', don't actually program the card", + default=False, action="store_true") (options, args) = parser.parse_args() @@ -435,7 +438,7 @@ def write_params_hlr(opts, params): [ params['imsi'], params['name'], - '9' + params['iccid'][-5:] + '9' + params['iccid'][-5:-1] ], ) sub_id = c.lastrowid @@ -553,27 +556,30 @@ if __name__ == '__main__': card = None while not done: - # Connect transport - print "Insert card now (or CTRL-C to cancel)" - sl.wait_for_card(newcardonly=not first) + + if opts.dry_run is False: + # Connect transport + print "Insert card now (or CTRL-C to cancel)" + sl.wait_for_card(newcardonly=not first) # Not the first anymore ! first = False - # Get card - card = card_detect(opts, scc) - if card is None: - if opts.batch_mode: - first = False - continue - else: - sys.exit(-1) - - # Erase if requested - if opts.erase: - print "Formatting ..." - card.erase() - card.reset() + if opts.dry_run is False: + # Get card + card = card_detect(opts, scc) + if card is None: + if opts.batch_mode: + first = False + continue + else: + sys.exit(-1) + + # Erase if requested + if opts.erase: + print "Formatting ..." + card.erase() + card.reset() # Generate parameters if opts.source == 'cmdline': @@ -585,9 +591,13 @@ if __name__ == '__main__': sys.exit(2) print_parameters(cp) - # Program the card - print "Programming ..." - card.program(cp) + if opts.dry_run is False: + # Program the card + print "Programming ..." + if opts.dry_run is not True: + card.program(cp) + else: + print "Dry Run: NOT PROGRAMMING!" # Write parameters permanently write_parameters(opts, cp) |