Добавил возможность удаления нескольких проектов из sln файла

This commit is contained in:
rzaitov 2013-11-14 15:46:49 +04:00
parent 018d02fc1f
commit 3d47ebcaad
6 changed files with 62 additions and 13 deletions

View File

@ -20,8 +20,8 @@ class RemoveProjectCommandBuilder:
parser = InsideRemoveParser('sln')
result = parser.parseLine(line)
slnPath = result[0]
projectName = result[1]
slnPath = result['file_path']
projectNames = result['names']
command = RemoveProjectCommand(slnPath, projectName)
command = RemoveProjectCommand(slnPath, projectNames)
return command

View File

@ -0,0 +1,21 @@
import unittest
from parsers.InsideParser.InsideRemoveParser import InsideRemoveParser
class TestInsideRemoveParser(unittest.TestCase):
def setUp(self):
self.parser = InsideRemoveParser('ext')
def test_parse(self):
self.check("inside 'Some/Path/file.ext' remove 'PROGECT' project", 'Some/Path/file.ext', ['PROGECT'])
self.check("inside 'file.ext' remove 'PR' projects", 'file.ext', ['PR'])
self.check("inside 'file.ext' remove 'PR' projects", 'file.ext', ['PR'])
self.check("inside 'file.ext' remove 'pr1:pr2:pr3' projects", 'file.ext', ['pr1', 'pr2', 'pr3'])
def check(self, line, filePath, expectedNames):
result = self.parser.parseLine(line)
self.assertEqual(filePath, result['file_path'])
self.assertListEqual(expectedNames, result['names'])

View File

@ -3,15 +3,15 @@ from utils.SlnPatcher import SlnPatcher
class RemoveProjectCommand(CommandBase):
def __init__(self, slnPath, projectName):
def __init__(self, slnPath, projectNames):
CommandBase.__init__(self)
assert slnPath is not None
assert projectName is not None
assert projectNames is not None
self.__slnPath = slnPath
self.__projectName = projectName
self.projectNames = projectNames
def execute(self):
patcher = SlnPatcher(self.__slnPath)
patcher.removeProjects([self.__projectName])
patcher.removeProjects(self.projectNames)

View File

@ -1,6 +1,7 @@
import re
from parsers.InsideParser.InsideParserBase import InsideParserBase
from parsers.RegexpBuilder import RegexpBuilder
from parsers.ValuesStriper import ValuesStripper
class InsideRemoveParser(InsideParserBase):
@ -11,20 +12,33 @@ class InsideRemoveParser(InsideParserBase):
match = self.fetchMatchFor(line)
filePath = match.group('file')
projectName = match.group('project')
projectNames = match.group('projects')
return filePath, projectName
names = self.parseNames(projectNames)
result = {
'file_path': filePath,
'names': names
}
return result
def getMatchInfo(self, line):
assert line is not None
filePathRegexp = r"'(?P<file>[./ a-zA-Z]+\.{0})'".format(self.fileExt)
projectNameRegexp = r'(?P<project>[.a-zA-Z]+)'
projectNameRegexp = r"'(?P<projects>[^']+)'"
rb = RegexpBuilder()
regexpSource = rb.startsWith('inside') + filePathRegexp + rb.keywordToken('remove') + projectNameRegexp + \
rb.spaceEndsWith('project')
rb.spaceEndsWith('project(s)?')
regexp = re.compile(regexpSource, re.UNICODE)
match = regexp.match(line)
return match, regexpSource
return match, regexpSource
def parseNames(self, namesStr):
vs = ValuesStripper()
names = vs.strip(namesStr)
return names

View File

@ -1,6 +1,7 @@
import re
from parsers.InsideParser.InsideParserBase import InsideParserBase
from parsers.RegexpBuilder import RegexpBuilder
from parsers.ValuesStriper import ValuesStripper
class InsideSetArrayParser(InsideParserBase):
@ -39,5 +40,7 @@ class InsideSetArrayParser(InsideParserBase):
assert valuesStr is not None
assert len(valuesStr) > 0
values = valuesStr.split(':')
vs = ValuesStripper()
values = vs.strip(valuesStr)
return values

View File

@ -0,0 +1,11 @@
class ValuesStripper:
def __init__(self):
pass
def strip(self, valueStr):
assert valueStr is not None
rawValues = valueStr.split(':')
values = [name.strip() for name in rawValues]
return values