Отладил модификацию csproj Файла
This commit is contained in:
parent
9dea142c7a
commit
e2571714a5
|
|
@ -1,15 +1,17 @@
|
|||
import path_provider
|
||||
import commands.patch_csproj_command as csproj
|
||||
|
||||
config = {
|
||||
'csproj group:CoolApp key:rel_path': 'BuildSample/CoolApp.csproj',
|
||||
'csproj group:CoolApp key:CodesignProvision': '@codesign_provision',
|
||||
'csproj group:CoolApp key:CodesignKey': '@codesign_key',
|
||||
'csproj app:CoolApp rel_path': 'BuildSample/BuildSample/CoolApp.csproj',
|
||||
'csproj app:CoolApp key:CodesignProvision': '@codesign_provision',
|
||||
'csproj app:CoolApp key:CodesignKey': '@codesign_key',
|
||||
|
||||
'codesign_provision': 'MyProvisioningValue',
|
||||
'codesign_key': 'MyCodesignValue'
|
||||
'codesign_key': 'MyCodesignValue',
|
||||
'sln_config': 'Release|iPhone'
|
||||
}
|
||||
|
||||
base_dir = '/Users/rzaitov/Documents/Apps/BuildScript',
|
||||
base_dir = '/Users/rzaitov/Documents/Apps/BuildScript'
|
||||
provider = path_provider.PathProvider(base_dir)
|
||||
|
||||
patcher = csproj.PatchCsproj(config, provider)
|
||||
|
|
|
|||
|
|
@ -3,8 +3,12 @@ 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
|
||||
|
||||
def ResolveAbsPath(self, rel_path):
|
||||
abs_path = os.path.join(self._base_dir, rel_path)
|
||||
return abs_path
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,10 @@ class CsprojParser:
|
|||
self._token_buffer = None
|
||||
self._token_index = 0
|
||||
self._current_project = None
|
||||
self.projects = {}
|
||||
self._projects = {}
|
||||
|
||||
def getProjects(self):
|
||||
return self._projects.values()
|
||||
|
||||
def initTokenBuffer(self, string_to_parse, value_token):
|
||||
self._token_buffer = string_to_parse.split(' ')
|
||||
|
|
@ -24,6 +27,7 @@ class CsprojParser:
|
|||
|
||||
def ProcessToken(self):
|
||||
token = self.getCurrentToken()
|
||||
print token
|
||||
|
||||
if self.isCsprojStatement(token):
|
||||
self._token_index += 1
|
||||
|
|
@ -34,7 +38,7 @@ class CsprojParser:
|
|||
key_name = self.processKeyToken(token)
|
||||
self._token_index += 1
|
||||
token = self.getCurrentToken()
|
||||
value = self.processValueToken()
|
||||
value = self.processValueToken(token)
|
||||
self._token_index += 1
|
||||
self._current_project.settings[key_name] = value
|
||||
elif self.isAttributeToken(token):
|
||||
|
|
@ -43,7 +47,9 @@ class CsprojParser:
|
|||
token = self.getCurrentToken()
|
||||
attribute_value = self.processValueToken(token)
|
||||
self._token_index += 1
|
||||
setattr(self.project, attribute_name, attribute_value)
|
||||
setattr(self._current_project, attribute_name, attribute_value)
|
||||
else:
|
||||
raise Exception('unrecognized token', token)
|
||||
|
||||
def isCsprojStatement(self, token):
|
||||
return token == 'csproj'
|
||||
|
|
@ -58,17 +64,19 @@ class CsprojParser:
|
|||
return ':' not in token
|
||||
|
||||
def processAppToken(self, appToken):
|
||||
appName = appToken[len('app:')]
|
||||
appName = appToken[len('app:'):]
|
||||
print appName
|
||||
self.setCurrentProject(appName)
|
||||
|
||||
def setCurrentProject(self, appName):
|
||||
exists = appName in self.projects
|
||||
exists = appName in self._projects
|
||||
|
||||
self._current_project = self.projects[appName] if exists else Csproj(appName)
|
||||
self.projects[appName] = self._current_project
|
||||
self._current_project = self._projects[appName] if exists else Csproj(appName)
|
||||
self._projects[appName] = self._current_project
|
||||
|
||||
def processKeyToken(self, token):
|
||||
key_name = token[len('key:')]
|
||||
key_name = token[len('key:'):]
|
||||
print key_name
|
||||
return key_name
|
||||
|
||||
def processAttributeNameToken(self, token):
|
||||
|
|
@ -92,4 +100,7 @@ class CsprojParser:
|
|||
class Csproj:
|
||||
def __init__(self, appName):
|
||||
self.appName = appName
|
||||
self.settings = {}
|
||||
self.settings = {}
|
||||
|
||||
def __str__(self):
|
||||
return 'app Name: {0} settings: {1}'.format(self.appName, self.settings)
|
||||
|
|
@ -1,21 +1,26 @@
|
|||
import xml.etree.ElementTree as eT
|
||||
|
||||
eT.register_namespace('', "http://schemas.microsoft.com/developer/msbuild/2003")
|
||||
|
||||
class Patcher:
|
||||
def __init__(self, csproj_abs_path):
|
||||
self._csproj_abs_path = csproj_abs_path
|
||||
self._tree = None
|
||||
self._namespaces = {'ns': 'http://schemas.microsoft.com/developer/msbuild/2003'}
|
||||
|
||||
|
||||
def FetchPropertyGroup(self, sln_config_name):
|
||||
tree = eT.parse(self._csproj_abs_path)
|
||||
project_element = tree.getroot()
|
||||
self._tree = eT.parse(self._csproj_abs_path)
|
||||
project_element = self._tree.getroot()
|
||||
|
||||
property_group = self.GetPropertyGroupBy(project_element, sln_config_name)
|
||||
return property_group
|
||||
|
||||
def WriteTree(self):
|
||||
self._tree.write(self._csproj_abs_path, xml_declaration=True, encoding='utf-8', method="xml")
|
||||
|
||||
|
||||
def GetPropertyGroupBy(self, project_element, config_name):
|
||||
namespaces = {'xmlns': 'http://schemas.microsoft.com/developer/msbuild/2003'}
|
||||
property_groups = project_element.findall('xmlns:PropertyGroup', namespaces)
|
||||
property_groups = project_element.findall('ns:PropertyGroup', self._namespaces)
|
||||
|
||||
prop_group = None
|
||||
|
||||
|
|
@ -37,11 +42,13 @@ class Patcher:
|
|||
def Remove(self, tag_names, sln_config_name):
|
||||
property_group = self.FetchPropertyGroup(sln_config_name)
|
||||
self.RemoveTagsFor(property_group, tag_names)
|
||||
self.WriteTree()
|
||||
|
||||
|
||||
def AddOrReplace(self, key_value_dict, sln_config_name):
|
||||
property_group = self.FetchPropertyGroup(sln_config_name)
|
||||
self.AddOrReplaceTagsFor(property_group, key_value_dict)
|
||||
self.WriteTree()
|
||||
|
||||
|
||||
def IsValueFitFor(self, config_name, condition_attr_value):
|
||||
|
|
@ -64,7 +71,7 @@ class Patcher:
|
|||
|
||||
|
||||
def AppendOrReplaceValueByKey(self, tag_name, value, property_group_element):
|
||||
tag = property_group_element.find(tag_name)
|
||||
tag = property_group_element.find('ns:{0}'.format(tag_name), self._namespaces)
|
||||
|
||||
if tag is None:
|
||||
tag = eT.Element(tag_name)
|
||||
|
|
|
|||
Loading…
Reference in New Issue