read_params_csv: Make sure we don't end up in endless loop

as a side effect, the first line is now specified with '-j 0'
and not '-j 1'
This commit is contained in:
Harald Welte 2012-08-15 15:25:51 +02:00
parent 7f62cecb61
commit c26b82939f
1 changed files with 14 additions and 8 deletions

View File

@ -410,7 +410,7 @@ def write_params_csv(opts, params):
cw.writerow([params[x] for x in row])
f.close()
def read_params_csv(opts, imsi):
def _read_params_csv(opts, imsi):
import csv
row = ['name', 'iccid', 'mcc', 'mnc', 'imsi', 'smsp', 'ki', 'opc']
f = open(opts.read_csv, 'r')
@ -418,19 +418,25 @@ def read_params_csv(opts, imsi):
i = 0
for row in cr:
if opts.num is not None:
i += 1
if opts.num == i:
break
f.close()
return row;
i += 1
if row['imsi'] == imsi:
break
if row:
row['mcc'] = int(row['mcc'])
row['mnc'] = int(row['mnc'])
f.close()
return row;
f.close()
return None
def read_params_csv(opts, imsi):
row = _read_params_csv(opts, imsi)
if row is not None:
row['mcc'] = int(row['mcc'])
row['mnc'] = int(row['mnc'])
return row
def write_params_hlr(opts, params):
# SQLite3 OpenBSC HLR
if opts.write_hlr: