Реализовал парсер для команды публикации в тестфлайт

This commit is contained in:
rzaitov 2013-11-01 19:40:16 +04:00
parent 43b881d736
commit 8a5ba62209
11 changed files with 83 additions and 9 deletions

View File

@ -0,0 +1 @@
__author__ = 'rzaitov'

View File

@ -0,0 +1,28 @@
import unittest
from parser.TestflightParser import TestflightParser
class TesttestflightParser(unittest.TestCase):
def setUp(self):
self.parser = TestflightParser()
def test_isValid(self):
line = 'publish bla bla'
isValid = self.parser.isValidLine(line)
self.assertEqual(True, isValid)
def test_isNotValid(self):
line = '*publish'
isValid = self.parser.isValidLine(line)
self.assertEqual(False, isValid)
def test_validInput(self):
line = "publish '~/Dir/another dir/file.ipa' to testflight notes = 'hello world! 123' api_token = 'qwerty123' team_token = 'asdfg123'"
result = self.parser.parseLine(line)
self.assertEqual('~/Dir/another dir/file.ipa', result['path'])
self.assertEqual('hello world! 123', result['notes'])
self.assertEqual('qwerty123',result['api_token'])
self.assertEqual('asdfg123', result['team_token'])

View File

@ -14,7 +14,7 @@ class CreateBackupParser(LineParser):
folderNameRegexp = r"'(?P<folder>[^']+)'$"
regexpSource = self.startsWithKeywordToken('create backup for') + folderNameRegexp
regexpSource = self.startsWith('create backup for') + folderNameRegexp
regexp = re.compile(regexpSource, re.UNICODE)
match = regexp.match(line)

View File

@ -16,7 +16,7 @@ class CleanBuildParser(LineParser):
filePathRegexp = r"'(?P<path>[./ a-zA-Z]+\.sln)'"
slnConfigRegexp = r"'(?P<config>[a-zA-Z|]+)'$"
regexpSource = self.startsWithKeywordToken(self.__commandToken) + filePathRegexp + self.keywordToken('for') + slnConfigRegexp
regexpSource = self.startsWith(self.__commandToken) + filePathRegexp + self.keywordToken('for') + slnConfigRegexp
regexp = re.compile(regexpSource, re.UNICODE)
match = regexp.match(line)

View File

@ -15,7 +15,7 @@ class CopyLineParser(LineParser):
srcFileNameRegexp = r"'(?P<src>[^']+)'"
dstFileNameRegexp = r"'(?P<dst>[^']+)'$"
regexpSource = self.startsWithKeywordToken('copy') + srcFileNameRegexp + self.keywordToken('to') + dstFileNameRegexp
regexpSource = self.startsWith('copy') + srcFileNameRegexp + self.keywordToken('to') + dstFileNameRegexp
regexp = re.compile(regexpSource, re.UNICODE)
match = regexp.match(line)

View File

@ -16,7 +16,7 @@ class InsideRemoveParser(LineParser):
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.endsWithKeywordToken('project')
regexpSource = self.startsWith('inside') + filePathRegexp + self.keywordToken('remove') + projectNameRegexp + self.endsWith('project')
regexp = re.compile(regexpSource, re.UNICODE)
match = regexp.match(line)

View File

@ -18,7 +18,7 @@ class InsideSetParser(LineParser):
keyRegexp = r'(?P<key>[a-zA-Z]+)'
valueRegexp = r"'(?P<value>[^']+)'"
regexpSource = self.startsWithKeywordToken('inside') + filePathRegexp + self.keywordToken('set') + keyRegexp + self.keywordToken('to') + valueRegexp
regexpSource = self.startsWith('inside') + filePathRegexp + self.keywordToken('set') + keyRegexp + self.keywordToken('to') + valueRegexp
regexp = re.compile(regexpSource, re.UNICODE)
match = regexp.match(line)

View File

@ -14,14 +14,18 @@ class LineParser:
assert keyword is not None
return r'\s+' + keyword + r'\s+'
def startsWithKeywordToken(self, keyword):
def startsWith(self, keyword):
assert keyword is not None
return r'^' + keyword + r'\s+'
def endsWithKeywordToken(self, keyword):
def endsWith(self, keyword):
assert keyword is not None
return r'\s+' + 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)

View File

@ -10,7 +10,7 @@ class MakeDirsParser(LineParser):
def parseLine(self, line):
pathRegexp = r"'(?P<path>[^']+)'$"
regexpSource = self.startsWithKeywordToken('create dirs') + pathRegexp
regexpSource = self.startsWith('create dirs') + pathRegexp
regexp = re.compile(regexpSource, re.UNICODE)
match = regexp.match(line)

View File

@ -12,7 +12,7 @@ class ShParser(LineParser):
cmdTextRegexp = r'(?P<text>.*)'
regexpSource = self.startsWithKeywordToken('sh') + cmdTextRegexp
regexpSource = self.startsWith('sh') + cmdTextRegexp
regexp = re.compile(regexpSource, re.UNICODE)
match = regexp.match(line)

View File

@ -0,0 +1,41 @@
from parser.LineParser import LineParser
import re
class TestflightParser(LineParser):
def __init__(self):
LineParser.__init__(self)
def parseLine(self, line):
assert line is not None
notesRegexp = r"'(?P<notes>[^']+)'"
apiTokenRegexp = r"'(?P<api_token>[^']+)'"
teamTokenRegexp = r"'(?P<team_token>[^']+)'"
filePathRegexp = r"'(?P<path>[^']+)'"
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
regexp = re.compile(regexpSource, re.UNICODE)
match = regexp.match(line)
self._guardMatch(match, line, regexpSource)
path = match.group('path')
notes = match.group('notes')
apiToken = match.group('api_token')
teamToken = match.group('team_token')
return {
'path': path,
'notes': notes,
'api_token': apiToken,
'team_token': teamToken
}
def isValidLine(self, line):
assert line is not None
return line.startswith('publish')