Merge branch 'patch-plist'
This commit is contained in:
commit
02807b5f19
|
|
@ -0,0 +1,33 @@
|
|||
from commands.PatchInfoPlistCommand import PatchInfoPlistCommand
|
||||
from parser.InsideParser.InsideSetParser import InsideSetParser
|
||||
|
||||
|
||||
class PatchInfoplistCommandBuilder:
|
||||
def __init__(self, valueProvider):
|
||||
assert valueProvider is not None
|
||||
|
||||
self.__valueProvider = valueProvider
|
||||
|
||||
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 = InsideSetParser(self.__valueProvider, 'plist')
|
||||
return parser
|
||||
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
from CommandBuilders.PatchInfoplistCommandBuilder import PatchInfoplistCommandBuilder
|
||||
from commands.ValueProvider import ValueProvider
|
||||
import commands.patch_infoplist_command as plist
|
||||
import path_provider
|
||||
|
||||
config = {
|
||||
'version': '0.1.2',
|
||||
|
|
@ -11,10 +10,10 @@ config = {
|
|||
'plist app:CoolApp key:CFBundleVersion': '@version', # set CFBundleVersion
|
||||
'plist app:CoolApp key:CFBundleDisplayName': '@app_name', # set CFBundleDisplayName
|
||||
}
|
||||
line = "inside 'BuildSample/BuildSample/Info.plist' set CFBundleDisplayName to 'MyCoolApp'"
|
||||
|
||||
base_dir = '/Users/rzaitov/Documents/Apps/BuildScript/BuildSample'
|
||||
provider = path_provider.PathProvider(base_dir)
|
||||
value_provider = ValueProvider(config)
|
||||
builder = PatchInfoplistCommandBuilder(value_provider)
|
||||
|
||||
command = plist.PatchInfoPlist(config, provider, value_provider)
|
||||
command = builder.getCommandFor(line)
|
||||
command.execute()
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
from utils.infoplist.patcher import Patcher
|
||||
|
||||
|
||||
class PatchInfoPlistCommand():
|
||||
def __init__(self, pathToPlist, key, value):
|
||||
assert pathToPlist is not None
|
||||
assert key is not None
|
||||
assert value is not None
|
||||
|
||||
self.__pathToPlist = pathToPlist
|
||||
self.__key = key
|
||||
self.__value = value
|
||||
|
||||
def execute(self):
|
||||
patcher = Patcher(self.__pathToPlist)
|
||||
|
||||
dict = { self.__key : self.__value }
|
||||
patcher.AddOrReplace(dict)
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
from commands.patch_project import PatchProject
|
||||
from utils.infoplist.patcher import Patcher
|
||||
|
||||
|
||||
class PatchInfoPlist(PatchProject):
|
||||
def __init__(self, config, path_provider, value_provider):
|
||||
PatchProject.__init__(self, config, path_provider, value_provider, 'plist')
|
||||
|
||||
def _patchProject(self, project):
|
||||
abs_path = self._path_provider.resolveAbsPath(project.rel_path)
|
||||
|
||||
patcher = Patcher(abs_path)
|
||||
patcher.AddOrReplace(project.settings)
|
||||
|
|
@ -15,5 +15,6 @@ os.chdir(baseDir)
|
|||
#import ManualTests.csproj_test
|
||||
#import ManualTests.run_sh_command
|
||||
#import ManualTests.make_dirs
|
||||
#import ManualTests.remove_project
|
||||
|
||||
import ManualTests.remove_project
|
||||
import ManualTests.infoplist_test
|
||||
|
|
@ -2,17 +2,17 @@ import xml.etree.ElementTree as eT
|
|||
|
||||
|
||||
class Patcher():
|
||||
def __init__(self, abs_plist_path):
|
||||
self._abs_plist_path = abs_plist_path
|
||||
def __init__(self, infoPlistPath):
|
||||
self.__infoPlistPath = infoPlistPath
|
||||
|
||||
def AddOrReplace(self, key_value_dict):
|
||||
tree = eT.parse(self._abs_plist_path)
|
||||
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)
|
||||
|
||||
tree.write(self._abs_plist_path, xml_declaration=True, encoding='UTF-8', method="xml")
|
||||
tree.write(self.__infoPlistPath, xml_declaration=True, encoding='UTF-8', method="xml")
|
||||
|
||||
def AppendOrReplaceValueByKey(self, key_name, value, dict_element):
|
||||
key_index = self.FindIndexByKey(key_name, dict_element)
|
||||
|
|
|
|||
Loading…
Reference in New Issue