Начал реализовывать функционал по замене множественных значений в Info.plist
This commit is contained in:
parent
9d93d6ff49
commit
810ab396d7
|
|
@ -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
|
||||
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
@ -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
|
||||
#import Tests.ManualTests.resolve_settings
|
||||
|
||||
import Tests.ManualTests.infoPlistMultipleValues_test
|
||||
|
|
@ -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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue