From 6d947c7ccdd73a2cc278bd2fdfcd200cfc3ad98f Mon Sep 17 00:00:00 2001 From: rzaitov Date: Thu, 14 Nov 2013 12:33:12 +0400 Subject: [PATCH 1/3] =?UTF-8?q?=D0=A3=D0=BD=D0=B0=D1=81=D0=BB=D0=B5=D0=B4?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BB=20=D0=B2=D1=81=D0=B5=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=BC=D0=B0=D0=BD=D0=B4=D1=8B=20=D0=BE=D1=82=20=D0=B1?= =?UTF-8?q?=D0=B0=D0=B7=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE=20=D0=BA=D0=BB=D0=B0?= =?UTF-8?q?=D1=81=D1=81=D0=B0=20CommandBase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CommandBuilders/ShCommandBuilder.py | 4 ++-- .../Core/LineConveyor/PreprocessorBase.py | 2 +- .../Tests/ManualTests/run_sh_command.py | 6 +++--- .../BaseBackupCommand/BaseBackupCommand.py | 5 +++-- .../CleanBuildCommands/CleanBuildCommandBase.py | 9 ++++++--- scripts/TouchinBuild/commands/CommandBase.py | 12 ++++++++++++ scripts/TouchinBuild/commands/CopyCommand.py | 6 +++++- scripts/TouchinBuild/commands/MakeDirsCommand.py | 13 +++++-------- .../TouchinBuild/commands/PatchCsprojCommand.py | 5 ++++- .../commands/PatchInfoPlistCommand.py | 5 ++++- .../commands/RemoveProjectCommand.py | 5 ++++- scripts/TouchinBuild/commands/ShCommand.py | 11 ----------- scripts/TouchinBuild/commands/ShTextCommand.py | 12 ++++++++++++ .../TouchinBuild/commands/ShellCommandBase.py | 16 ++++++++++++++++ .../TouchinBuild/commands/TestflightCommand.py | 5 ++++- 15 files changed, 81 insertions(+), 35 deletions(-) create mode 100644 scripts/TouchinBuild/commands/CommandBase.py delete mode 100644 scripts/TouchinBuild/commands/ShCommand.py create mode 100644 scripts/TouchinBuild/commands/ShTextCommand.py create mode 100644 scripts/TouchinBuild/commands/ShellCommandBase.py diff --git a/scripts/TouchinBuild/CommandBuilders/ShCommandBuilder.py b/scripts/TouchinBuild/CommandBuilders/ShCommandBuilder.py index b555582..bbe4cfd 100644 --- a/scripts/TouchinBuild/CommandBuilders/ShCommandBuilder.py +++ b/scripts/TouchinBuild/CommandBuilders/ShCommandBuilder.py @@ -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 diff --git a/scripts/TouchinBuild/Core/LineConveyor/PreprocessorBase.py b/scripts/TouchinBuild/Core/LineConveyor/PreprocessorBase.py index 2a18eda..d07e2fb 100644 --- a/scripts/TouchinBuild/Core/LineConveyor/PreprocessorBase.py +++ b/scripts/TouchinBuild/Core/LineConveyor/PreprocessorBase.py @@ -1,7 +1,7 @@ import abc -class PreprocessorBase: +class PreprocessorBase(object): __metaclass__ = abc.ABCMeta def __init__(self): diff --git a/scripts/TouchinBuild/Tests/ManualTests/run_sh_command.py b/scripts/TouchinBuild/Tests/ManualTests/run_sh_command.py index 8b633ff..d32bc5a 100644 --- a/scripts/TouchinBuild/Tests/ManualTests/run_sh_command.py +++ b/scripts/TouchinBuild/Tests/ManualTests/run_sh_command.py @@ -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() diff --git a/scripts/TouchinBuild/commands/BaseBackupCommand/BaseBackupCommand.py b/scripts/TouchinBuild/commands/BaseBackupCommand/BaseBackupCommand.py index 95a4eb7..aba3acc 100644 --- a/scripts/TouchinBuild/commands/BaseBackupCommand/BaseBackupCommand.py +++ b/scripts/TouchinBuild/commands/BaseBackupCommand/BaseBackupCommand.py @@ -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 = '.' # вычислять абсолютные пути надо на этапе создания комманды diff --git a/scripts/TouchinBuild/commands/CleanBuildCommands/CleanBuildCommandBase.py b/scripts/TouchinBuild/commands/CleanBuildCommands/CleanBuildCommandBase.py index 8bed240..38dd455 100644 --- a/scripts/TouchinBuild/commands/CleanBuildCommands/CleanBuildCommandBase.py +++ b/scripts/TouchinBuild/commands/CleanBuildCommands/CleanBuildCommandBase.py @@ -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) diff --git a/scripts/TouchinBuild/commands/CommandBase.py b/scripts/TouchinBuild/commands/CommandBase.py new file mode 100644 index 0000000..6411593 --- /dev/null +++ b/scripts/TouchinBuild/commands/CommandBase.py @@ -0,0 +1,12 @@ +import abc + + +class CommandBase(object): + __metaclass__ = abc.ABCMeta + + def __init__(self): + pass + + @abc.abstractmethod + def execute(self): + pass diff --git a/scripts/TouchinBuild/commands/CopyCommand.py b/scripts/TouchinBuild/commands/CopyCommand.py index dc8dd94..dd9d032 100644 --- a/scripts/TouchinBuild/commands/CopyCommand.py +++ b/scripts/TouchinBuild/commands/CopyCommand.py @@ -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 diff --git a/scripts/TouchinBuild/commands/MakeDirsCommand.py b/scripts/TouchinBuild/commands/MakeDirsCommand.py index 7ba3c22..1fece89 100644 --- a/scripts/TouchinBuild/commands/MakeDirsCommand.py +++ b/scripts/TouchinBuild/commands/MakeDirsCommand.py @@ -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) \ No newline at end of file diff --git a/scripts/TouchinBuild/commands/PatchCsprojCommand.py b/scripts/TouchinBuild/commands/PatchCsprojCommand.py index 68007eb..00036e3 100644 --- a/scripts/TouchinBuild/commands/PatchCsprojCommand.py +++ b/scripts/TouchinBuild/commands/PatchCsprojCommand.py @@ -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 diff --git a/scripts/TouchinBuild/commands/PatchInfoPlistCommand.py b/scripts/TouchinBuild/commands/PatchInfoPlistCommand.py index c16987b..a9654df 100644 --- a/scripts/TouchinBuild/commands/PatchInfoPlistCommand.py +++ b/scripts/TouchinBuild/commands/PatchInfoPlistCommand.py @@ -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 diff --git a/scripts/TouchinBuild/commands/RemoveProjectCommand.py b/scripts/TouchinBuild/commands/RemoveProjectCommand.py index 858d205..61ae1df 100644 --- a/scripts/TouchinBuild/commands/RemoveProjectCommand.py +++ b/scripts/TouchinBuild/commands/RemoveProjectCommand.py @@ -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 diff --git a/scripts/TouchinBuild/commands/ShCommand.py b/scripts/TouchinBuild/commands/ShCommand.py deleted file mode 100644 index 54f02f8..0000000 --- a/scripts/TouchinBuild/commands/ShCommand.py +++ /dev/null @@ -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) diff --git a/scripts/TouchinBuild/commands/ShTextCommand.py b/scripts/TouchinBuild/commands/ShTextCommand.py new file mode 100644 index 0000000..839a1af --- /dev/null +++ b/scripts/TouchinBuild/commands/ShTextCommand.py @@ -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) \ No newline at end of file diff --git a/scripts/TouchinBuild/commands/ShellCommandBase.py b/scripts/TouchinBuild/commands/ShellCommandBase.py new file mode 100644 index 0000000..79807cc --- /dev/null +++ b/scripts/TouchinBuild/commands/ShellCommandBase.py @@ -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) \ No newline at end of file diff --git a/scripts/TouchinBuild/commands/TestflightCommand.py b/scripts/TouchinBuild/commands/TestflightCommand.py index f0b73f0..1cc9878 100644 --- a/scripts/TouchinBuild/commands/TestflightCommand.py +++ b/scripts/TouchinBuild/commands/TestflightCommand.py @@ -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 From a27b3ff8b7155c8769067805b1171f72f8e9a19d Mon Sep 17 00:00:00 2001 From: rzaitov Date: Thu, 14 Nov 2013 12:40:49 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D0=9F=D0=BE=D1=84=D0=B8=D0=BA=D1=81=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BF=D1=80=D0=B5=D0=B4=D1=83=D0=BF=D1=80=D0=B5=D0=B6?= =?UTF-8?q?=D0=B4=D0=B5=D0=BD=D0=B8=D1=8F=20code=20inspect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/TouchinBuild/Tests/Common/SettingsProviderStub.py | 5 ++++- .../TouchinBuild/Tests/ManualTests/macros_include_test.py | 7 ++++++- scripts/TouchinBuild/Tests/ManualTests/resolve_settings.py | 4 +++- scripts/TouchinBuild/Tests/ManualTests/run_sh_command.py | 2 +- .../UnitTests/InsideParsers/test_insideSetArrayParser.py | 1 - .../TouchinBuild/parsers/InsideParser/InsideParserBase.py | 2 +- 6 files changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts/TouchinBuild/Tests/Common/SettingsProviderStub.py b/scripts/TouchinBuild/Tests/Common/SettingsProviderStub.py index 3b0cc32..f7346f2 100644 --- a/scripts/TouchinBuild/Tests/Common/SettingsProviderStub.py +++ b/scripts/TouchinBuild/Tests/Common/SettingsProviderStub.py @@ -1,3 +1,4 @@ +from Core.LineConveyor.NullPreprocessor import NullPreprocessor from Core.SettingsProviderBase import SettingsProviderBase from parsers.SettingsParser.SettingsParser import SettingsParser @@ -10,7 +11,9 @@ class SettingsProviderStub(SettingsProviderBase): self.settingsText = settingsText def fetchSettings(self): - parser = SettingsParser() + preprocessor = NullPreprocessor() + + parser = SettingsParser(preprocessor, None) parser.parse(self.settingsText) return parser.settings \ No newline at end of file diff --git a/scripts/TouchinBuild/Tests/ManualTests/macros_include_test.py b/scripts/TouchinBuild/Tests/ManualTests/macros_include_test.py index ca8a6b3..a3c03d9 100644 --- a/scripts/TouchinBuild/Tests/ManualTests/macros_include_test.py +++ b/scripts/TouchinBuild/Tests/ManualTests/macros_include_test.py @@ -1,6 +1,8 @@ from Core.ContentProviderBase import ContentProviderBase +from Core.LineConveyor.NullPreprocessor import NullPreprocessor from Tests.Common.SettingsProviderStub import SettingsProviderStub from taskRunner import TaskRunner +from utils.BuildConfigProvider.BuildConfigProvider import BuildConfigProvider settingsText = """ build_tool = '/Applications/Xamarin\ Studio.app/Contents/MacOS/mdtool' @@ -42,6 +44,9 @@ class ContentProviderMock(ContentProviderBase): settingsProvider = SettingsProviderStub(settingsText) contentProvider = ContentProviderMock() -taskRunner = TaskRunner(settingsProvider, contentProvider) +buildConfigProvider = BuildConfigProvider() +preprocessor = NullPreprocessor() + +taskRunner = TaskRunner(settingsProvider, contentProvider, buildConfigProvider, preprocessor) taskRunner.run() diff --git a/scripts/TouchinBuild/Tests/ManualTests/resolve_settings.py b/scripts/TouchinBuild/Tests/ManualTests/resolve_settings.py index 9bf097a..b60aa96 100644 --- a/scripts/TouchinBuild/Tests/ManualTests/resolve_settings.py +++ b/scripts/TouchinBuild/Tests/ManualTests/resolve_settings.py @@ -1,4 +1,5 @@ from Core.ContentProviderBase import ContentProviderBase +from Core.LineConveyor.NullPreprocessor import NullPreprocessor from Tests.Common.SettingsProviderStub import SettingsProviderStub from taskRunner import TaskRunner from utils.BuildConfigProvider.BuildConfigProvider import BuildConfigProvider @@ -37,8 +38,9 @@ buildConfigProvider = BuildConfigProvider() resolvedBuildConfigProvider = ResolvedBuildConfigProvider(buildConfigProvider) contentProvider = ContentProviderMock() +preprocessor = NullPreprocessor() -taskRunner = TaskRunner(settingsProvider, contentProvider, resolvedBuildConfigProvider) +taskRunner = TaskRunner(settingsProvider, contentProvider, resolvedBuildConfigProvider, preprocessor) taskRunner.run() diff --git a/scripts/TouchinBuild/Tests/ManualTests/run_sh_command.py b/scripts/TouchinBuild/Tests/ManualTests/run_sh_command.py index d32bc5a..de85742 100644 --- a/scripts/TouchinBuild/Tests/ManualTests/run_sh_command.py +++ b/scripts/TouchinBuild/Tests/ManualTests/run_sh_command.py @@ -1,4 +1,4 @@ -from commands.ShCommand import ShTextCommand +from commands.ShTextCommand import ShTextCommand calendarCommand = ShTextCommand('cal 12 2013') calendarCommand.execute() diff --git a/scripts/TouchinBuild/Tests/UnitTests/InsideParsers/test_insideSetArrayParser.py b/scripts/TouchinBuild/Tests/UnitTests/InsideParsers/test_insideSetArrayParser.py index 224d8e2..1f19716 100644 --- a/scripts/TouchinBuild/Tests/UnitTests/InsideParsers/test_insideSetArrayParser.py +++ b/scripts/TouchinBuild/Tests/UnitTests/InsideParsers/test_insideSetArrayParser.py @@ -1,4 +1,3 @@ -import unittest from Tests.UnitTests.LineParserTestCaseBase import LineParserTestCaseBase from parsers.InsideParser.InsideSetArrayParser import InsideSetArrayParser diff --git a/scripts/TouchinBuild/parsers/InsideParser/InsideParserBase.py b/scripts/TouchinBuild/parsers/InsideParser/InsideParserBase.py index c824749..9515110 100644 --- a/scripts/TouchinBuild/parsers/InsideParser/InsideParserBase.py +++ b/scripts/TouchinBuild/parsers/InsideParser/InsideParserBase.py @@ -14,7 +14,7 @@ class InsideParserBase(object, LineParser): @abc.abstractmethod def getMatchInfo(self, line): - "Not implemented" + # "Not implemented" return None, None def fetchMatchFor(self, text): From aa0b3394ea018d591d36ab2ffe2784bb820b1304 Mon Sep 17 00:00:00 2001 From: rzaitov Date: Thu, 14 Nov 2013 12:59:16 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=BD=D0=B0=20=D0=B2=D0=BE?= =?UTF-8?q?=D0=B7=D0=B2=D1=80=D0=B0=D1=89=D0=B0=D0=B5=D0=BC=D1=8B=D0=B5=20?= =?UTF-8?q?=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20shell=20comm?= =?UTF-8?q?and?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Tests/UnitTests/ShellCommand/__init__.py | 1 + .../ShellCommand/test_shellCommand.py | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 scripts/TouchinBuild/Tests/UnitTests/ShellCommand/__init__.py create mode 100644 scripts/TouchinBuild/Tests/UnitTests/ShellCommand/test_shellCommand.py diff --git a/scripts/TouchinBuild/Tests/UnitTests/ShellCommand/__init__.py b/scripts/TouchinBuild/Tests/UnitTests/ShellCommand/__init__.py new file mode 100644 index 0000000..cc31abc --- /dev/null +++ b/scripts/TouchinBuild/Tests/UnitTests/ShellCommand/__init__.py @@ -0,0 +1 @@ +__author__ = 'rzaitov' diff --git a/scripts/TouchinBuild/Tests/UnitTests/ShellCommand/test_shellCommand.py b/scripts/TouchinBuild/Tests/UnitTests/ShellCommand/test_shellCommand.py new file mode 100644 index 0000000..34be057 --- /dev/null +++ b/scripts/TouchinBuild/Tests/UnitTests/ShellCommand/test_shellCommand.py @@ -0,0 +1,24 @@ +import unittest +from commands.ShellCommandBase import ShellCommandBase + + +class MyShellCommand(ShellCommandBase): + def __init__(self, execWithError=False): + ShellCommandBase.__init__(self) + self.execWithError = execWithError + + def execute(self): + cmdText = 'exit 1' if self.execWithError else 'exit 0' + self.executeShell(cmdText) + + +class TestShellCommand(unittest.TestCase): + def test_noError(self): + cmd = MyShellCommand(execWithError=False) + cmd.execute() + + def test_withError(self): + cmd = MyShellCommand(execWithError=True) + + with self.assertRaises(Exception): + cmd.execute() \ No newline at end of file