реализовал построитель команды для создания дерева папок и ручной тест
This commit is contained in:
parent
0174a20c05
commit
07b205a6e3
|
|
@ -0,0 +1,21 @@
|
||||||
|
from commands.MakeDirsCommand import MakeDirsCommand
|
||||||
|
from parser.MakeDirsParser import MakeDirsParser
|
||||||
|
|
||||||
|
|
||||||
|
class MakeDirsCommandBuilder:
|
||||||
|
def isMakeDirsCommand(self, line):
|
||||||
|
assert line is not None
|
||||||
|
|
||||||
|
parser = MakeDirsParser()
|
||||||
|
isValid = parser.isValidLine(line)
|
||||||
|
|
||||||
|
return isValid
|
||||||
|
|
||||||
|
def getCommandFor(self, line):
|
||||||
|
assert line is not None
|
||||||
|
|
||||||
|
parser = MakeDirsParser()
|
||||||
|
path = parser.parseLine(line)
|
||||||
|
|
||||||
|
command = MakeDirsCommand(path)
|
||||||
|
return command
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
from CommandBuilders.MakeDirsCommandBuilder import MakeDirsCommandBuilder
|
||||||
|
|
||||||
|
line = "create dirs '../Output/mySuperConfigName/Artifacts'"
|
||||||
|
|
||||||
|
builder = MakeDirsCommandBuilder()
|
||||||
|
|
||||||
|
command = builder.getCommandFor(line)
|
||||||
|
command.execute()
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
__author__ = 'rzaitov'
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
import unittest
|
||||||
|
from parser.MakeDirsParser import MakeDirsParser
|
||||||
|
|
||||||
|
|
||||||
|
class TestMakeDirsParser(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.parser = MakeDirsParser()
|
||||||
|
|
||||||
|
def test_isValid(self):
|
||||||
|
line = 'create dirs bla bla'
|
||||||
|
isValid = self.parser.isValidLine(line)
|
||||||
|
|
||||||
|
self.assertEqual(True, isValid)
|
||||||
|
|
||||||
|
def test_isNotValid(self):
|
||||||
|
line = 'create dirs bla bla'
|
||||||
|
isValid = self.parser.isValidLine(line)
|
||||||
|
|
||||||
|
self.assertEqual(False, isValid)
|
||||||
|
|
||||||
|
def test_parse(self):
|
||||||
|
line = r"create dirs '~/Some dir/../'"
|
||||||
|
path = self.parser.parseLine(line)
|
||||||
|
|
||||||
|
self.assertEqual('~/Some dir/../', path)
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
from commands.ShCommand import ShCommand
|
||||||
|
|
||||||
|
|
||||||
|
class MakeDirsCommand:
|
||||||
|
def __init__(self, path):
|
||||||
|
assert path is not None
|
||||||
|
|
||||||
|
self.__path = path
|
||||||
|
|
||||||
|
def execute(self):
|
||||||
|
cmdText = "mkdir -p '{0}'".format(self.__path)
|
||||||
|
innerCommand = ShCommand(cmdText)
|
||||||
|
innerCommand.execute()
|
||||||
|
|
@ -1 +1,20 @@
|
||||||
|
from parser.LineParser import LineParser
|
||||||
|
import re
|
||||||
|
|
||||||
|
class MakeDirsParser(LineParser):
|
||||||
|
def parseLine(self, line):
|
||||||
|
pathRegexp = r"'(?P<path>[^']+)'$"
|
||||||
|
|
||||||
|
regexpSource = self.startsWithKeywordToken('create dirs') + pathRegexp
|
||||||
|
regexp = re.compile(regexpSource, re.UNICODE)
|
||||||
|
|
||||||
|
match = regexp.match(line)
|
||||||
|
self._guardMatch(match, line, regexpSource)
|
||||||
|
|
||||||
|
path = match.group('path')
|
||||||
|
return path
|
||||||
|
|
||||||
|
def isValidLine(self, line):
|
||||||
|
assert line is not None
|
||||||
|
|
||||||
|
return line.startswith('create dirs ')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue