class CopyLineParser(LineParser):
	def __init__(self):
		LineParser.__init__(self)
		self.__copyArguments = CopyArguments()

	def parseLine(self, line):
		assert line is not None

		srcFileNameRegexp = r"'(?P<src>[^']+)'"
		dstFileNameRegexp = r"'(?P<dst>[^']+)'$"

		rb = RegexpBuilder()
		regexpSource = rb.startsWith('copy') + srcFileNameRegexp + rb.keywordToken('to') + dstFileNameRegexp
		regexp = re.compile(regexpSource, re.UNICODE)

		match = regexp.match(line)
		self._guardMatch(match, line, regexpSource)

		src = match.group('src')
		dst = match.group('dst')

		self.__copyArguments.setArguments(src, dst)
		return self.__copyArguments

	def isValidLine(self, line):
		assert line is not None

		isValid = line.startswith("copy")
		return isValid
	def getCommandFor(self, line):
		assert line is not None

		parser = InstallProfileParser()

		srcPath = parser.parseLine(line)
		dstPath = self.getDestinationPath(srcPath)

		cpArgs = CopyArguments()
		cpArgs.setArguments(srcPath, dstPath)

		command = CopyCommand(cpArgs)
		return command
	def setUp(self):
		self.__copyArguments = CopyArguments()
class TestCopyArguments(unittest.TestCase):
	def setUp(self):
		self.__copyArguments = CopyArguments()

	def test_isValid(self):
		self.__copyArguments.setArguments("someVal1", "someVal2")
		isValid = self.__copyArguments.isValid()

		self.assertEqual(True, isValid)

	def test_notValid(self):
		self.__copyArguments.setArguments(None, "someVal2")
		isValid = self.__copyArguments.isValid()

		self.assertEqual(False, isValid)

	def test_safeValues(self):
		self.__copyArguments.setArguments('val1', 'val2')

		safeSrc = self.__copyArguments.getSafeSource()
		safeDst = self.__copyArguments.getSaveTarget()

		self.assertEqual('val1', safeSrc)
		self.assertEqual('val2', safeDst)

	def test_unsafeValues(self):
		self.__copyArguments.setArguments('val1 with ws', 'val2 with ws')

		safeSrc = self.__copyArguments.getSafeSource()
		safeDst = self.__copyArguments.getSaveTarget()

		self.assertEqual('"val1 with ws"', safeSrc)
		self.assertEqual('"val2 with ws"', safeDst)
	def __init__(self):
		LineParser.__init__(self)
		self.__copyArguments = CopyArguments()