Унаследовал все комманды от базового класса 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 from parsers.ShParser import ShParser
@ -19,5 +19,5 @@ class ShCommandBuilder:
cmdText = parser.parseLine(line) cmdText = parser.parseLine(line)
command = ShCommand(cmdText) command = ShTextCommand(cmdText)
return command return command

View File

@ -1,7 +1,7 @@
import abc import abc
class PreprocessorBase: class PreprocessorBase(object):
__metaclass__ = abc.ABCMeta __metaclass__ = abc.ABCMeta
def __init__(self): 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() calendarCommand.execute()
touchCommand = ShCommand('touch ../tmp.txt') touchCommand = ShTextCommand('touch ../tmp.txt')
touchCommand.execute() touchCommand.execute()

View File

@ -1,10 +1,11 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os import os
from commands.CommandBase import CommandBase
class BaseBackupCommand: class BaseBackupCommand(CommandBase):
def __init__(self): def __init__(self):
CommandBase.__init__(self)
self.folderPath = '.' 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): def __init__(self, commandPattern, pathToBuildUtil, slnPath, slnConfig):
ShellCommandBase.__init__(self)
assert commandPattern is not None assert commandPattern is not None
assert pathToBuildUtil is not None assert pathToBuildUtil is not None
assert slnPath is not None assert slnPath is not None
@ -15,4 +17,5 @@ class CleanBuildCommandBase:
def execute(self): def execute(self):
cmdText = self.__commandPattern.format(self.__pathToBuildUtil, self.__slnConfig, self.__slnPath) 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 shutil
import os import os
from commands.CommandBase import CommandBase
class CopyCommand:
class CopyCommand(CommandBase):
def __init__(self, copyArguments): def __init__(self, copyArguments):
CommandBase.__init__(self)
assert copyArguments is not None assert copyArguments is not None
self.__copyArguments = copyArguments 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): def __init__(self, path):
assert path is not None assert path is not None
self.path = path
self.__path = path cmdText = "mkdir -p '{0}'".format(self.path)
ShTextCommand.__init__(self, cmdText)
def execute(self):
cmdText = "mkdir -p '{0}'".format(self.__path)
innerCommand = ShCommand(cmdText)
innerCommand.execute()

View File

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

View File

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

View File

@ -1,8 +1,11 @@
from commands.CommandBase import CommandBase
from utils.SlnPatcher import SlnPatcher from utils.SlnPatcher import SlnPatcher
class RemoveProjectCommand: class RemoveProjectCommand(CommandBase):
def __init__(self, slnPath, projectName): def __init__(self, slnPath, projectName):
CommandBase.__init__(self)
assert slnPath is not None assert slnPath is not None
assert projectName 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 from utils.TestflightPublisher import TestFlightPublisher
class TestflightCommand: class TestflightCommand(CommandBase):
def __init__(self, pathToFile, api_token, team_token, notes): def __init__(self, pathToFile, api_token, team_token, notes):
CommandBase.__init__(self)
assert pathToFile is not None assert pathToFile is not None
self.__pathToFile = pathToFile self.__pathToFile = pathToFile