diff --git a/scripts/ManualTests/info_plist_test.py b/scripts/ManualTests/info_plist_test.py index 1b959d8..032dd36 100644 --- a/scripts/ManualTests/info_plist_test.py +++ b/scripts/ManualTests/info_plist_test.py @@ -1,3 +1,4 @@ +from commands.ValueProvider import ValueProvider import commands.patch_infoplist_command as plist import path_provider @@ -11,8 +12,9 @@ config = { 'plist app:CoolApp key:CFBundleDisplayName': '@app_name', # set CFBundleDisplayName } -base_dir = '/Users/rzaitov/Documents/Apps/BuildScript', +base_dir = '/Users/rzaitov/Documents/Apps/BuildScript/BuildSample' provider = path_provider.PathProvider(base_dir) +value_provider = ValueProvider(config) -patcher = plist.PatchInfoPlist(config, provider) -patcher.execute() +command = plist.PatchInfoPlist(config, provider, value_provider) +command.execute() diff --git a/scripts/ManualTests/path_provider.py b/scripts/ManualTests/path_provider.py index 80563e9..b050f0e 100644 --- a/scripts/ManualTests/path_provider.py +++ b/scripts/ManualTests/path_provider.py @@ -3,12 +3,8 @@ import os class PathProvider: def __init__(self, base_dir): self._base_dir = base_dir - print self._base_dir def resolveAbsPath(self, rel_path): - print self._base_dir - print rel_path - abs_path = os.path.join(self._base_dir, rel_path) return abs_path diff --git a/scripts/commands/patch_csproj_command.py b/scripts/commands/patch_csproj_command.py index 313bc86..cef15aa 100644 --- a/scripts/commands/patch_csproj_command.py +++ b/scripts/commands/patch_csproj_command.py @@ -1,45 +1,12 @@ -import commands.build_command as bcmd -from parser.ProjectParser.ProjectParser import ProjectParser +from commands.patch_project import PatchProject import utils.csproj.patcher as csproj -class PatchCsproj(bcmd.BuildCommand): +class PatchCsproj(PatchProject): def __init__(self, config, path_provider, value_provider): - assert path_provider is not None - assert value_provider is not None + PatchProject.__init__(self, config, path_provider, value_provider, 'csproj') - bcmd.BuildCommand.__init__(self, config, 'csproj') - self._path_provider = path_provider - self._value_provider = value_provider - self._parser = None + def _patchProject(self, project): + csproj_abs_path = self._path_provider.resolveAbsPath(project.rel_path) - self._parseConfig() - - def _parseConfig(self): - csproj_keys = self.FetchAllKeysFromConfig() - line_collection = self.__fetchLineCollection(csproj_keys) - - self.__fillPatchSettings(line_collection) - - def __fetchLineCollection(self, keys): - assert keys is not None - - line_collection = ["{0} '{1}'".format(k, self._config[k]) for k in keys] - return line_collection - - def __fillPatchSettings(self, line_collection): - assert line_collection is not None - - self._parser = ProjectParser(line_collection, self._value_provider) - self._parser.parse() - - def execute(self): - projects = self._parser.projects_dict.values() - - for project in projects: - self.__patchProject(project) - - def __patchProject(self, project): - csproj_abs_path = self._path_provider.resolveAbsPath(project.rel_path) - - patcher = csproj.Patcher(csproj_abs_path) - patcher.AddOrReplace(project.settings, self._config['sln_config']) \ No newline at end of file + patcher = csproj.Patcher(csproj_abs_path) + patcher.AddOrReplace(project.settings, self._config['sln_config']) \ No newline at end of file diff --git a/scripts/commands/patch_infoplist_command.py b/scripts/commands/patch_infoplist_command.py index 2da9612..e855b17 100644 --- a/scripts/commands/patch_infoplist_command.py +++ b/scripts/commands/patch_infoplist_command.py @@ -1,51 +1,13 @@ -import commands.build_command as bcmd -import utils.PathConverter.path_converter as pc -import utils.infoplist.patcher as plist +from commands.patch_project import PatchProject +from utils.infoplist.patcher import Patcher -class PatchInfoPlist(bcmd.BuildCommand): - def __init__(self, config, path_provider): - bcmd.BuildCommand.__init__(self, config, 'plist') - self._info_plist_rel_path = None - self._path_provider = path_provider - self._plist_dict = {} +class PatchInfoPlist(PatchProject): + def __init__(self, config, path_provider, value_provider): + PatchProject.__init__(self, config, path_provider, value_provider, 'plist') - self._parseConfig() + def _patchProject(self, project): + abs_path = self._path_provider.resolveAbsPath(project.rel_path) - def _parseConfig(self): - self.FetchInfoPlistPath() - self.FetchAllParams() - - def FetchInfoPlistPath(self): - self._info_plist_rel_path = self._config['info_plist_rel_path'] - - def FetchAllParams(self): - all_conf_keys = self.FetchAllConfigKeys() - - for k in all_conf_keys: - self.AddValueFor(k) - - def FetchAllConfigKeys(self): - all_keys = [] - for k in self._config.keys(): - if k.startswith(PatchInfoPlist._command_prefix) and not k.endswith('rel_path'): - all_keys.append(k) - - return all_keys - - def AddValueFor(self, conf_key): - value_token = self._config[conf_key] - value = self.ParseValueFromToken(value_token) - - k = self.ParsePlistKeyFrom(conf_key) - self._plist_dict[k] = value - - - def ParsePlistKeyFrom(self, config_key): - return config_key[PatchInfoPlist._cmd_prefix_len:] - - def execute(self): - info_plist_abs_path = self._path_provider.resolveAbsPath(self._info_plist_rel_path) - patcher = plist.Patcher(info_plist_abs_path) - - patcher.AddOrReplace(self._plist_dict) + patcher = Patcher(abs_path) + patcher.AddOrReplace(project.settings) diff --git a/scripts/commands/patch_project.py b/scripts/commands/patch_project.py new file mode 100644 index 0000000..2e70eca --- /dev/null +++ b/scripts/commands/patch_project.py @@ -0,0 +1,47 @@ +import commands.build_command as bcmd +from parser.ProjectParser.ProjectParser import ProjectParser + + +class PatchProject(bcmd.BuildCommand): + def __init__(self, config, path_provider, value_provider, command_token): + assert path_provider is not None + assert value_provider is not None + assert command_token is not None + + bcmd.BuildCommand.__init__(self, config, command_token) + self._path_provider = path_provider + self._value_provider = value_provider + self._command_token = command_token + + self._parser = None + + self._parseConfig() + + def _parseConfig(self): + csproj_keys = self.FetchAllKeysFromConfig() + line_collection = self.__fetchLineCollection(csproj_keys) + + self.__fillPatchSettings(line_collection) + + def __fetchLineCollection(self, keys): + assert keys is not None + + line_collection = ["{0} '{1}'".format(k, self._config[k]) for k in keys] + return line_collection + + def __fillPatchSettings(self, line_collection): + assert line_collection is not None + + self._parser = ProjectParser(line_collection, self._value_provider, self._command_token) + self._parser.parse() + + def execute(self): + projects = self._parser.projects_dict.values() + + for project in projects: + self._patchProject(project) + + def _patchProject(self, project): + print 'Do nothing' + # override this method to do useful work + pass diff --git a/scripts/parser/ProjectParser/ProjectParser.py b/scripts/parser/ProjectParser/ProjectParser.py index 04f59e1..9322faa 100644 --- a/scripts/parser/ProjectParser/ProjectParser.py +++ b/scripts/parser/ProjectParser/ProjectParser.py @@ -3,12 +3,14 @@ from parser.ProjectParser.ProjectLineParser import ProjectLineParser class ProjectParser: - def __init__(self, line_collection, value_provider): + def __init__(self, line_collection, value_provider, command_token): assert line_collection is not None assert value_provider is not None + assert command_token is not None self._line_collection = line_collection self._value_provider = value_provider + self._command_token = command_token self.projects_dict = {} def parse(self): @@ -30,7 +32,7 @@ class ProjectParser: return project def __parse_line(self, line): - line_parser = ProjectLineParser(self._value_provider, 'csproj') + line_parser = ProjectLineParser(self._value_provider, self._command_token) setting = line_parser.parse(line) return setting \ No newline at end of file diff --git a/scripts/run_manual_tests.py b/scripts/run_manual_tests.py index 2fe0325..117f43b 100644 --- a/scripts/run_manual_tests.py +++ b/scripts/run_manual_tests.py @@ -1 +1,2 @@ import ManualTests.csproj_test +import ManualTests.info_plist_test \ No newline at end of file diff --git a/scripts/utils/infoplist/patcher.py b/scripts/utils/infoplist/patcher.py index a216d2a..02305af 100644 --- a/scripts/utils/infoplist/patcher.py +++ b/scripts/utils/infoplist/patcher.py @@ -12,7 +12,7 @@ class Patcher(): for key_name in key_value_dict: self.AppendOrReplaceValueByKey(key_name, key_value_dict[key_name], plist_dict) - tree.write(self._abs_plist_path) + tree.write(self._abs_plist_path, xml_declaration=True, encoding='UTF-8', method="xml") def AppendOrReplaceValueByKey(self, key_name, value, dict_element): key_index = self.FindIndexByKey(key_name, dict_element)