-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
random: Add scripts to copy IMS APN as well as sort APNs
(cherry picked from commit c6201a8) Signed-off-by: Omkar Chandorkar <[email protected]> Signed-off-by: Akhil Narang <[email protected]>
- Loading branch information
1 parent
1f2974a
commit 10860ba
Showing
2 changed files
with
48 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python | ||
|
||
import sys | ||
from pathlib import Path | ||
from xml.etree import ElementTree | ||
|
||
# ./sort_apn.py apns-conf.xml | ||
# If no arguments are provided, the user will be prompted to enter the file paths | ||
|
||
if len(sys.argv) < 2: | ||
apns = input("Enter the apns-conf XML path: ") | ||
else: | ||
apns = sys.argv[1] | ||
|
||
apns_path = Path(apns) | ||
|
||
if not apns_path.exists(): | ||
print("Please ensure that the files exist") | ||
sys.exit(1) | ||
|
||
def sort_apns(apns_path): | ||
# Parse the XML file into an ElementTree | ||
tree = ElementTree.parse(apns_path) | ||
root = tree.getroot() | ||
|
||
# Sort the children of the root by 'mcc' and 'mnc' | ||
root[:] = sorted(root, key=lambda child: (child.attrib.get('mcc', ''), child.attrib.get('mnc', ''))) | ||
|
||
# Write the sorted ElementTree back into the XML file | ||
with open(apns_path, 'wb') as f: | ||
f.write(ElementTree.tostring(root, encoding='utf-8')) | ||
|
||
# Call the function with the XML file path | ||
sort_apns(apns_path) |