blob: 9ba0907793f50df9ed7416a987d21f2c9453cc4d [file] [log] [blame]
Rashed Abdel-Tawab0d2fa552018-09-06 08:48:26 -07001#!/usr/bin/env python
2#
3# Copyright (C) 2018 The LineageOS Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18import sys
19from xml.dom.minidom import parseString
20
21def main(argv):
22 reload(sys)
23 sys.setdefaultencoding('utf8')
iprouteth0a7b81aa2021-04-09 21:26:02 -050024 original_file = 'vendor/bliss/prebuilt/common/etc/apns-conf.xml'
Rashed Abdel-Tawab0d2fa552018-09-06 08:48:26 -070025
26 if len(argv) == 3:
27 output_file_path = argv[1]
28 custom_override_file = argv[2]
29 else:
30 raise ValueError("Wrong number of arguments %s" % len(argv))
31
32 custom_apn_names = []
33 with open(custom_override_file, 'r') as f:
34 for line in f:
35 xmltree = parseString(line)
36 carrier = xmltree.getElementsByTagName('apn')[0].getAttribute('carrier')
37 custom_apn_names.append(carrier)
38
39 with open(original_file, 'r') as input_file:
40 with open(output_file_path, 'w') as output_file:
41 for line in input_file:
42 writeOriginalLine = True
43 for apn in custom_apn_names:
44 if apn in line:
45 with open(custom_override_file, 'r') as custom_file:
46 for override_line in custom_file:
47 if apn in override_line:
48 output_file.write(override_line)
49 writeOriginalLine = False
50 custom_apn_names.remove(apn)
51 if writeOriginalLine:
52 if "</apns>" in line:
53 if custom_apn_names:
54 for apn in custom_apn_names:
55 with open(custom_override_file, 'r') as custom_file:
56 for override_line in custom_file:
57 if apn in override_line:
58 output_file.write(override_line)
59 output_file.write(line)
60
61if __name__ == '__main__':
62 main(sys.argv)