diff --git a/scripts/CommandBuilders/PatchInfoplistCommandBuilder.py b/scripts/CommandBuilders/PatchInfoplistCommandBuilder.py new file mode 100644 index 0000000..466c5b4 --- /dev/null +++ b/scripts/CommandBuilders/PatchInfoplistCommandBuilder.py @@ -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 + diff --git a/scripts/ManualTests/info_plist_test.py b/scripts/ManualTests/infoplist_test.py similarity index 60% rename from scripts/ManualTests/info_plist_test.py rename to scripts/ManualTests/infoplist_test.py index 032dd36..55e26df 100644 --- a/scripts/ManualTests/info_plist_test.py +++ b/scripts/ManualTests/infoplist_test.py @@ -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() diff --git a/scripts/commands/PatchInfoPlistCommand.py b/scripts/commands/PatchInfoPlistCommand.py new file mode 100644 index 0000000..fbd97b0 --- /dev/null +++ b/scripts/commands/PatchInfoPlistCommand.py @@ -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) diff --git a/scripts/commands/patch_infoplist_command.py b/scripts/commands/patch_infoplist_command.py deleted file mode 100644 index e855b17..0000000 --- a/scripts/commands/patch_infoplist_command.py +++ /dev/null @@ -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) diff --git a/scripts/run_manual_tests.py b/scripts/run_manual_tests.py index 6e6c1ca..077bfeb 100644 --- a/scripts/run_manual_tests.py +++ b/scripts/run_manual_tests.py @@ -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 \ No newline at end of file +import ManualTests.infoplist_test \ No newline at end of file diff --git a/scripts/utils/infoplist/patcher.py b/scripts/utils/infoplist/patcher.py index 02305af..3d349d0 100644 --- a/scripts/utils/infoplist/patcher.py +++ b/scripts/utils/infoplist/patcher.py @@ -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)