реализовал патчинг manifest файла

This commit is contained in:
rzaitov 2013-11-14 19:59:12 +04:00
parent f46c5e0c78
commit cf255b7b1b
5 changed files with 79 additions and 12 deletions

View File

@ -1,6 +1,6 @@
from CommandBuilders.PatchManifestCommandBuilder import PatchManifestCommandBuilder
line = "inside 'BuildSample/DroidApp/Properties/AndroidManifest.xml' set android:versionCode to '777'"
line = "inside 'BuildSample/DroidApp/Properties/AndroidManifest.xml' set android:versionCode to '7.7.7'"
builder = PatchManifestCommandBuilder()

View File

@ -19,7 +19,7 @@ class InsideSetParser(InsideParserBase):
def getMatchInfo(self, line):
assert line is not None
keyRegexp = r'(?P<key>[a-zA-Z]+)'
keyRegexp = r'(?P<key>\S+)'
valueRegexp = r"'(?P<value>[^']+)'$"
rb = RegexpBuilder()

View File

@ -24,5 +24,6 @@ print 'current working dir: {0}'.format(baseDirAbsPath)
#import Tests.ManualTests.install_profile
#import Tests.ManualTests.macros_include_test
#import Tests.ManualTests.resolve_settings
#import Tests.ManualTests.infoPlistMultipleValues_test
import Tests.ManualTests.infoPlistMultipleValues_test
import Tests.ManualTests.manifest_test

View File

@ -1,16 +1,55 @@
import xml.etree.ElementTree as eT
from utils.XmlPatcher import XmlPatcher
class ManifestPatcher:
class ManifestPatcher(XmlPatcher):
def __init__(self, manifestPath):
assert manifestPath is not None
self.manifestPath = manifestPath
XmlPatcher.__init__(self, manifestPath)
def AddOrReplaceManifestAtr(self, atrName, atrValue):
tree = eT.parse(self.manifestPath)
manifestElement = tree.getroot().find('manifest')
self.androidNs = "http://schemas.android.com/apk/res/android"
self.androidNsPrefix = 'android'
manifestElement.attrib[atrName] = atrValue
self.namespaces[self.androidNsPrefix] = self.androidNs
self.regNamespace(self.androidNsPrefix, self.androidNs)
tree.write(self.manifestPath, xml_declaration=True, encoding='UTF-8', method="xml")
def AddOrReplaceManifestAtr(self, rawAtrName, atrValue):
assert rawAtrName is not None
assert atrValue is not None
tree = self.parse()
manifestElement = tree.getroot()
name = self.fetchNameByRawName(rawAtrName)
manifestElement.set(name, atrValue)
self.write(tree)
def fetchNameByRawName(self, rawName):
nameInfo = self.parseRawName(rawName)
name = self.fetchName(nameInfo)
return name
def parseRawName(self, rawName):
"""rawName=(nsPrefix:)?OriginalName
"""
result = rawName.split(':')
prefixExists = len(result) > 0
atrInfo = {
'prefix': result[0] if prefixExists else None,
'original_name': result[1]
}
return atrInfo
def fetchName(self, nameInfo):
assert nameInfo is not None
nsPrefix = nameInfo['prefix']
origName = nameInfo['original_name']
namespace = self.namespaces.get(nsPrefix, None)
name = self.getNameWithNs(origName, namespace) if nsPrefix else origName
return name

View File

@ -0,0 +1,27 @@
import xml.etree.ElementTree as eT
class XmlPatcher:
def __init__(self, path):
assert path is not None
self.path = path
self.namespaces = {}
def parse(self):
return eT.parse(self.path)
def write(self, tree):
tree.write(self.path, xml_declaration=True, encoding="UTF-8", method="xml")
def regNamespace(self, nsKey, nsValue):
assert nsKey is not None
assert nsValue is not None
eT.register_namespace(nsKey, nsValue)
def getNameWithNs(self, originalName, namespace):
assert originalName is not None
assert namespace is not None
# {someNamespace}OriginalName
return '{{{0}}}{1}'.format(namespace, originalName)