From b0abdcccdb9fde6bbf0f95ae2c6c197271cb962a Mon Sep 17 00:00:00 2001 From: Rustam Zaitov Date: Thu, 3 Oct 2013 21:41:52 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8E=20dsl=20=D0=BA?= =?UTF-8?q?=20=D0=B1=D0=B8=D0=BB=D0=B4=20=D0=BA=D0=BE=D0=BC=D0=BC=D0=B0?= =?UTF-8?q?=D0=BD=D0=B4=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/ManualTests/__init__.py | 1 + scripts/ManualTests/info_plist_test.py | 26 ++++++++ scripts/commands/build_command.py | 6 +- scripts/commands/patch_csproj_command.py | 2 +- scripts/commands/patch_infoplist_command.py | 10 ++-- scripts/parser/AttributeNameParser.py | 8 +++ scripts/parser/StringValueParser.py | 10 ++++ scripts/parser/__init__.py | 1 + scripts/parser/csproj_sequential_parser.py | 66 +++++++++++++++++++++ scripts/settings.py | 12 ++-- 10 files changed, 126 insertions(+), 16 deletions(-) create mode 100644 scripts/ManualTests/__init__.py create mode 100644 scripts/ManualTests/info_plist_test.py create mode 100644 scripts/parser/AttributeNameParser.py create mode 100644 scripts/parser/StringValueParser.py create mode 100644 scripts/parser/__init__.py create mode 100644 scripts/parser/csproj_sequential_parser.py diff --git a/scripts/ManualTests/__init__.py b/scripts/ManualTests/__init__.py new file mode 100644 index 0000000..cc31abc --- /dev/null +++ b/scripts/ManualTests/__init__.py @@ -0,0 +1 @@ +__author__ = 'rzaitov' diff --git a/scripts/ManualTests/info_plist_test.py b/scripts/ManualTests/info_plist_test.py new file mode 100644 index 0000000..bbdfe52 --- /dev/null +++ b/scripts/ManualTests/info_plist_test.py @@ -0,0 +1,26 @@ +import commands.patch_infoplist_command as plist +import os + +config = { + 'version': '0.1.2', + + # patch_info_plist + 'plist-CoolApp_rel_path': 'BuildSample/Info.plist', + 'plist-CoolApp_CFBundleVersion': '@version', # set CFBundleVersion + 'plist-CoolApp_CFBundleDisplayName': '@app_name', # set CFBundleDisplayName + +} + +base_dir = '/Users/rzaitov/Documents/Apps/BuildScript', + +class PathProvider: + def __init__(self, base_dir): + self._base_dir = base_dir + + def ResolveAbsPath(self, rel_path): + abs_path = os.path.join(self._base_dir, rel_path) + return abs_path + +provider = PathProvider(base_dir) +patcher = plist.PatchInfoPlist(config, provider) +patcher.Execute() diff --git a/scripts/commands/build_command.py b/scripts/commands/build_command.py index a957e1b..df0f717 100644 --- a/scripts/commands/build_command.py +++ b/scripts/commands/build_command.py @@ -6,10 +6,10 @@ class BuildCommand: self._cmd_prefix_len = len(self._command_prefix) self._prefix_name= 'prefix' - self._group_name= 'group' + self._app_name= 'app' self._key_name = 'key' - def __init__(self, config, cmd_prefix, separator='-'): + def __init__(self, config, cmd_prefix, separator=' '): self._separator = separator self._config = config self.SetCommandPrefix(cmd_prefix) @@ -35,7 +35,7 @@ class BuildCommand: result = { self._prefix_name: identifiers[0], - self._group_name: identifiers[1], + self._app_name: identifiers[1], self._key_name: identifiers[2] } diff --git a/scripts/commands/patch_csproj_command.py b/scripts/commands/patch_csproj_command.py index 06200b8..867fed8 100644 --- a/scripts/commands/patch_csproj_command.py +++ b/scripts/commands/patch_csproj_command.py @@ -16,7 +16,7 @@ class PatchCsproj(bcmd.BuildCommand): for key_token in key_tokens: key_info = self.ParseKeyToken(key_token) - project_name = key_info[self._group_name] + project_name = key_info[self._app_name] key = key_info[self._key_name] value = self.ParseValueFromToken(self._config[key_token]) diff --git a/scripts/commands/patch_infoplist_command.py b/scripts/commands/patch_infoplist_command.py index 1f05c31..1c0d54e 100644 --- a/scripts/commands/patch_infoplist_command.py +++ b/scripts/commands/patch_infoplist_command.py @@ -4,9 +4,10 @@ import utils.infoplist.patcher as plist class PatchInfoPlist(bcmd.BuildCommand): - def __init__(self, config): - bcmd.BuildCommand.__init__(self, config, 'plist-') + 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 = {} self.ParseConfig() @@ -44,10 +45,7 @@ class PatchInfoPlist(bcmd.BuildCommand): return config_key[PatchInfoPlist._cmd_prefix_len:] def Execute(self): - sln_path = self._config['sln_path'] - pConverter = pc.PathConverter(sln_path) - - info_plist_abs_path = pConverter.Convert(self._info_plist_rel_path) + 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) diff --git a/scripts/parser/AttributeNameParser.py b/scripts/parser/AttributeNameParser.py new file mode 100644 index 0000000..c49226b --- /dev/null +++ b/scripts/parser/AttributeNameParser.py @@ -0,0 +1,8 @@ +import parser.StringValueParser as parser + +class AttributeNameParser(parser.StringValueParser): + def __init__(self, attribute_name, model): + parser.StringValueParser.__init__(self, attribute_name, model) + + def ProcessToken(self, token): + self._model.rel_path = '' diff --git a/scripts/parser/StringValueParser.py b/scripts/parser/StringValueParser.py new file mode 100644 index 0000000..135e3b9 --- /dev/null +++ b/scripts/parser/StringValueParser.py @@ -0,0 +1,10 @@ +class StringValueParser: + def __init__(self, valid_string, model): + self._valid_string = valid_string + self._model = model + + def IsTokenValid(self, token): + return token == self._valid_string + + def ProcessToken(self, token): + pass diff --git a/scripts/parser/__init__.py b/scripts/parser/__init__.py new file mode 100644 index 0000000..cc31abc --- /dev/null +++ b/scripts/parser/__init__.py @@ -0,0 +1 @@ +__author__ = 'rzaitov' diff --git a/scripts/parser/csproj_sequential_parser.py b/scripts/parser/csproj_sequential_parser.py new file mode 100644 index 0000000..e61347e --- /dev/null +++ b/scripts/parser/csproj_sequential_parser.py @@ -0,0 +1,66 @@ +from parser.StringValueParser import * +from parser.AttributeNameParser import * + +class CsprojParser: + def __init__(self, string_to_parse, value_token, config): + self._config = config + self._token_buffer = string_to_parse.split(' ') + self._token_buffer.append(value_token) + self._token_index = 0; + self._project = None + + def Parse(self): + while self._token_index < len(self._token_buffer): + self.ProcessToken() + + + def ProcessToken(self): + token = self.getCurrentToken() + + if self.isCsprojStatement(token): + self._token_index += 1 + elif self.isAppToken(token): + self.processAppToken(token) + self._token_index += 1 + elif self.isAttributeToken(token): + attribute_name = self.processAttributeNameToken(token) + self._token_index += 1 + token = self.getCurrentToken() + attribute_value = self.processAttributeValueToken(token) + setattr(self.project, attribute_name, attribute_value) + + def isCsprojStatement(self, token): + return token == 'csproj' + + def isAppToken(self, token): + return token.startswith('app:') + + def isAttributeToken(self, token): + return ':' not in token + + def processAppToken(self, appToken): + appName = appToken[len('app:')] + + self.project = Csproj(appName) + self._settings[appName] = self.project + + def processAttributeNameToken(self, token): + attribute_name = token + return attribute_name + + def processAttributeValueToken(self, token): + value = token + + if token.startswith('@'): + key = token[1:] + value = self._config[key] + + return value + + def getCurrentToken(self): + token = self._token_buffer[self._token_index] + return token + +class Csproj: + def __init__(self, appName): + self.appName = appName \ No newline at end of file diff --git a/scripts/settings.py b/scripts/settings.py index 29f2742..d448715 100644 --- a/scripts/settings.py +++ b/scripts/settings.py @@ -30,17 +30,17 @@ ios_development_root = { 'projects_to_exclude': ['NotCompileApp'], # patch_info_plist - 'plist-CoolApp_rel_path': 'BuildSample/Info.plist', - 'plist-CoolApp_CFBundleVersion': '@version', # set CFBundleVersion - 'plist-CoolApp_CFBundleDisplayName': '@app_name', # set CFBundleDisplayName + 'plist app:CoolApp rel_path': 'BuildSample/Info.plist', + 'plist app:CoolApp key:CFBundleVersion': '@version', # set CFBundleVersion + 'plist app:CoolApp key:CFBundleDisplayName': '@app_name', # set CFBundleDisplayName # test flight command section 'tf_CoolApp_output': 'ipa', # patch_csproj - 'csproj-CoolApp-rel_path': 'BuildSample/CoolApp.csproj', - 'csproj-CoolApp-CodesignProvision': '@codesign_provision', - 'csproj-CoolApp-CodesignKey': '@codesign_key', + 'csproj group:CoolApp key:rel_path': 'BuildSample/CoolApp.csproj', + 'csproj group:CoolApp key:CodesignProvision': '@codesign_provision', + 'csproj group:CoolApp key:CodesignKey': '@codesign_key', 'build_steps':[ # before build