From 3d47ebcaad3c12405de1c4a310626fab0bf0f6b0 Mon Sep 17 00:00:00 2001 From: rzaitov Date: Thu, 14 Nov 2013 15:46:49 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BD=D0=B5=D1=81=D0=BA=D0=BE=D0=BB=D1=8C=D0=BA=D0=B8=D1=85=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=BE=D0=B2=20=D0=B8=D0=B7?= =?UTF-8?q?=20sln=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RemoveProjectCommandBuilder.py | 6 ++--- .../InsideParsers/test_insideRemoveParser.py | 21 ++++++++++++++++ .../commands/RemoveProjectCommand.py | 8 +++---- .../InsideParser/InsideRemoveParser.py | 24 +++++++++++++++---- .../InsideParser/InsideSetArrayParser.py | 5 +++- scripts/TouchinBuild/parsers/ValuesStriper.py | 11 +++++++++ 6 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 scripts/TouchinBuild/Tests/UnitTests/InsideParsers/test_insideRemoveParser.py create mode 100644 scripts/TouchinBuild/parsers/ValuesStriper.py diff --git a/scripts/TouchinBuild/CommandBuilders/RemoveProjectCommandBuilder.py b/scripts/TouchinBuild/CommandBuilders/RemoveProjectCommandBuilder.py index b81482f..b8dc34f 100644 --- a/scripts/TouchinBuild/CommandBuilders/RemoveProjectCommandBuilder.py +++ b/scripts/TouchinBuild/CommandBuilders/RemoveProjectCommandBuilder.py @@ -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 \ No newline at end of file diff --git a/scripts/TouchinBuild/Tests/UnitTests/InsideParsers/test_insideRemoveParser.py b/scripts/TouchinBuild/Tests/UnitTests/InsideParsers/test_insideRemoveParser.py new file mode 100644 index 0000000..a397091 --- /dev/null +++ b/scripts/TouchinBuild/Tests/UnitTests/InsideParsers/test_insideRemoveParser.py @@ -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']) diff --git a/scripts/TouchinBuild/commands/RemoveProjectCommand.py b/scripts/TouchinBuild/commands/RemoveProjectCommand.py index 61ae1df..b09985d 100644 --- a/scripts/TouchinBuild/commands/RemoveProjectCommand.py +++ b/scripts/TouchinBuild/commands/RemoveProjectCommand.py @@ -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) diff --git a/scripts/TouchinBuild/parsers/InsideParser/InsideRemoveParser.py b/scripts/TouchinBuild/parsers/InsideParser/InsideRemoveParser.py index 3ec570e..a3fce6e 100644 --- a/scripts/TouchinBuild/parsers/InsideParser/InsideRemoveParser.py +++ b/scripts/TouchinBuild/parsers/InsideParser/InsideRemoveParser.py @@ -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[./ a-zA-Z]+\.{0})'".format(self.fileExt) - projectNameRegexp = r'(?P[.a-zA-Z]+)' + projectNameRegexp = r"'(?P[^']+)'" 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 \ No newline at end of file + return match, regexpSource + + def parseNames(self, namesStr): + + vs = ValuesStripper() + names = vs.strip(namesStr) + + return names \ No newline at end of file diff --git a/scripts/TouchinBuild/parsers/InsideParser/InsideSetArrayParser.py b/scripts/TouchinBuild/parsers/InsideParser/InsideSetArrayParser.py index e133719..60ee509 100644 --- a/scripts/TouchinBuild/parsers/InsideParser/InsideSetArrayParser.py +++ b/scripts/TouchinBuild/parsers/InsideParser/InsideSetArrayParser.py @@ -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 \ No newline at end of file diff --git a/scripts/TouchinBuild/parsers/ValuesStriper.py b/scripts/TouchinBuild/parsers/ValuesStriper.py new file mode 100644 index 0000000..934cc84 --- /dev/null +++ b/scripts/TouchinBuild/parsers/ValuesStriper.py @@ -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 \ No newline at end of file