Merge branch 'create-dirs'

This commit is contained in:
rzaitov 2013-10-30 19:13:55 +04:00
commit 51e3081151
13 changed files with 184 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,8 @@
from CommandBuilders.MakeDirsCommandBuilder import MakeDirsCommandBuilder
line = "create dirs '../Output/mySuperConfigName/Artifacts'"
builder = MakeDirsCommandBuilder()
command = builder.getCommandFor(line)
command.execute()

View File

@ -0,0 +1,7 @@
from commands.ShCommand import ShCommand
calendarCommand = ShCommand('cal 12 2013')
calendarCommand.execute()
touchCommand = ShCommand('touch ../tmp.txt')
touchCommand.execute()

View File

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

View File

@ -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)

View File

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

View File

@ -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)

View File

@ -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()

View File

@ -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)

View File

@ -0,0 +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 ')

View File

@ -0,0 +1,22 @@
from parser.LineParser import LineParser
import re
class ShParser(LineParser):
def parseLine(self, line):
assert line
cmdTextRegexp = r'(?P<text>.*)'
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 ')

View File

@ -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
import ManualTests.make_dirs