Создал комманду для удаления проетка из файла решения
This commit is contained in:
parent
249cf28917
commit
4318a70207
|
|
@ -1,5 +1,5 @@
|
|||
from commands.PatchCsprojCommand import PatchCsprojCommand
|
||||
from parser.InsideParser.InsideParser import InsideParser
|
||||
from parser.InsideParser.InsideSetParser import InsideSetParser
|
||||
|
||||
|
||||
class PatchCsprojCommandBuilder:
|
||||
|
|
@ -15,7 +15,7 @@ class PatchCsprojCommandBuilder:
|
|||
def getCommandFor(self, line):
|
||||
assert line is not None
|
||||
|
||||
parser = InsideParser(self.__valueProvider, 'csproj')
|
||||
parser = InsideSetParser(self.__valueProvider, 'csproj')
|
||||
result = parser.parseLine(line)
|
||||
|
||||
relPath = result[0]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
from commands.RemoveProjectCommand import RemoveProjectCommand
|
||||
from parser.InsideParser.InsideRemoveParser import InsideRemoveParser
|
||||
|
||||
|
||||
class RemoveProjectCommandBuilder:
|
||||
def isRemoveProject(self, line):
|
||||
assert line is not None
|
||||
|
||||
parser = InsideRemoveParser('sln')
|
||||
isValid = parser.isValidLine(line)
|
||||
|
||||
return isValid
|
||||
|
||||
def getCommandFor(self, line):
|
||||
assert line is not None
|
||||
|
||||
parser = InsideRemoveParser('sln')
|
||||
result = parser.parseLine(line)
|
||||
|
||||
slnPath = result[0]
|
||||
projectName = result[1]
|
||||
|
||||
command = RemoveProjectCommand(slnPath, projectName)
|
||||
return command
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
from CommandBuilders.RemoveProjectCommandBuilder import RemoveProjectCommandBuilder
|
||||
|
||||
line = "inside 'BuildSample/BuildSample.sln' remove NotCompile project"
|
||||
|
||||
builder = RemoveProjectCommandBuilder()
|
||||
command = builder.getCommandFor(line)
|
||||
|
||||
command.execute()
|
||||
|
|
@ -1,14 +1,14 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import unittest
|
||||
from UnitTests.ProjectParser.ValueProvider import ValueProvider
|
||||
from parser.InsideParser.InsideParser import InsideParser
|
||||
from parser.InsideParser.InsideSetParser import InsideSetParser
|
||||
|
||||
|
||||
class TestCsprojParser(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
value_provider = ValueProvider()
|
||||
self.parser = InsideParser(value_provider, 'csproj')
|
||||
self.parser = InsideSetParser(value_provider, 'csproj')
|
||||
|
||||
|
||||
def test_isValid(self):
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
from utils.sln.patcher import Patcher
|
||||
|
||||
|
||||
class RemoveProjectCommand:
|
||||
def __init__(self, slnPath, projectName):
|
||||
assert slnPath is not None
|
||||
assert projectName is not None
|
||||
|
||||
self.__slnPath = slnPath
|
||||
self.__projectName = projectName
|
||||
|
||||
def execute(self):
|
||||
patcher = Patcher(self.__slnPath)
|
||||
patcher.removeProjects([self.__projectName])
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
from subprocess import call
|
||||
import shutil
|
||||
import os
|
||||
from utils.sln import sln_toolkit as sln
|
||||
from utils.sln import patcher as sln
|
||||
|
||||
|
||||
def MapToBackupName(origin_path):
|
||||
|
|
@ -55,8 +55,8 @@ def ResetDirectory(base_dir, relative_path_to_files):
|
|||
return None
|
||||
|
||||
def RemoveProjectFromSolution(abs_path_to_sln, project_names):
|
||||
toolkit = sln.SolutionToolkit(abs_path_to_sln)
|
||||
toolkit.RemoveProjects(project_names)
|
||||
toolkit = sln.Patcher(abs_path_to_sln)
|
||||
toolkit.removeProjects(project_names)
|
||||
|
||||
def CleanSolution(mdtool, abs_path_to_sln, config):
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
from parser.LineParser import LineParser
|
||||
import re
|
||||
|
||||
|
||||
class InsideRemoveParser(LineParser):
|
||||
def __init__(self, fileExt):
|
||||
assert fileExt is not None
|
||||
|
||||
self.__extension = fileExt
|
||||
|
||||
def parseLine(self, line):
|
||||
assert line is not None
|
||||
|
||||
filePathRegexp = r"'(?P<file>[./ a-zA-Z]+\.{0})'".format(self.__extension)
|
||||
projectNameRegexp = r'(?P<project>[.a-zA-Z]+)'
|
||||
|
||||
regexpSource = self.startsWithKeywordToken('inside') + filePathRegexp + self.keywordToken('remove') + projectNameRegexp + self.keywordToken('project')
|
||||
regexp = re.compile(regexpSource, re.UNICODE)
|
||||
|
||||
match = regexp.match(line)
|
||||
self._guardMatch(match, line, regexpSource)
|
||||
|
||||
filePath = match.group('file')
|
||||
projectName = match.group('project')
|
||||
|
||||
return (filePath, projectName)
|
||||
|
||||
def isValidLine(self, line):
|
||||
regexpSrc = r"inside\s+'[./ a-zA-Z]+\.{0}'\s+remove".format(self.__extension)
|
||||
print regexpSrc
|
||||
regexp = re.compile(regexpSrc, re.UNICODE)
|
||||
|
||||
match = regexp.match(line)
|
||||
return match is not None
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
from parser.LineParser import LineParser
|
||||
import re
|
||||
|
||||
class InsideSetParser(LineParser):
|
||||
def __init__(self, value_provider, fileExt):
|
||||
assert value_provider is not None
|
||||
|
||||
self.__value_provider = value_provider
|
||||
self.__extension = fileExt
|
||||
|
||||
def parseLine(self, line):
|
||||
assert line is not None
|
||||
|
||||
filePathRegexp = r"'(?P<file>[./ a-zA-Z]+\.{0})'".format(self.__extension)
|
||||
keyRegexp = r'(?P<key>[a-zA-Z]+)'
|
||||
valueRegexp = r"'(?P<value>[^']+)'"
|
||||
|
||||
regexpSource = self.startsWithKeywordToken('inside') + filePathRegexp + self.keywordToken('set') + keyRegexp + self.keywordToken('to') + valueRegexp
|
||||
regexp = re.compile(regexpSource, re.UNICODE)
|
||||
|
||||
match = regexp.match(line)
|
||||
self._guardMatch(match, line, regexpSource)
|
||||
|
||||
filePath = match.group('file')
|
||||
key = match.group('key')
|
||||
value = match.group('value')
|
||||
|
||||
return (filePath, key, value)
|
||||
|
||||
def isValidLine(self, line):
|
||||
regexpSrc = r"inside\s+'[./ a-zA-Z]+\.{0}'\s+set".format(self.__extension)
|
||||
print regexpSrc
|
||||
regexp = re.compile(regexpSrc, re.UNICODE)
|
||||
|
||||
match = regexp.match(line)
|
||||
return match is not None
|
||||
|
|
@ -1,7 +1,10 @@
|
|||
import os
|
||||
scriptFilePath = os.path.abspath(__file__)
|
||||
|
||||
scriptDir = os.path.dirname(scriptFilePath)
|
||||
os.chdir(scriptDir)
|
||||
baseDir = os.path.join(scriptDir, os.pardir)
|
||||
|
||||
os.chdir(baseDir)
|
||||
|
||||
#import ManualTests.csproj_test
|
||||
#import ManualTests.info_plist_test
|
||||
|
|
@ -11,5 +14,6 @@ os.chdir(scriptDir)
|
|||
#import ManualTests.restore_backup_test
|
||||
#import ManualTests.csproj_test
|
||||
#import ManualTests.run_sh_command
|
||||
#import ManualTests.make_dirs
|
||||
|
||||
import ManualTests.make_dirs
|
||||
import ManualTests.remove_project
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
import re
|
||||
|
||||
|
||||
class Patcher:
|
||||
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()
|
||||
|
||||
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
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
import utils.sln.sln_toolkit_base as sln
|
||||
|
||||
|
||||
class SolutionToolkit(sln.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()
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
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
|
||||
|
||||
Loading…
Reference in New Issue