Fix custom_apns script
Removing an element from the list that is currently iterated does not work. At least it may skip the next element. Also the handling of duplicate APN names was broken: It would output the lines containing duplicate APN names times the number of the duplication, i.e. the exact same line would be duplicated. So use a `set` for storing apn names. Change-Id: Id54d245dc935117cd4640ae0f1f30b8608c87459
This commit is contained in:
committed by
Jan Altensen (Stricted)
parent
ba14020f85
commit
faca8c641c
@@ -29,26 +29,27 @@ def main(argv):
|
||||
else:
|
||||
raise ValueError("Wrong number of arguments %s" % len(argv))
|
||||
|
||||
custom_apn_names = []
|
||||
custom_apn_names = set()
|
||||
with open(custom_override_file, 'r') as f:
|
||||
for line in f:
|
||||
xmltree = parseString(line)
|
||||
carrier = xmltree.getElementsByTagName('apn')[0].getAttribute('carrier')
|
||||
custom_apn_names.append('"' + carrier + '"')
|
||||
custom_apn_names.add('"' + carrier + '"')
|
||||
|
||||
with open(original_file, 'r') as input_file:
|
||||
with open(output_file_path, 'w') as output_file:
|
||||
for line in input_file:
|
||||
writeOriginalLine = True
|
||||
found_custom_apns = set()
|
||||
for apn in custom_apn_names:
|
||||
if apn in line:
|
||||
with open(custom_override_file, 'r') as custom_file:
|
||||
for override_line in custom_file:
|
||||
if apn in override_line:
|
||||
output_file.write(override_line)
|
||||
writeOriginalLine = False
|
||||
custom_apn_names.remove(apn)
|
||||
if writeOriginalLine:
|
||||
found_custom_apns.add(apn)
|
||||
if found_custom_apns:
|
||||
custom_apn_names -= found_custom_apns
|
||||
else:
|
||||
if "</apns>" in line:
|
||||
if custom_apn_names:
|
||||
for apn in custom_apn_names:
|
||||
|
Reference in New Issue
Block a user