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/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/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/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..8b13789 --- /dev/null +++ b/scripts/parser/MakeDirsParser.py @@ -0,0 +1 @@ + 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..1df810d 100644 --- a/scripts/run_manual_tests.py +++ b/scripts/run_manual_tests.py @@ -1,3 +1,8 @@ +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 @@ -5,4 +10,6 @@ #import ManualTests.delete_backup_test #import ManualTests.restore_backup_test -import ManualTests.csproj_test \ No newline at end of file +#import ManualTests.csproj_test + +import ManualTests.run_sh_command \ No newline at end of file