diff --git a/scripts/CommandBuilders/MakeDirsCommandBuilder.py b/scripts/CommandBuilders/MakeDirsCommandBuilder.py new file mode 100644 index 0000000..f523e9f --- /dev/null +++ b/scripts/CommandBuilders/MakeDirsCommandBuilder.py @@ -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 \ No newline at end of file diff --git a/scripts/ManualTests/make_dirs.py b/scripts/ManualTests/make_dirs.py new file mode 100644 index 0000000..68175e5 --- /dev/null +++ b/scripts/ManualTests/make_dirs.py @@ -0,0 +1,8 @@ +from CommandBuilders.MakeDirsCommandBuilder import MakeDirsCommandBuilder + +line = "create dirs '../Output/mySuperConfigName/Artifacts'" + +builder = MakeDirsCommandBuilder() + +command = builder.getCommandFor(line) +command.execute() \ No newline at end of file diff --git a/scripts/UnitTests/MakeDirsParser/__init__.py b/scripts/UnitTests/MakeDirsParser/__init__.py new file mode 100644 index 0000000..cc31abc --- /dev/null +++ b/scripts/UnitTests/MakeDirsParser/__init__.py @@ -0,0 +1 @@ +__author__ = 'rzaitov' diff --git a/scripts/UnitTests/MakeDirsParser/test_makeDirsParser.py b/scripts/UnitTests/MakeDirsParser/test_makeDirsParser.py new file mode 100644 index 0000000..6e1178a --- /dev/null +++ b/scripts/UnitTests/MakeDirsParser/test_makeDirsParser.py @@ -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) diff --git a/scripts/commands/MakeDirsCommand.py b/scripts/commands/MakeDirsCommand.py new file mode 100644 index 0000000..7ba3c22 --- /dev/null +++ b/scripts/commands/MakeDirsCommand.py @@ -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() diff --git a/scripts/parser/MakeDirsParser.py b/scripts/parser/MakeDirsParser.py index 8b13789..1366866 100644 --- a/scripts/parser/MakeDirsParser.py +++ b/scripts/parser/MakeDirsParser.py @@ -1 +1,20 @@ +from parser.LineParser import LineParser +import re +class MakeDirsParser(LineParser): + def parseLine(self, line): + pathRegexp = r"'(?P[^']+)'$" + + 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 ')