Унаследовал все комманды от базового класса CommandBase

This commit is contained in:
rzaitov 2013-11-14 12:33:12 +04:00
parent ca7f318949
commit 6d947c7ccd
15 changed files with 81 additions and 35 deletions

View File

@ -1,4 +1,4 @@
from commands.ShCommand import ShCommand
from commands.ShTextCommand import ShTextCommand
from parsers.ShParser import ShParser
@ -19,5 +19,5 @@ class ShCommandBuilder:
cmdText = parser.parseLine(line)
command = ShCommand(cmdText)
command = ShTextCommand(cmdText)
return command

View File

@ -1,7 +1,7 @@
import abc
class PreprocessorBase:
class PreprocessorBase(object):
__metaclass__ = abc.ABCMeta
def __init__(self):

View File

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

View File

@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
import os
from commands.CommandBase import CommandBase
class BaseBackupCommand:
class BaseBackupCommand(CommandBase):
def __init__(self):
CommandBase.__init__(self)
self.folderPath = '.'
# вычислять абсолютные пути надо на этапе создания комманды

View File

@ -1,8 +1,10 @@
from subprocess import call
from commands.ShellCommandBase import ShellCommandBase
class CleanBuildCommandBase:
class CleanBuildCommandBase(ShellCommandBase):
def __init__(self, commandPattern, pathToBuildUtil, slnPath, slnConfig):
ShellCommandBase.__init__(self)
assert commandPattern is not None
assert pathToBuildUtil is not None
assert slnPath is not None
@ -15,4 +17,5 @@ class CleanBuildCommandBase:
def execute(self):
cmdText = self.__commandPattern.format(self.__pathToBuildUtil, self.__slnConfig, self.__slnPath)
call(cmdText, shell=True)
self.executeShell(cmdText)

View File

@ -0,0 +1,12 @@
import abc
class CommandBase(object):
__metaclass__ = abc.ABCMeta
def __init__(self):
pass
@abc.abstractmethod
def execute(self):
pass

View File

@ -1,8 +1,12 @@
import shutil
import os
from commands.CommandBase import CommandBase
class CopyCommand:
class CopyCommand(CommandBase):
def __init__(self, copyArguments):
CommandBase.__init__(self)
assert copyArguments is not None
self.__copyArguments = copyArguments

View File

@ -1,13 +1,10 @@
from commands.ShCommand import ShCommand
from commands.ShTextCommand import ShTextCommand
class MakeDirsCommand:
class MakeDirsCommand(ShTextCommand):
def __init__(self, path):
assert path is not None
self.path = path
self.__path = path
def execute(self):
cmdText = "mkdir -p '{0}'".format(self.__path)
innerCommand = ShCommand(cmdText)
innerCommand.execute()
cmdText = "mkdir -p '{0}'".format(self.path)
ShTextCommand.__init__(self, cmdText)

View File

@ -1,7 +1,10 @@
from commands.CommandBase import CommandBase
import utils.CsprojPatcher as csproj
class PatchCsprojCommand():
class PatchCsprojCommand(CommandBase):
def __init__(self, csprojAbsPath, key, value, slnConfig):
CommandBase.__init__(self)
assert csprojAbsPath is not None
assert key is not None
assert value is not None

View File

@ -1,8 +1,11 @@
from commands.CommandBase import CommandBase
from utils.InfoPlistPatcher import InfoPlistPatcher
class PatchInfoPlistCommand():
class PatchInfoPlistCommand(CommandBase):
def __init__(self, pathToPlist, key, value):
CommandBase.__init__(self)
assert pathToPlist is not None
assert key is not None
assert value is not None

View File

@ -1,8 +1,11 @@
from commands.CommandBase import CommandBase
from utils.SlnPatcher import SlnPatcher
class RemoveProjectCommand:
class RemoveProjectCommand(CommandBase):
def __init__(self, slnPath, projectName):
CommandBase.__init__(self)
assert slnPath is not None
assert projectName is not None

View File

@ -1,11 +0,0 @@
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,12 @@
from commands.ShellCommandBase import ShellCommandBase
class ShTextCommand(ShellCommandBase):
def __init__(self, commandText):
ShellCommandBase.__init__(self)
assert commandText is not None
self.commandText = commandText
def execute(self):
self.executeShell(self.commandText)

View File

@ -0,0 +1,16 @@
from commands.CommandBase import CommandBase
from subprocess import call
class ShellCommandBase(CommandBase):
def __init__(self):
CommandBase.__init__(self)
def executeShell(self, commandText):
assert commandText is not None
retCode = call(commandText, shell=True)
if retCode != 0:
msg = 'problem with shell command: {0}'.format(commandText)
raise Exception(msg)

View File

@ -1,8 +1,11 @@
from commands.CommandBase import CommandBase
from utils.TestflightPublisher import TestFlightPublisher
class TestflightCommand:
class TestflightCommand(CommandBase):
def __init__(self, pathToFile, api_token, team_token, notes):
CommandBase.__init__(self)
assert pathToFile is not None
self.__pathToFile = pathToFile