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/CommandBuilders/ShCommandBuilder.py b/scripts/CommandBuilders/ShCommandBuilder.py new file mode 100644 index 0000000..edcf924 --- /dev/null +++ b/scripts/CommandBuilders/ShCommandBuilder.py @@ -0,0 +1,20 @@ +from commands.ShCommand import ShCommand +from parser.ShParser import ShParser + + +class ShCommandBuilder: + def isShCommand(self, line): + assert line is not None + + parser = ShParser() + isValid = parser.isValidLine(line) + + return isValid + + def getCommandFor(self, line): + parser = ShParser() + + cmdText = parser.parseLine(line) + + command = ShCommand(cmdText) + return command 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/ManualTests/run_sh_command.py b/scripts/ManualTests/run_sh_command.py new file mode 100644 index 0000000..8b633ff --- /dev/null +++ b/scripts/ManualTests/run_sh_command.py @@ -0,0 +1,7 @@ +from commands.ShCommand import ShCommand + +calendarCommand = ShCommand('cal 12 2013') +calendarCommand.execute() + +touchCommand = ShCommand('touch ../tmp.txt') +touchCommand.execute() 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/UnitTests/ShParser/__init__.py b/scripts/UnitTests/ShParser/__init__.py new file mode 100644 index 0000000..cc31abc --- /dev/null +++ b/scripts/UnitTests/ShParser/__init__.py @@ -0,0 +1 @@ +__author__ = 'rzaitov' diff --git a/scripts/UnitTests/ShParser/test_shPareser.py b/scripts/UnitTests/ShParser/test_shPareser.py new file mode 100644 index 0000000..f5eb030 --- /dev/null +++ b/scripts/UnitTests/ShParser/test_shPareser.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +import unittest +from parser.ShParser import ShParser + + +class TestShParser(unittest.TestCase): + def setUp(self): + self.parser = ShParser() + + def test_isValid(self): + line = 'sh 123 ./±~ bla' + isValid = self.parser.isValidLine(line) + + self.assertEqual(True, isValid) + + def test_isNotValid(self): + line = 'copy 123 ./±~ bla' + isValid = self.parser.isValidLine(line) + + self.assertEqual(False, isValid) + + def test_Parse(self): + line = 'sh 123 ./±~ bla' + shCmdText = self.parser.parseLine(line) + + self.assertEqual('123 ./±~ bla', shCmdText) + 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/commands/ShCommand.py b/scripts/commands/ShCommand.py new file mode 100644 index 0000000..54f02f8 --- /dev/null +++ b/scripts/commands/ShCommand.py @@ -0,0 +1,11 @@ +from subprocess import call + + +class ShCommand: + def __init__(self, commandText): + assert commandText is not None + + self.__commandText = commandText + + def execute(self): + call(self.__commandText, shell=True) diff --git a/scripts/parser/MakeDirsParser.py b/scripts/parser/MakeDirsParser.py new file mode 100644 index 0000000..1366866 --- /dev/null +++ b/scripts/parser/MakeDirsParser.py @@ -0,0 +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 ') diff --git a/scripts/parser/ShParser.py b/scripts/parser/ShParser.py new file mode 100644 index 0000000..0613f21 --- /dev/null +++ b/scripts/parser/ShParser.py @@ -0,0 +1,22 @@ +from parser.LineParser import LineParser +import re + +class ShParser(LineParser): + def parseLine(self, line): + assert line + + cmdTextRegexp = r'(?P.*)' + + regexpSource = self.startsWithKeywordToken('sh') + cmdTextRegexp + regexp = re.compile(regexpSource, re.UNICODE) + + match = regexp.match(line) + self._guardMatch(match, line, regexpSource) + + cmdText = match.group('text') + return cmdText + + def isValidLine(self, line): + assert line is not None + + return line.startswith('sh ') \ No newline at end of file diff --git a/scripts/run_manual_tests.py b/scripts/run_manual_tests.py index ad72b79..c9d71c1 100644 --- a/scripts/run_manual_tests.py +++ b/scripts/run_manual_tests.py @@ -1,8 +1,15 @@ +import os +scriptFilePath = os.path.abspath(__file__) +scriptDir = os.path.dirname(scriptFilePath) +os.chdir(scriptDir) + #import ManualTests.csproj_test #import ManualTests.info_plist_test #import ManualTests.copy_test #import ManualTests.create_backup_test #import ManualTests.delete_backup_test #import ManualTests.restore_backup_test +#import ManualTests.csproj_test +#import ManualTests.run_sh_command -import ManualTests.csproj_test \ No newline at end of file +import ManualTests.make_dirs \ No newline at end of file