Created
April 21, 2015 10:45
-
-
Save ineersa/77651e978a6db13f528f to your computer and use it in GitHub Desktop.
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
import xml.etree.ElementTree as ET | |
def indent(elem, level=0): | |
i = "\n" + level*" " | |
if len(elem): | |
if not elem.text or not elem.text.strip(): | |
elem.text = i + " " | |
if not elem.tail or not elem.tail.strip(): | |
elem.tail = i | |
for elem in elem: | |
indent(elem, level+1) | |
if not elem.tail or not elem.tail.strip(): | |
elem.tail = i | |
else: | |
if level and (not elem.tail or not elem.tail.strip()): | |
elem.tail = i | |
ET.register_namespace('android', 'http://schemas.android.com/apk/res/android') | |
template_tree = ET.parse('template.xml') | |
template_root = template_tree.getroot() | |
tree = ET.parse('AndroidManifest.xml') | |
root = tree.getroot() | |
ET.register_namespace('android', 'http://schemas.android.com/apk/res/android') | |
j = 0 | |
for child in root.iter('uses-permission'): | |
j += 1 | |
permissions = template_root.findall('uses-permission') | |
for child in permissions: | |
j += 1 | |
root.insert(j, child) | |
application = root.find('application') | |
activities = template_root.findall('activity') | |
for child in activities: | |
application.append(child) | |
receiver = template_root.find('receiver') | |
application.append(receiver) | |
services = template_root.findall('service') | |
for child in services: | |
application.append(child) | |
indent(root) | |
tree.write("AndroidManifest.xml") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment