class StepsRunner:
	def __init__(self, config, compositeLineProcessor, valueProvider):
		assert config is not None
		assert compositeLineProcessor is not None
		assert valueProvider is not None

		self.lineConveyor = compositeLineProcessor
		self.valueProvider = valueProvider

		self.shCommandBuilder = ShCommandBuilder()
		self.removeProjectBuilder = RemoveProjectCommandBuilder()
		self.createDirs = MakeDirsCommandBuilder()
		self.patchCsproj = PatchCsprojCommandBuilder()
		self.patchInfoPlist = PatchInfoplistCommandBuilder(self.valueProvider)
		self.patchInfoPlistArray = PatchInfoPlistArrayCommandBuilder()
		self.patchManifest = PatchManifestCommandBuilder()
		self.copyBuilder = CopyCommandBuilder()
		self.testflightBuilder = TestflightCommandBuilder()

		ignoreBackup = config.get('backup_ignore', None)
		self.createBackupBuilder = CreateBackupCommandBuilder(ignoreBackup)
		self.restoreFromBackupBuilder = RestoreBackupCommandBuilder(ignoreBackup)
		self.deleteBackupBuilder = DeleteBackupCommandBuilder(ignoreBackup)


		profilePrefix = config['project_name']
		self.installProfileBuilder = InstallProfileCommandBuilder(profilePrefix)

		buildUtilPath = config['build_tool']
		self.cleanBuilder = CleanBuildCommandBuilder(buildUtilPath, 'clean')
		self.buildBuilder = CleanBuildCommandBuilder(buildUtilPath, 'build')
		self.signAndroid = SignApkCommandBuilder(buildUtilPath)

	def run(self, content):
		assert content is not None

		lines = content.splitlines()
		for line in lines:
			processedLine = self.lineConveyor.processText(line, self.lineConveyor)

			if len(processedLine) == 0:
				continue
			else:
				self.processLine(processedLine)

	def processLine(self, line):
		if self.shCommandBuilder.isShCommand(line):
			cmd = self.shCommandBuilder.getCommandFor(line)
		elif self.removeProjectBuilder.isRemoveProject(line):
			cmd = self.removeProjectBuilder.getCommandFor(line)
		elif self.cleanBuilder.isCleanBuild(line):
			cmd = self.cleanBuilder.getCommandFor(line)
		elif self.buildBuilder.isCleanBuild(line):
			cmd = self.buildBuilder.getCommandFor(line)
		elif self.signAndroid.isSignApk(line):
			cmd = self.signAndroid.getCommandFor(line)
		elif self.createBackupBuilder.isCreateBackup(line):
			cmd = self.createBackupBuilder.getCommandFor(line)
		elif self.createDirs.isMakeDirsCommand(line):
			cmd = self.createDirs.getCommandFor(line)
		elif self.patchCsproj.isPatchCsproj(line):
			cmd = self.patchCsproj.getCommandFor(line)
		elif self.patchInfoPlist.isPatchInfoPlist(line):
			cmd = self.patchInfoPlist.getCommandFor(line)
		elif self.patchInfoPlistArray.isPatchInfoPlist(line):
			cmd = self.patchInfoPlistArray.getCommandFor(line)
		elif self.patchManifest.isManifestCommand(line):
			cmd = self.patchManifest.getCommandFor(line)
		elif self.copyBuilder.isCopy(line):
			cmd =self.copyBuilder.getCommandFor(line)
		elif self.restoreFromBackupBuilder.isRestoreBackup(line):
			cmd = self.restoreFromBackupBuilder.getCommandFor(line)
		elif self.deleteBackupBuilder.isDeleteBackup(line):
			cmd =self.deleteBackupBuilder.getCommandFor(line)
		elif self.testflightBuilder.isTestflight(line):
			cmd = self.testflightBuilder.getCommandFor(line)
		elif self.installProfileBuilder.isInstallProfile(line):
			cmd = self.installProfileBuilder.getCommandFor(line)
		else:
			msg = "unrecognised step. Line: '{0}'".format(line)
			raise Exception(msg)

		print 'start: {0}'.format(line)
		cmd.execute()
		print 'finish: {0}'.format(line)
from CommandBuilders.CopyCommandBuilder import CopyCommandBuilder

line1 = "copy 'BuildSample/BuildSample.sln' to 'BuildSample/BuildSample.txt'"
line2 = "copy 'BuildSample/BuildSample/Profiles/8F606DAE-F9C9-4A19-8EFF-34B990D76C28.mobileprovision' to '~/Library/MobileDevice/Provisioning Profiles/BuildScript.mobileprovision'"

copyCmdBuilder = CopyCommandBuilder()

# copyCmdToRel = copyCmdBuilder.getCommandFor(line1)
# copyCmdToRel.execute()

copyCmdToAbs = copyCmdBuilder.getCommandFor(line2)
copyCmdToAbs.execute()