From 31e938809d671cf5501d3b50d2824c7e4df39afc Mon Sep 17 00:00:00 2001 From: rzaitov Date: Tue, 12 Nov 2013 19:36:13 +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=B1=D0=B0=D0=B7=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0?= =?UTF-8?q?=D1=81=D1=81=20=D0=B4=D0=BB=D1=8F=20Inside=20=D0=BF=D0=B0=D1=80?= =?UTF-8?q?=D1=81=D0=B5=D1=80=D0=BE=D0=B2=20=D0=B8=20=D0=B2=D1=8B=D0=BD?= =?UTF-8?q?=D0=B5=D1=81=20=D1=82=D1=83=D0=B4=D0=B0=20=D0=B7=D0=BD=D0=B0?= =?UTF-8?q?=D1=87=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=83=D1=8E=20=D1=87?= =?UTF-8?q?=D0=B0=D1=81=D1=82=D1=8C=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D0=BE=D0=BD=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InsideParser/InsideCsprojSetParser.py | 29 +++----------- .../parsers/InsideParser/InsideParserBase.py | 38 +++++++++++++++++++ .../InsideParser/InsideRemoveParser.py | 34 +++++++---------- .../InsideParser/InsideSetArrayParser.py | 30 +++++++++++++++ .../parsers/InsideParser/InsideSetParser.py | 27 +++---------- 5 files changed, 93 insertions(+), 65 deletions(-) create mode 100644 scripts/TouchinBuild/parsers/InsideParser/InsideParserBase.py create mode 100644 scripts/TouchinBuild/parsers/InsideParser/InsideSetArrayParser.py diff --git a/scripts/TouchinBuild/parsers/InsideParser/InsideCsprojSetParser.py b/scripts/TouchinBuild/parsers/InsideParser/InsideCsprojSetParser.py index 2dcf2e9..d7f62bc 100644 --- a/scripts/TouchinBuild/parsers/InsideParser/InsideCsprojSetParser.py +++ b/scripts/TouchinBuild/parsers/InsideParser/InsideCsprojSetParser.py @@ -1,21 +1,13 @@ import re - -from parsers.LineParser import LineParser +from parsers.InsideParser.InsideParserBase import InsideParserBase -class InsideCsprojSetParser(LineParser): +class InsideCsprojSetParser(InsideParserBase): def __init__(self, fileExt): - LineParser.__init__(self) - - self.__extension = fileExt + InsideParserBase.__init__(self, fileExt) def parseLine(self, line): - assert line is not None - - matchInfo = self.getMatchInfo(line) - match = matchInfo[0] - regexpSource = matchInfo[1] - self._guardMatch(match, line, regexpSource) + match = self.fetchMatchFor(line) filePath = match.group('file') key = match.group('key') @@ -27,22 +19,13 @@ class InsideCsprojSetParser(LineParser): def getMatchInfo(self, line): assert line is not None - filePathRegexp = r"'(?P[./ a-zA-Z]+\.{0})'".format(self.__extension) keyRegexp = r'(?P[a-zA-Z]+)' valueRegexp = r"'(?P[^']+)'" slnConfigRegexp = r"'(?P[a-zA-Z|]+)'$" - regexpSource = self.startsWith('inside') + filePathRegexp + self.keywordToken('set') + keyRegexp + \ + regexpSource = self.startsWith('inside') + self.filePathRegexp + self.keywordToken('set') + keyRegexp + \ self.keywordToken('to') + valueRegexp + self.keywordToken('for') + slnConfigRegexp regexp = re.compile(regexpSource, re.UNICODE) match = regexp.match(line) - return match, regexpSource - - def isValidLine(self, line): - assert line is not None - - matchInfo = self.getMatchInfo(line) - match = matchInfo[0] - - return match is not None \ No newline at end of file + return match, regexpSource \ No newline at end of file diff --git a/scripts/TouchinBuild/parsers/InsideParser/InsideParserBase.py b/scripts/TouchinBuild/parsers/InsideParser/InsideParserBase.py new file mode 100644 index 0000000..c824749 --- /dev/null +++ b/scripts/TouchinBuild/parsers/InsideParser/InsideParserBase.py @@ -0,0 +1,38 @@ +import abc +from parsers.LineParser import LineParser + + +class InsideParserBase(object, LineParser): + __metaclass__ = abc.ABCMeta + + def __init__(self, fileExt): + LineParser.__init__(self) + + assert fileExt is not None + self.fileExt = fileExt + self.filePathRegexp = r"'(?P[./ a-zA-Z]+\.{0})'".format(self.fileExt) + + @abc.abstractmethod + def getMatchInfo(self, line): + "Not implemented" + return None, None + + def fetchMatchFor(self, text): + assert text is not None + + matchInfo = self.getMatchInfo(text) + match = matchInfo[0] + regexpSource = matchInfo[1] + + self._guardMatch(match, text, regexpSource) + + return match + + + def isValidLine(self, line): + assert line is not None + + matchInfo = self.getMatchInfo(line) + match = matchInfo[0] + + return match is not None diff --git a/scripts/TouchinBuild/parsers/InsideParser/InsideRemoveParser.py b/scripts/TouchinBuild/parsers/InsideParser/InsideRemoveParser.py index 4c72539..435acd2 100644 --- a/scripts/TouchinBuild/parsers/InsideParser/InsideRemoveParser.py +++ b/scripts/TouchinBuild/parsers/InsideParser/InsideRemoveParser.py @@ -1,35 +1,27 @@ import re - -from parsers.LineParser import LineParser +from parsers.InsideParser.InsideParserBase import InsideParserBase -class InsideRemoveParser(LineParser): +class InsideRemoveParser(InsideParserBase): def __init__(self, fileExt): - LineParser.__init__(self) - assert fileExt is not None - - self.__extension = fileExt + InsideParserBase.__init__(self, fileExt) def parseLine(self, line): - assert line is not None - - filePathRegexp = r"'(?P[./ a-zA-Z]+\.{0})'".format(self.__extension) - projectNameRegexp = r'(?P[.a-zA-Z]+)' - - regexpSource = self.startsWith('inside') + filePathRegexp + self.keywordToken('remove') + projectNameRegexp + self.spaceEndsWith('project') - regexp = re.compile(regexpSource, re.UNICODE) - - match = regexp.match(line) - self._guardMatch(match, line, regexpSource) + match = self.fetchMatchFor(line) 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) - regexp = re.compile(regexpSrc, re.UNICODE) + 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]+)' + + regexpSource = self.startsWith('inside') + filePathRegexp + self.keywordToken('remove') + projectNameRegexp + self.spaceEndsWith('project') + regexp = re.compile(regexpSource, re.UNICODE) match = regexp.match(line) - return match is not None \ No newline at end of file + return match, regexpSource \ No newline at end of file diff --git a/scripts/TouchinBuild/parsers/InsideParser/InsideSetArrayParser.py b/scripts/TouchinBuild/parsers/InsideParser/InsideSetArrayParser.py new file mode 100644 index 0000000..44cf234 --- /dev/null +++ b/scripts/TouchinBuild/parsers/InsideParser/InsideSetArrayParser.py @@ -0,0 +1,30 @@ +import re +from parsers.InsideParser.InsideParserBase import InsideParserBase + + +class InsideSetArrayParser(InsideParserBase): + def __init__(self, fileExt): + InsideParserBase.__init__(self, fileExt) + + def parseLine(self, line): + match = self.fetchMatchFor(line) + + filePath = match.group('file') + key = match.group('key') + value = match.group('value') + + return filePath, key, value + + def getMatchInfo(self, line): + assert line is not None + + keyRegexp = r'(?P[a-zA-Z]+)' + valueRegexp = r"'(?P[^']+)'$" + + regexpSource = self.startsWith('inside') + self.filePathRegexp + self.keywordToken('set') + keyRegexp + \ + self.keywordToken('to') + valueRegexp + regexp = re.compile(regexpSource, re.UNICODE) + + match = regexp.match(line) + + return match, regexpSource \ No newline at end of file diff --git a/scripts/TouchinBuild/parsers/InsideParser/InsideSetParser.py b/scripts/TouchinBuild/parsers/InsideParser/InsideSetParser.py index 7269940..2c9f883 100644 --- a/scripts/TouchinBuild/parsers/InsideParser/InsideSetParser.py +++ b/scripts/TouchinBuild/parsers/InsideParser/InsideSetParser.py @@ -1,20 +1,13 @@ import re - -from parsers.LineParser import LineParser +from parsers.InsideParser.InsideParserBase import InsideParserBase -class InsideSetParser(LineParser): +class InsideSetParser(InsideParserBase): def __init__(self, fileExt): - LineParser.__init__(self) - self.__extension = fileExt + InsideParserBase.__init__(self, fileExt) def parseLine(self, line): - assert line is not None - - matchInfo = self.getMatchInfo(line) - match = matchInfo[0] - regexpSource = matchInfo[1] - self._guardMatch(match, line, regexpSource) + match = self.fetchMatchFor(line) filePath = match.group('file') key = match.group('key') @@ -25,21 +18,13 @@ class InsideSetParser(LineParser): def getMatchInfo(self, line): assert line is not None - filePathRegexp = r"'(?P[./ a-zA-Z]+\.{0})'".format(self.__extension) keyRegexp = r'(?P[a-zA-Z]+)' valueRegexp = r"'(?P[^']+)'$" - regexpSource = self.startsWith('inside') + filePathRegexp + self.keywordToken('set') + keyRegexp + \ + regexpSource = self.startsWith('inside') + self.filePathRegexp + self.keywordToken('set') + keyRegexp + \ self.keywordToken('to') + valueRegexp regexp = re.compile(regexpSource, re.UNICODE) match = regexp.match(line) - return match, regexpSource - - def isValidLine(self, line): - assert line is not None - - matchInfo = self.getMatchInfo(line) - match = matchInfo[0] - return match is not None \ No newline at end of file + return match, regexpSource \ No newline at end of file