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.
This commit is contained in:
Harald Welte
2012-08-15 15:26:30 +02:00
parent c26b82939f
commit e9e5ecbe30

View File

@@ -141,6 +141,9 @@ def parse_options():
parser.add_option("--write-hlr", dest="write_hlr", metavar="FILE", parser.add_option("--write-hlr", dest="write_hlr", metavar="FILE",
help="Append generated parameters to OpenBSC HLR sqlite3", 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() (options, args) = parser.parse_args()
@@ -451,7 +454,7 @@ def write_params_hlr(opts, params):
[ [
params['imsi'], params['imsi'],
params['name'], params['name'],
'9' + params['iccid'][-5:] '9' + params['iccid'][-5:-1]
], ],
) )
sub_id = c.lastrowid sub_id = c.lastrowid
@@ -569,27 +572,30 @@ if __name__ == '__main__':
card = None card = None
while not done: while not done:
# Connect transport
print "Insert card now (or CTRL-C to cancel)" if opts.dry_run is False:
sl.wait_for_card(newcardonly=not first) # Connect transport
print "Insert card now (or CTRL-C to cancel)"
sl.wait_for_card(newcardonly=not first)
# Not the first anymore ! # Not the first anymore !
first = False first = False
# Get card if opts.dry_run is False:
card = card_detect(opts, scc) # Get card
if card is None: card = card_detect(opts, scc)
if opts.batch_mode: if card is None:
first = False if opts.batch_mode:
continue first = False
else: continue
sys.exit(-1) else:
sys.exit(-1)
# Erase if requested # Erase if requested
if opts.erase: if opts.erase:
print "Formatting ..." print "Formatting ..."
card.erase() card.erase()
card.reset() card.reset()
# Generate parameters # Generate parameters
if opts.source == 'cmdline': if opts.source == 'cmdline':
@@ -601,9 +607,13 @@ if __name__ == '__main__':
sys.exit(2) sys.exit(2)
print_parameters(cp) print_parameters(cp)
# Program the card if opts.dry_run is False:
print "Programming ..." # Program the card
card.program(cp) print "Programming ..."
if opts.dry_run is not True:
card.program(cp)
else:
print "Dry Run: NOT PROGRAMMING!"
# Write parameters permanently # Write parameters permanently
write_parameters(opts, cp) write_parameters(opts, cp)