From 3becc5945e03b3bf4cb20cc3bb4ae2fa67b44333 Mon Sep 17 00:00:00 2001 From: Rustam Zaitov Date: Mon, 7 Oct 2013 01:52:44 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BC=D0=BE=D0=B4=D0=B8=D1=84=D0=B8=D1=86?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BB=20=D0=BA=D0=BB=D0=B0=D1=81?= =?UTF-8?q?=D1=81=20PatchCsproj=20=D1=87=D1=82=D0=BE=D0=B1=D1=8B=20=D0=BE?= =?UTF-8?q?=D0=BD=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=BB=20=D1=81=20?= =?UTF-8?q?csproj=20=D0=BF=D0=B0=D1=80=D1=81=D0=B5=D1=80=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/ManualTests/csproj_test.py | 2 +- scripts/ManualTests/info_plist_test.py | 2 +- scripts/UnitTests/ValueProvider/__init__.py | 1 + .../ValueProvider/test_valueProvider.py | 18 +++++++++ scripts/commands/ValueProvider.py | 15 +++++++ scripts/commands/build_command.py | 4 +- scripts/commands/patch_csproj_command.py | 40 ++++++++++++------- scripts/commands/patch_infoplist_command.py | 6 +-- scripts/commands/testflight_command.py | 2 +- 9 files changed, 67 insertions(+), 23 deletions(-) create mode 100644 scripts/UnitTests/ValueProvider/__init__.py create mode 100644 scripts/UnitTests/ValueProvider/test_valueProvider.py create mode 100644 scripts/commands/ValueProvider.py diff --git a/scripts/ManualTests/csproj_test.py b/scripts/ManualTests/csproj_test.py index 92c3ee8..db3d714 100644 --- a/scripts/ManualTests/csproj_test.py +++ b/scripts/ManualTests/csproj_test.py @@ -15,4 +15,4 @@ base_dir = '/Users/rzaitov/Documents/Apps/BuildScript' provider = path_provider.PathProvider(base_dir) patcher = csproj.PatchCsproj(config, provider) -patcher.Execute() +patcher.execute() diff --git a/scripts/ManualTests/info_plist_test.py b/scripts/ManualTests/info_plist_test.py index e3d5ca2..1b959d8 100644 --- a/scripts/ManualTests/info_plist_test.py +++ b/scripts/ManualTests/info_plist_test.py @@ -15,4 +15,4 @@ base_dir = '/Users/rzaitov/Documents/Apps/BuildScript', provider = path_provider.PathProvider(base_dir) patcher = plist.PatchInfoPlist(config, provider) -patcher.Execute() +patcher.execute() diff --git a/scripts/UnitTests/ValueProvider/__init__.py b/scripts/UnitTests/ValueProvider/__init__.py new file mode 100644 index 0000000..cc31abc --- /dev/null +++ b/scripts/UnitTests/ValueProvider/__init__.py @@ -0,0 +1 @@ +__author__ = 'rzaitov' diff --git a/scripts/UnitTests/ValueProvider/test_valueProvider.py b/scripts/UnitTests/ValueProvider/test_valueProvider.py new file mode 100644 index 0000000..6d0e2ae --- /dev/null +++ b/scripts/UnitTests/ValueProvider/test_valueProvider.py @@ -0,0 +1,18 @@ +import unittest +from commands.ValueProvider import ValueProvider + + +class TestCase(unittest.TestCase): + def setUp(self): + self.__config = { + 'key1': 'value1', + 'key2': 'value2' + } + self.__provider = ValueProvider(self.__config) + + def test_provideByLink(self): + value1 = self.__provider.getValueFor('@key1') + value2 = self.__provider.getValueFor('@key2') + + self.assertEqual(value1, 'value1') + self.assertEqual(value2, 'value2') diff --git a/scripts/commands/ValueProvider.py b/scripts/commands/ValueProvider.py new file mode 100644 index 0000000..8423cb9 --- /dev/null +++ b/scripts/commands/ValueProvider.py @@ -0,0 +1,15 @@ +class ValueProvider: + def __init__(self, config): + assert config is not None + + self.__config = config + + def getValueFor(self, link): + is_link = link.startswith('@') + result = link + + if is_link: + key = link[1:] + result = self.__config[key] + + return result \ No newline at end of file diff --git a/scripts/commands/build_command.py b/scripts/commands/build_command.py index 1848b87..3eb1db0 100644 --- a/scripts/commands/build_command.py +++ b/scripts/commands/build_command.py @@ -15,7 +15,7 @@ class BuildCommand: self.SetCommandPrefix(cmd_prefix) - def ParseConfig(self): + def _parseConfig(self): return None @@ -40,5 +40,5 @@ class BuildCommand: return value - def Execute(self): + def execute(self): return None diff --git a/scripts/commands/patch_csproj_command.py b/scripts/commands/patch_csproj_command.py index efc8666..945bc14 100644 --- a/scripts/commands/patch_csproj_command.py +++ b/scripts/commands/patch_csproj_command.py @@ -1,35 +1,45 @@ import commands.build_command as bcmd +from parser.CsprojParser.CsprojParser import CsprojParser import utils.csproj.patcher as csproj -import parser.CsprojParser.CsprojLineParser as parser class PatchCsproj(bcmd.BuildCommand): - def __init__(self, config, path_provider): + def __init__(self, config, path_provider, value_provider): + assert path_provider is not None + assert value_provider is not None + bcmd.BuildCommand.__init__(self, config, 'csproj') self._path_provider = path_provider + self._value_provider = value_provider self._parser = None - self.ParseConfig() + self._parseConfig() - def ParseConfig(self): + def _parseConfig(self): csproj_keys = self.FetchAllKeysFromConfig() - self.FillPatchSettings(csproj_keys) + line_collection = self.__fetchLineCollection(csproj_keys) + self.__fillPatchSettings(line_collection) - def FillPatchSettings(self, key_tokens): - self._parser = parser.CsprojLineParser(self._config) + def __fetchLineCollection(self, keys): + assert keys is not None - for key_token in key_tokens: - self._parser.parse(key_token, self._config[key_token]) + 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 - def Execute(self): - projects_list = self._parser.getProjects() + self._parser = CsprojParser(line_collection, self._value_provider) + self._parser.parse() - for project in projects_list: - self.PatchProject(project) + def execute(self): + projects = self._parser.projects_dict.values() - def PatchProject(self, project): + 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']) + 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 e08db4e..2da9612 100644 --- a/scripts/commands/patch_infoplist_command.py +++ b/scripts/commands/patch_infoplist_command.py @@ -10,9 +10,9 @@ class PatchInfoPlist(bcmd.BuildCommand): self._path_provider = path_provider self._plist_dict = {} - self.ParseConfig() + self._parseConfig() - def ParseConfig(self): + def _parseConfig(self): self.FetchInfoPlistPath() self.FetchAllParams() @@ -44,7 +44,7 @@ class PatchInfoPlist(bcmd.BuildCommand): def ParsePlistKeyFrom(self, config_key): return config_key[PatchInfoPlist._cmd_prefix_len:] - def Execute(self): + def execute(self): info_plist_abs_path = self._path_provider.resolveAbsPath(self._info_plist_rel_path) patcher = plist.Patcher(info_plist_abs_path) diff --git a/scripts/commands/testflight_command.py b/scripts/commands/testflight_command.py index dd4c40d..eb6f20d 100644 --- a/scripts/commands/testflight_command.py +++ b/scripts/commands/testflight_command.py @@ -6,5 +6,5 @@ class PublishToTestFlightCommand(bcmd.BuildCommand): def __init__(self, api_token, team_token, notes): self._publisher = tf.TestFlightPublisherBase(api_token, team_token, notes) - def Execute(self): + def execute(self): self._publisher.Publish() \ No newline at end of file