From e0e6ed61eb4281031e39f4b1f84678e080052089 Mon Sep 17 00:00:00 2001 From: rzaitov Date: Thu, 14 Nov 2013 14:33:05 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=B5=D1=81=20?= =?UTF-8?q?=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=BE=D0=BD=D0=B0=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D1=81=D0=B2=D1=8F=D0=B7?= =?UTF-8?q?=D0=B0=D0=BD=D0=BD=D1=83=D1=8E=20=D1=81=20=D0=BF=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B3=D1=83=D0=BB=D1=8F=D1=80=D0=BD=D1=8B=D1=85=20=D0=B2=D1=8B?= =?UTF-8?q?=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=B8=D0=B7=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20LineParser=20=D0=B2=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20RegexpBuilder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InstallProfileCommandBuilder.py | 24 ++++++++++++--- .../InstallProfile/test_installProfile.py | 5 ++-- .../TouchinBuild/parsers/CleanBuildParser.py | 8 +++-- .../parsers/CopyParser/CopyLineParser.py | 4 ++- .../parsers/InstallProfileParser.py | 15 +--------- scripts/TouchinBuild/parsers/LineParser.py | 29 +++++-------------- .../TouchinBuild/parsers/MakeDirsParser.py | 4 ++- .../ParserBackup/CreateBackupParser.py | 4 ++- .../ParserBackup/DeleteBackupParser.py | 4 ++- .../ParserBackup/RestoreBackupParser.py | 4 ++- scripts/TouchinBuild/parsers/RegexpBuilder.py | 20 +++++++++++++ .../SettingsParser/SettingsLineParser.py | 5 ++++ scripts/TouchinBuild/parsers/ShParser.py | 4 ++- .../TouchinBuild/parsers/TestflightParser.py | 12 +++++--- .../TouchinBuild/utils/IncludeProcessor.py | 4 ++- 15 files changed, 89 insertions(+), 57 deletions(-) create mode 100644 scripts/TouchinBuild/parsers/RegexpBuilder.py diff --git a/scripts/TouchinBuild/CommandBuilders/InstallProfileCommandBuilder.py b/scripts/TouchinBuild/CommandBuilders/InstallProfileCommandBuilder.py index 1e9668b..4b31f80 100644 --- a/scripts/TouchinBuild/CommandBuilders/InstallProfileCommandBuilder.py +++ b/scripts/TouchinBuild/CommandBuilders/InstallProfileCommandBuilder.py @@ -1,21 +1,37 @@ +import os from commands.CopyCommand import CopyCommand +from parsers.CopyParser.CopyArguments import CopyArguments from parsers.InstallProfileParser import InstallProfileParser class InstallProfileCommandBuilder: def __init__(self): - pass + self.profileStorageDir = '~/Library/MobileDevice/Provisioning Profiles/' def isInstallProfile(self, line): assert line is not None - return line.startswith('install profile') + parser = InstallProfileParser() + isValid = parser.isValidLine(line) + + return isValid def getCommandFor(self, line): assert line is not None - + parser = InstallProfileParser() - cpArgs = parser.parseLine(line) + + srcPath = parser.parseLine(line) + dstPath = self.getDestinationPath(srcPath) + + cpArgs = CopyArguments() + cpArgs.setArguments(srcPath, dstPath) command = CopyCommand(cpArgs) return command + + def getDestinationPath(self, sourcePath): + profileFileName = os.path.basename(sourcePath) + destination = os.path.join(self.profileStorageDir, profileFileName) + + return destination diff --git a/scripts/TouchinBuild/Tests/UnitTests/InstallProfile/test_installProfile.py b/scripts/TouchinBuild/Tests/UnitTests/InstallProfile/test_installProfile.py index ba9313f..a6e9d82 100644 --- a/scripts/TouchinBuild/Tests/UnitTests/InstallProfile/test_installProfile.py +++ b/scripts/TouchinBuild/Tests/UnitTests/InstallProfile/test_installProfile.py @@ -8,7 +8,6 @@ class TestInstallProfile(unittest.TestCase): def test_parse(self): line = "install profile 'Path/To/Profile.mobileprovision'" - copyArgs = self.parser.parseLine(line) + src = self.parser.parseLine(line) - self.assertEqual('Path/To/Profile.mobileprovision', copyArgs.source) - self.assertEqual('~/Library/MobileDevice/Provisioning Profiles/Profile.mobileprovision', copyArgs.target) \ No newline at end of file + self.assertEqual('Path/To/Profile.mobileprovision', src) diff --git a/scripts/TouchinBuild/parsers/CleanBuildParser.py b/scripts/TouchinBuild/parsers/CleanBuildParser.py index 2f7ed14..f65cf93 100644 --- a/scripts/TouchinBuild/parsers/CleanBuildParser.py +++ b/scripts/TouchinBuild/parsers/CleanBuildParser.py @@ -1,6 +1,7 @@ import re from parsers.LineParser import LineParser +from parsers.RegexpBuilder import RegexpBuilder class CleanBuildParser(LineParser): @@ -8,7 +9,7 @@ class CleanBuildParser(LineParser): LineParser.__init__(self) assert commandToken is not None - self.__commandToken = commandToken + self.commandToken = commandToken def parseLine(self, line): assert line is not None @@ -16,7 +17,8 @@ class CleanBuildParser(LineParser): filePathRegexp = r"'(?P[./ a-zA-Z]+\.sln)'" slnConfigRegexp = r"'(?P[a-zA-Z|]+)'$" - regexpSource = self.startsWith(self.__commandToken) + filePathRegexp + self.keywordToken('for') + slnConfigRegexp + rb = RegexpBuilder() + regexpSource = rb.startsWith(self.commandToken) + filePathRegexp + rb.keywordToken('for') + slnConfigRegexp regexp = re.compile(regexpSource, re.UNICODE) match = regexp.match(line) @@ -30,5 +32,5 @@ class CleanBuildParser(LineParser): def isValidLine(self, line): assert line is not None - isValid = line.startswith(self.__commandToken) + isValid = line.startswith(self.commandToken) return isValid diff --git a/scripts/TouchinBuild/parsers/CopyParser/CopyLineParser.py b/scripts/TouchinBuild/parsers/CopyParser/CopyLineParser.py index 9a99db9..8b865f5 100644 --- a/scripts/TouchinBuild/parsers/CopyParser/CopyLineParser.py +++ b/scripts/TouchinBuild/parsers/CopyParser/CopyLineParser.py @@ -2,6 +2,7 @@ import re from parsers.CopyParser.CopyArguments import CopyArguments from parsers.LineParser import LineParser +from parsers.RegexpBuilder import RegexpBuilder class CopyLineParser(LineParser): @@ -15,7 +16,8 @@ class CopyLineParser(LineParser): srcFileNameRegexp = r"'(?P[^']+)'" dstFileNameRegexp = r"'(?P[^']+)'$" - regexpSource = self.startsWith('copy') + srcFileNameRegexp + self.keywordToken('to') + dstFileNameRegexp + rb = RegexpBuilder() + regexpSource = rb.startsWith('copy') + srcFileNameRegexp + rb.keywordToken('to') + dstFileNameRegexp regexp = re.compile(regexpSource, re.UNICODE) match = regexp.match(line) diff --git a/scripts/TouchinBuild/parsers/InstallProfileParser.py b/scripts/TouchinBuild/parsers/InstallProfileParser.py index d70797c..c7e227c 100644 --- a/scripts/TouchinBuild/parsers/InstallProfileParser.py +++ b/scripts/TouchinBuild/parsers/InstallProfileParser.py @@ -1,14 +1,10 @@ import re -import os -from parsers.CopyParser.CopyArguments import CopyArguments from parsers.LineParser import LineParser class InstallProfileParser(LineParser): def __init__(self): LineParser.__init__(self) - self.__copyArguments = CopyArguments() - self.__profileStorageDir = '~/Library/MobileDevice/Provisioning Profiles/' def parseLine(self, line): assert line is not None @@ -22,13 +18,4 @@ class InstallProfileParser(LineParser): self._guardMatch(match, line, regexpSource) srcPath = match.group('path') - dstPath = self.getDestinationPath(srcPath) - - self.__copyArguments.setArguments(srcPath, dstPath) - return self.__copyArguments - - def getDestinationPath(self, sourcePath): - profileFileName = os.path.basename(sourcePath) - destination = os.path.join(self.__profileStorageDir, profileFileName) - - return destination \ No newline at end of file + return srcPath \ No newline at end of file diff --git a/scripts/TouchinBuild/parsers/LineParser.py b/scripts/TouchinBuild/parsers/LineParser.py index db0581e..8747007 100644 --- a/scripts/TouchinBuild/parsers/LineParser.py +++ b/scripts/TouchinBuild/parsers/LineParser.py @@ -1,35 +1,20 @@ +import abc + + class LineParser: + __metaclass__ = abc.ABCMeta + def __init__(self): pass + @abc.abstractmethod def parseLine(self, line): - assert line is not None pass + @abc.abstractmethod def isValidLine(self, line): - assert line is not None return False - def keywordToken(self, keyword): - assert keyword is not None - return r'\s+' + keyword + r'\s+' - - def startsWith(self, keyword): - assert keyword is not None - return r'^' + keyword + r'\s+' - - def spaceEndsWith(self, keyword): - assert keyword is not None - return r'\s+' + keyword + '$' - - def endsWith(self, keyword): - assert keyword is not None - return keyword + '$' - - def than(self, keyword): - assert keyword is not None - return keyword + r'\s+' - def _guardMatch(self, match_object, source, regexpSource = None): if match_object is None: msg = 'Recognition exception: "{0}" for "{1}"'.format(source, regexpSource) diff --git a/scripts/TouchinBuild/parsers/MakeDirsParser.py b/scripts/TouchinBuild/parsers/MakeDirsParser.py index 8345596..fa30ff9 100644 --- a/scripts/TouchinBuild/parsers/MakeDirsParser.py +++ b/scripts/TouchinBuild/parsers/MakeDirsParser.py @@ -1,6 +1,7 @@ import re from parsers.LineParser import LineParser +from parsers.RegexpBuilder import RegexpBuilder class MakeDirsParser(LineParser): @@ -10,7 +11,8 @@ class MakeDirsParser(LineParser): def parseLine(self, line): pathRegexp = r"'(?P[^']+)'$" - regexpSource = self.startsWith('create dirs') + pathRegexp + rb = RegexpBuilder() + regexpSource = rb.startsWith('create dirs') + pathRegexp regexp = re.compile(regexpSource, re.UNICODE) match = regexp.match(line) diff --git a/scripts/TouchinBuild/parsers/ParserBackup/CreateBackupParser.py b/scripts/TouchinBuild/parsers/ParserBackup/CreateBackupParser.py index de31ee3..774fede 100644 --- a/scripts/TouchinBuild/parsers/ParserBackup/CreateBackupParser.py +++ b/scripts/TouchinBuild/parsers/ParserBackup/CreateBackupParser.py @@ -1,6 +1,7 @@ import re from parsers.ParserBackup.ParserBackupBase import ParserBackupBase +from parsers.RegexpBuilder import RegexpBuilder class CreateBackupParser(ParserBackupBase): @@ -10,7 +11,8 @@ class CreateBackupParser(ParserBackupBase): def getMatchInfo(self, line): assert line is not None - regexpSource = self.startsWith('create') + self.endsWith('backup') + rb = RegexpBuilder() + regexpSource = rb.startsWith('create') + rb.endsWith('backup') regexp = re.compile(regexpSource, re.UNICODE) match = regexp.match(line) diff --git a/scripts/TouchinBuild/parsers/ParserBackup/DeleteBackupParser.py b/scripts/TouchinBuild/parsers/ParserBackup/DeleteBackupParser.py index 936f4ec..c6238c5 100644 --- a/scripts/TouchinBuild/parsers/ParserBackup/DeleteBackupParser.py +++ b/scripts/TouchinBuild/parsers/ParserBackup/DeleteBackupParser.py @@ -1,6 +1,7 @@ import re from parsers.ParserBackup.ParserBackupBase import ParserBackupBase +from parsers.RegexpBuilder import RegexpBuilder class DeleteBackupParser(ParserBackupBase): @@ -10,7 +11,8 @@ class DeleteBackupParser(ParserBackupBase): def getMatchInfo(self, line): assert line is not None - regexpSource = self.startsWith('delete') + self.endsWith('backup') + rb = RegexpBuilder() + regexpSource = rb.startsWith('delete') + rb.endsWith('backup') regexp = re.compile(regexpSource, re.UNICODE) match = regexp.match(line) diff --git a/scripts/TouchinBuild/parsers/ParserBackup/RestoreBackupParser.py b/scripts/TouchinBuild/parsers/ParserBackup/RestoreBackupParser.py index 3f1ca81..2f5ed4b 100644 --- a/scripts/TouchinBuild/parsers/ParserBackup/RestoreBackupParser.py +++ b/scripts/TouchinBuild/parsers/ParserBackup/RestoreBackupParser.py @@ -1,6 +1,7 @@ import re from parsers.ParserBackup.ParserBackupBase import ParserBackupBase +from parsers.RegexpBuilder import RegexpBuilder class RestoreBackupParser(ParserBackupBase): @@ -10,7 +11,8 @@ class RestoreBackupParser(ParserBackupBase): def getMatchInfo(self, line): assert line is not None - regexpSource = self.startsWith('restore') + self.than('from') + self.endsWith('backup') + rb = RegexpBuilder() + regexpSource = rb.startsWith('restore') + rb.than('from') + rb.endsWith('backup') regexp = re.compile(regexpSource, re.UNICODE) match = regexp.match(line) diff --git a/scripts/TouchinBuild/parsers/RegexpBuilder.py b/scripts/TouchinBuild/parsers/RegexpBuilder.py new file mode 100644 index 0000000..ffa28f4 --- /dev/null +++ b/scripts/TouchinBuild/parsers/RegexpBuilder.py @@ -0,0 +1,20 @@ +class RegexpBuilder: + def keywordToken(self, keyword): + assert keyword is not None + return r'\s+' + keyword + r'\s+' + + def startsWith(self, keyword): + assert keyword is not None + return r'^' + keyword + r'\s+' + + def spaceEndsWith(self, keyword): + assert keyword is not None + return r'\s+' + keyword + '$' + + def endsWith(self, keyword): + assert keyword is not None + return keyword + '$' + + def than(self, keyword): + assert keyword is not None + return keyword + r'\s+' \ No newline at end of file diff --git a/scripts/TouchinBuild/parsers/SettingsParser/SettingsLineParser.py b/scripts/TouchinBuild/parsers/SettingsParser/SettingsLineParser.py index 755d4be..425d9f4 100644 --- a/scripts/TouchinBuild/parsers/SettingsParser/SettingsLineParser.py +++ b/scripts/TouchinBuild/parsers/SettingsParser/SettingsLineParser.py @@ -26,6 +26,11 @@ class SettingsLineParser(LineParser): return result + def isValidLine(self, line): + assert line is not None + + return '=' in line + def splitToPathAndValue(self, line): # some.path = some_value result = line.split('=') diff --git a/scripts/TouchinBuild/parsers/ShParser.py b/scripts/TouchinBuild/parsers/ShParser.py index 6e39807..39f41e4 100644 --- a/scripts/TouchinBuild/parsers/ShParser.py +++ b/scripts/TouchinBuild/parsers/ShParser.py @@ -1,6 +1,7 @@ import re from parsers.LineParser import LineParser +from parsers.RegexpBuilder import RegexpBuilder class ShParser(LineParser): @@ -10,9 +11,10 @@ class ShParser(LineParser): def parseLine(self, line): assert line + rb = RegexpBuilder() cmdTextRegexp = r'(?P.*)' - regexpSource = self.startsWith('sh') + cmdTextRegexp + regexpSource = rb.startsWith('sh') + cmdTextRegexp regexp = re.compile(regexpSource, re.UNICODE) match = regexp.match(line) diff --git a/scripts/TouchinBuild/parsers/TestflightParser.py b/scripts/TouchinBuild/parsers/TestflightParser.py index b27f471..94caf65 100644 --- a/scripts/TouchinBuild/parsers/TestflightParser.py +++ b/scripts/TouchinBuild/parsers/TestflightParser.py @@ -1,5 +1,7 @@ from parsers.LineParser import LineParser import re +from parsers.RegexpBuilder import RegexpBuilder + class TestflightParser(LineParser): def __init__(self): @@ -8,15 +10,17 @@ class TestflightParser(LineParser): def parseLine(self, line): assert line is not None + rb = RegexpBuilder() + notesRegexp = r"'(?P[^']+)'" apiTokenRegexp = r"'(?P[^']+)'" teamTokenRegexp = r"'(?P[^']+)'" filePathRegexp = r"'(?P[^']+)'" - regexpSource = self.startsWith('publish') + filePathRegexp + self.keywordToken('to') + self.than('testflight') + \ - self.than('notes') + self.than('=') + notesRegexp + \ - self.keywordToken('api_token') + self.than('=') + apiTokenRegexp + \ - self.keywordToken('team_token') + self.than('=') + teamTokenRegexp + regexpSource = rb.startsWith('publish') + filePathRegexp + rb.keywordToken('to') + rb.than('testflight') + \ + rb.than('notes') + rb.than('=') + notesRegexp + \ + rb.keywordToken('api_token') + rb.than('=') + apiTokenRegexp + \ + rb.keywordToken('team_token') + rb.than('=') + teamTokenRegexp regexp = re.compile(regexpSource, re.UNICODE) diff --git a/scripts/TouchinBuild/utils/IncludeProcessor.py b/scripts/TouchinBuild/utils/IncludeProcessor.py index c0fa623..4f16fc9 100644 --- a/scripts/TouchinBuild/utils/IncludeProcessor.py +++ b/scripts/TouchinBuild/utils/IncludeProcessor.py @@ -1,5 +1,6 @@ import re from parsers.LineParser import LineParser +from parsers.RegexpBuilder import RegexpBuilder class IncludeProcessor(LineParser): @@ -9,7 +10,8 @@ class IncludeProcessor(LineParser): def getIncludesInfo(self, text): assert text is not None - regexpSource = '<\s*' + self.than('include') + r"'[^']+'" + '\s*>' + rb = RegexpBuilder() + regexpSource = '<\s*' + rb.than('include') + r"'[^']+'" + '\s*>' regexp = re.compile(regexpSource, re.UNICODE) results = regexp.findall(text)