From 977b478a40da3fafd70fe4afc28240ba6c11d4d0 Mon Sep 17 00:00:00 2001 From: Rustam Zaitov Date: Tue, 1 Oct 2013 15:17:57 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=8B=D0=BD=D0=B5=D1=81=20=D0=B2=D0=BE?= =?UTF-8?q?=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D1=83?= =?UTF-8?q?=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=BE=D0=B2=20=D0=B8=D0=B7=20=D1=84=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB=D0=B0=20=D1=80=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B2=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/instruments.py | 16 +++------------- scripts/sln_toolkit.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 scripts/sln_toolkit.py diff --git a/scripts/instruments.py b/scripts/instruments.py index 1fe2247..632de4c 100644 --- a/scripts/instruments.py +++ b/scripts/instruments.py @@ -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): diff --git a/scripts/sln_toolkit.py b/scripts/sln_toolkit.py new file mode 100644 index 0000000..9aa121f --- /dev/null +++ b/scripts/sln_toolkit.py @@ -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() \ No newline at end of file