Merge branch 'BS-47'

This commit is contained in:
rzaitov 2013-11-14 20:29:26 +04:00
commit 3e66f2a8c2
12 changed files with 176 additions and 4 deletions

View File

@ -0,0 +1,24 @@
from commands.PatchManifestCommand import PatchManifestCommand
from parsers.InsideParser.InsideSetParser import InsideSetParser
class PatchManifestCommandBuilder:
def __init__(self):
pass
def isManifestCommand(self, line):
assert line is not None
parser = InsideSetParser('xml')
isValid = parser.isValidLine(line)
return isValid
def getCommandFor(self, line):
assert line is not None
parser = InsideSetParser('xml')
result = parser.parseLine(line)
command = PatchManifestCommand(result[0], result[1], result[2])
return command

View File

@ -47,6 +47,6 @@ contentProvider = ContentProviderMock()
buildConfigProvider = BuildConfigProvider()
preprocessor = NullPreprocessor()
taskRunner = TaskRunner(settingsProvider, contentProvider, buildConfigProvider, preprocessor)
taskRunner = TaskRunner(settingsProvider, contentProvider, buildConfigProvider, preprocessor, {})
taskRunner.run()

View File

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

View File

@ -40,7 +40,7 @@ resolvedBuildConfigProvider = ResolvedBuildConfigProvider(buildConfigProvider)
contentProvider = ContentProviderMock()
preprocessor = NullPreprocessor()
taskRunner = TaskRunner(settingsProvider, contentProvider, resolvedBuildConfigProvider, preprocessor)
taskRunner = TaskRunner(settingsProvider, contentProvider, resolvedBuildConfigProvider, preprocessor, {})
taskRunner.run()

View File

@ -0,0 +1 @@
__author__ = 'rzaitov'

View File

@ -0,0 +1,25 @@
import unittest
from utils.ManifestPatcher import ManifestPatcher
class TestManifestPatcher(unittest.TestCase):
def setUp(self):
self.patcher = ManifestPatcher('somePath')
def test_parseRawName(self):
nameInfo1 = self.patcher.parseRawName('simpleName')
self.assertEqual(None, nameInfo1['prefix'])
self.assertEqual('simpleName', nameInfo1['original_name'])
nameInfo2 = self.patcher.parseRawName('prefix:originalName')
self.assertEqual('prefix', nameInfo2['prefix'])
self.assertEqual('originalName', nameInfo2['original_name'])
def test_fetchName(self):
nameInfo = {
'prefix': 'android',
'original_name': 'MyName'
}
name = self.patcher.fetchName(nameInfo)
self.assertEqual('{http://schemas.android.com/apk/res/android}MyName', name)

View File

@ -0,0 +1,11 @@
import unittest
from utils.XmlPatcher import XmlPatcher
class TestXmlPatcher(unittest.TestCase):
def setUp(self):
self.patcher = XmlPatcher('somePath')
def test_getNameWithNs(self):
name = self.patcher.getNameWithNs('OriginalName', 'http://namespace')
self.assertEqual('{http://namespace}OriginalName', name)

View File

@ -0,0 +1,20 @@
from commands.CommandBase import CommandBase
from utils.ManifestPatcher import ManifestPatcher
class PatchManifestCommand(CommandBase):
def __init__(self, pathToManifest, key, value):
CommandBase.__init__(self)
assert pathToManifest is not None
assert key is not None
assert value is not None
self.pathToManifest = pathToManifest
self.key = key
self.value = value
def execute(self):
patcher = ManifestPatcher(self.pathToManifest)
patcher.AddOrReplaceManifestAtr(self.key, self.value)

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

@ -0,0 +1,55 @@
from utils.XmlPatcher import XmlPatcher
class ManifestPatcher(XmlPatcher):
def __init__(self, manifestPath):
assert manifestPath is not None
XmlPatcher.__init__(self, manifestPath)
self.androidNs = "http://schemas.android.com/apk/res/android"
self.androidNsPrefix = 'android'
self.namespaces[self.androidNsPrefix] = self.androidNs
self.regNamespace(self.androidNsPrefix, self.androidNs)
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) > 1
nameInfo = {
'prefix': result[0] if prefixExists else None,
'original_name': result[1] if prefixExists else result[0]
}
return nameInfo
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)