Добавил возможность запускать sh комманду из скрипта
This commit is contained in:
parent
bdd8b74fba
commit
0174a20c05
|
|
@ -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
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
from commands.ShCommand import ShCommand
|
||||||
|
|
||||||
|
calendarCommand = ShCommand('cal 12 2013')
|
||||||
|
calendarCommand.execute()
|
||||||
|
|
||||||
|
touchCommand = ShCommand('touch ../tmp.txt')
|
||||||
|
touchCommand.execute()
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
__author__ = 'rzaitov'
|
||||||
|
|
@ -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)
|
||||||
|
|
||||||
|
|
@ -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)
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
|
|
@ -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 ')
|
||||||
|
|
@ -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.csproj_test
|
||||||
#import ManualTests.info_plist_test
|
#import ManualTests.info_plist_test
|
||||||
#import ManualTests.copy_test
|
#import ManualTests.copy_test
|
||||||
|
|
@ -5,4 +10,6 @@
|
||||||
#import ManualTests.delete_backup_test
|
#import ManualTests.delete_backup_test
|
||||||
#import ManualTests.restore_backup_test
|
#import ManualTests.restore_backup_test
|
||||||
|
|
||||||
import ManualTests.csproj_test
|
#import ManualTests.csproj_test
|
||||||
|
|
||||||
|
import ManualTests.run_sh_command
|
||||||
Loading…
Reference in New Issue