From 9dea142c7a592bab3cedb9dad2fd5942f3a4ba39 Mon Sep 17 00:00:00 2001 From: Rustam Zaitov Date: Thu, 3 Oct 2013 23:39:54 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9E=D1=82=D0=BB=D0=B0=D0=B4=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D0=B0=D1=82=D1=87=D0=B8=D0=BD=D0=B3=20csproj=20=D1=84?= =?UTF-8?q?=D0=B0=D0=B9=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/ManualTests/info_plist_test.py | 20 ++----- scripts/commands/build_command.py | 5 +- scripts/commands/patch_csproj_command.py | 6 +- scripts/commands/patch_infoplist_command.py | 2 +- scripts/parser/csproj_sequential_parser.py | 66 --------------------- scripts/run_manual_tests.py | 1 + scripts/utils/csproj/patcher.py | 10 +++- 7 files changed, 23 insertions(+), 87 deletions(-) delete mode 100644 scripts/parser/csproj_sequential_parser.py create mode 100644 scripts/run_manual_tests.py diff --git a/scripts/ManualTests/info_plist_test.py b/scripts/ManualTests/info_plist_test.py index bbdfe52..e3d5ca2 100644 --- a/scripts/ManualTests/info_plist_test.py +++ b/scripts/ManualTests/info_plist_test.py @@ -1,26 +1,18 @@ import commands.patch_infoplist_command as plist -import os +import path_provider config = { 'version': '0.1.2', + 'app_name': 'TestAppName', # 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 } base_dir = '/Users/rzaitov/Documents/Apps/BuildScript', +provider = path_provider.PathProvider(base_dir) -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 3f8d0b8..1848b87 100644 --- a/scripts/commands/build_command.py +++ b/scripts/commands/build_command.py @@ -23,9 +23,10 @@ class BuildCommand: all_keys = [] for k in self._config: - k.startswith(self._command_prefix) - all_keys.append(k) + if k.startswith(self._command_prefix): + all_keys.append(k) + print all_keys return all_keys diff --git a/scripts/commands/patch_csproj_command.py b/scripts/commands/patch_csproj_command.py index 92dc8b3..239afd0 100644 --- a/scripts/commands/patch_csproj_command.py +++ b/scripts/commands/patch_csproj_command.py @@ -8,6 +8,8 @@ class PatchCsproj(bcmd.BuildCommand): self._path_provider = path_provider self._parser = None + self.ParseConfig() + def ParseConfig(self): csproj_keys = self.FetchAllKeysFromConfig() self.FillPatchSettings(csproj_keys) @@ -21,13 +23,13 @@ class PatchCsproj(bcmd.BuildCommand): def Execute(self): - projects_list = self._parser.projects + projects_list = self._parser.getProjects() for project in projects_list: self.PatchProject(project) def PatchProject(self, project): - csproj_abs_path = self._path_provider.fetchAbsPath(project.rel_path) + csproj_abs_path = self._path_provider.resolveAbsPath(project.rel_path) patcher = csproj.Patcher(csproj_abs_path) patcher.AddOrReplace(project.settings, self._config['sln_config']) diff --git a/scripts/commands/patch_infoplist_command.py b/scripts/commands/patch_infoplist_command.py index 1c0d54e..e08db4e 100644 --- a/scripts/commands/patch_infoplist_command.py +++ b/scripts/commands/patch_infoplist_command.py @@ -45,7 +45,7 @@ class PatchInfoPlist(bcmd.BuildCommand): return config_key[PatchInfoPlist._cmd_prefix_len:] def Execute(self): - info_plist_abs_path = self._path_provider.ResolveAbsPath(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/csproj_sequential_parser.py b/scripts/parser/csproj_sequential_parser.py deleted file mode 100644 index e61347e..0000000 --- a/scripts/parser/csproj_sequential_parser.py +++ /dev/null @@ -1,66 +0,0 @@ -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/run_manual_tests.py b/scripts/run_manual_tests.py new file mode 100644 index 0000000..2fe0325 --- /dev/null +++ b/scripts/run_manual_tests.py @@ -0,0 +1 @@ +import ManualTests.csproj_test diff --git a/scripts/utils/csproj/patcher.py b/scripts/utils/csproj/patcher.py index 66564a2..85c5d2b 100644 --- a/scripts/utils/csproj/patcher.py +++ b/scripts/utils/csproj/patcher.py @@ -8,17 +8,23 @@ class Patcher: def FetchPropertyGroup(self, sln_config_name): tree = eT.parse(self._csproj_abs_path) project_element = tree.getroot() - property_group = self.GetPropertyGroupBy(project_element, sln_config_name) + property_group = self.GetPropertyGroupBy(project_element, sln_config_name) return property_group def GetPropertyGroupBy(self, project_element, config_name): - property_groups = project_element.findall('PropertyGroup') + namespaces = {'xmlns': 'http://schemas.microsoft.com/developer/msbuild/2003'} + property_groups = project_element.findall('xmlns:PropertyGroup', namespaces) + prop_group = None for pg_elem in property_groups: atr_value = pg_elem.get('Condition') + + if atr_value is None: + continue + is_fit = self.IsValueFitFor(config_name, atr_value) if is_fit: