вынес возможность удаления проектов из файла решения в api

This commit is contained in:
Rustam Zaitov 2013-10-01 15:17:57 +04:00
parent be698c09cf
commit 977b478a40
2 changed files with 41 additions and 13 deletions

View File

@ -2,6 +2,7 @@ from subprocess import call
import shutil
import os
import re
import sln_toolkit as sln
def MapToBackupName(origin_path):
@ -54,19 +55,8 @@ def ResetDirectory(base_dir, relative_path_to_files):
return None
def RemoveProjectFromSolution(abs_path_to_sln, project_names):
sln_file = open(abs_path_to_sln, 'r+')
content = sln_file.read()
for pn in project_names:
reg_pattern = r'\n*Project.*?"{0}".*?\n*EndProject'.format(pn)
content = re.sub(reg_pattern, "", content)
# override file
sln_file.seek(0)
sln_file.write(content)
sln_file.truncate()
sln_file.close()
toolkit = sln.SolutionToolkit(abs_path_to_sln)
toolkit.RemoveProjects(project_names)
def CleanSolution(mdtool, abs_path_to_sln, config):

38
scripts/sln_toolkit.py Normal file
View File

@ -0,0 +1,38 @@
import re
class SolutionToolkitBase:
def RemoveProjectSectionsFrom(self, sln_file_content, project_names):
for pn in project_names:
reg_pattern = r'\n*Project.*?"{0}".*?\n*EndProject'.format(pn)
sln_file_content = re.sub(reg_pattern, "", sln_file_content)
return sln_file_content
class SolutionToolkit(SolutionToolkitBase):
def __init__(self, pathToSlnFile):
self._sln_path = pathToSlnFile
self._sln_file = None
def RemoveProjects(self, project_names):
self.OpenSlnFile()
content = self.ReadSlnFileContent()
new_content = self.RemoveProjectSectionsFrom(content, project_names)
self.RewriteSlnFile(new_content)
self.CloseSlnFile()
def OpenSlnFile(self):
self._sln_file = open(self._sln_path, 'r+')
def CloseSlnFile(self):
self._sln_file.close()
def ReadSlnFileContent(self):
content = self._sln_file.read()
return content
def RewriteSlnFile(self, content):
self._sln_file.seek(0)
self._sln_file.write(content)
self._sln_file.truncate()