diff --git a/scripts/TouchinBuild/CommandBuilders/PatchInfoPlistArrayCommandBuilder.py b/scripts/TouchinBuild/CommandBuilders/PatchInfoPlistArrayCommandBuilder.py new file mode 100644 index 0000000..bedceb4 --- /dev/null +++ b/scripts/TouchinBuild/CommandBuilders/PatchInfoPlistArrayCommandBuilder.py @@ -0,0 +1,31 @@ +from commands.PatchInfoPlistCommand import PatchInfoPlistCommand +from parsers.InsideParser.InsideSetArrayParser import InsideSetArrayParser + + +class PatchInfoPlistArrayCommandBuilder: + def __init__(self): + pass + + def isPatchInfoPlist(self, line): + assert line is not None + + parser = self.createParser() + isValid = parser.isValidLine(line) + + return isValid + + def getCommandFor(self, line): + parser = self.createParser() + result = parser.parseLine(line) + + path = result[0] + key = result[1] + value = result[2] + + command = PatchInfoPlistCommand(path, key, value) + return command + + def createParser(self): + parser = InsideSetArrayParser('plist') + return parser + diff --git a/scripts/TouchinBuild/CommandBuilders/PatchInfoplistCommandBuilder.py b/scripts/TouchinBuild/CommandBuilders/PatchInfoplistCommandBuilder.py index 7c56d72..612e15d 100644 --- a/scripts/TouchinBuild/CommandBuilders/PatchInfoplistCommandBuilder.py +++ b/scripts/TouchinBuild/CommandBuilders/PatchInfoplistCommandBuilder.py @@ -11,13 +11,13 @@ class PatchInfoplistCommandBuilder: def isPatchInfoPlist(self, line): assert line is not None - parser = self.__createParser() + parser = self.createParser() isValid = parser.isValidLine(line) return isValid def getCommandFor(self, line): - parser = self.__createParser() + parser = self.createParser() result = parser.parseLine(line) path = result[0] @@ -27,7 +27,7 @@ class PatchInfoplistCommandBuilder: command = PatchInfoPlistCommand(path, key, value) return command - def __createParser(self): + def createParser(self): parser = InsideSetParser('plist') return parser diff --git a/scripts/TouchinBuild/Tests/ManualTests/infoPlistMultipleValues_test.py b/scripts/TouchinBuild/Tests/ManualTests/infoPlistMultipleValues_test.py new file mode 100644 index 0000000..3528cfa --- /dev/null +++ b/scripts/TouchinBuild/Tests/ManualTests/infoPlistMultipleValues_test.py @@ -0,0 +1,8 @@ +from CommandBuilders.PatchInfoPlistArrayCommandBuilder import PatchInfoPlistArrayCommandBuilder + +line = "inside 'BuildSample/BuildSample/Info.plist' set UISupportedInterfaceOrientations to 'value1:value2:value3'" + +cmdBuilder = PatchInfoPlistArrayCommandBuilder() +command = cmdBuilder.getCommandFor(line) +command.execute() + diff --git a/scripts/TouchinBuild/Tests/ManualTests/infoplist_test.py b/scripts/TouchinBuild/Tests/ManualTests/infoPlistSingleValue_test.py similarity index 100% rename from scripts/TouchinBuild/Tests/ManualTests/infoplist_test.py rename to scripts/TouchinBuild/Tests/ManualTests/infoPlistSingleValue_test.py diff --git a/scripts/TouchinBuild/run_manual_tests.py b/scripts/TouchinBuild/run_manual_tests.py index 2a4db75..20deb9d 100644 --- a/scripts/TouchinBuild/run_manual_tests.py +++ b/scripts/TouchinBuild/run_manual_tests.py @@ -12,7 +12,7 @@ print 'current working dir: {0}'.format(baseDirAbsPath) #import ManualTests.info_plist_test #import ManualTests.copy_test #import Tests.ManualTests.create_backup_test -import Tests.ManualTests.delete_backup_test +#import Tests.ManualTests.delete_backup_test #import Tests.ManualTests.restore_backup_test #import ManualTests.csproj_test #import ManualTests.run_sh_command @@ -23,4 +23,6 @@ import Tests.ManualTests.delete_backup_test #import Tests.ManualTests.testflight_test #import Tests.ManualTests.install_profile #import Tests.ManualTests.macros_include_test -#import Tests.ManualTests.resolve_settings \ No newline at end of file +#import Tests.ManualTests.resolve_settings + +import Tests.ManualTests.infoPlistMultipleValues_test \ No newline at end of file diff --git a/scripts/TouchinBuild/utils/InfoPlistPatcher.py b/scripts/TouchinBuild/utils/InfoPlistPatcher.py index 3dc15f6..9be9127 100644 --- a/scripts/TouchinBuild/utils/InfoPlistPatcher.py +++ b/scripts/TouchinBuild/utils/InfoPlistPatcher.py @@ -9,8 +9,12 @@ class InfoPlistPatcher(): tree = eT.parse(self.__infoPlistPath) plist_dict = tree.getroot().find('dict') - for key_name in key_value_dict: - self.AppendOrReplaceValueByKey(key_name, key_value_dict[key_name], plist_dict) + for keyName in key_value_dict: + value = key_value_dict[keyName] + if type(value) is str: + self.AppendOrReplaceValueByKey(keyName, value, plist_dict) + else: + self.AppendOrReplaceValuesByKey(keyName, value, plist_dict) tree.write(self.__infoPlistPath, xml_declaration=True, encoding='UTF-8', method="xml") @@ -23,6 +27,15 @@ class InfoPlistPatcher(): else: self.AppendKeyValue(key_name, value, dict_element) + def AppendOrReplaceValuesByKey(self, keyName, valuesArr, dictElement): + keyIndex = self.FindIndexByKey(keyName, dictElement) + elementExists = keyIndex >= 0 + + if elementExists: + self.ReplaceValuesByKeyIndex(keyIndex, valuesArr, dictElement) + else: + self.AppendValues(keyName, valuesArr, dictElement) + def FindIndexByKey(self, key_name, dict_element): all_keys_elements = dict_element.findall('key') @@ -43,15 +56,49 @@ class InfoPlistPatcher(): value_element = dict_element[value_index] value_element.text = value - def AppendKeyValue(self, key_name, value, dict_element): - key_element = eT.Element('key') - key_element.text = key_name + def ReplaceValuesByKeyIndex(self, keyIndex, valueArr, dict_element): + valuesIndex = keyIndex + 1 + arrayElement = dict_element[valuesIndex] - value_element = eT.Element('string') - value_element.text = value + children = arrayElement.findall('string') + arrayElement.remove(children) + + self.fillArrayElementWithValues(arrayElement, valueArr) + + def AppendKeyValue(self, keyName, value, dict_element): + key_element = self.createKeyElement(keyName) + value_element = self.createValueElement(value) dict_element.append(key_element) dict_element.append(value_element) + def AppendValues(self, keyName, valuesArr, parentElement): + keyElement = self.createKeyElement(keyName) + + arrayElement = eT.Element('array') + self.fillArrayElementWithValues(arrayElement, valuesArr) + + parentElement.append(keyElement) + parentElement.append(arrayElement) + + def createKeyElement(self, keyName): + keyElement = eT.Element('key') + keyElement.text = keyName + + return keyElement + + def createValueElement(self, value): + valueElement = eT.Element('string') + valueElement.text = value + + return valueElement + + def fillArrayElementWithValues(self, arrayElement, values): + for value in values: + valueElement = self.createValueElement(value) + arrayElement.append(valueElement) + + +