# coding: utf-8
# Copyright (c) 2010-2012 Raphaël Barrois

"""Common action code."""


class BaseAction(object):
    def __init__(self, source, destination, fs, **kwargs):
        super(BaseAction, self).__init__(**kwargs)
        self.source = source
        self.fs = fs

    def forward(self, categories):
        """Apply the action."""
        raise NotImplementedError()

    def backward(self, categories):
        """Revert the action."""
        raise NotImplementedError()


class FileContentAction(BaseAction):
    """An action based on file *contents*."""

    def forward(self, categories):
        source_lines = self.fs.readlines(self.source)
        destination_lines = self.forward_file(source_lines, categories)
        self.fs.writelines(self.destination, destination_lines)

    def forward_file(self, source_lines, categories):
        """Convert the source file, based on its lines.
        
        Args:
            source_lines (str list): lines of the original file
            categories (str list): active categories
        
        Yields:
            str: lines of the destination file
        """
        raise NotImplementedError()

    def backward(self, categories):
        source_lines = self.fs.readlines(self.source)
        modified_lines = self.fs.readlines(self.destination)
        updated_lines = self.backward_file(source_lines, categories, modified_lines)

        self.fs.writelines(self.source, updated_lines)

    def backward_file(self, source_lines, categories, modified_lines):
        """Convert back the modified file, based on its lines.
        
        Args:
            source_lines (str list): lines of the original file
            categories (str list): active categories
            modified_lines (str list): lines of the modified files
        
        Yields:
            str: new lines for the source file
        """
        raise NotImplementedError()


class FileProcessingAction(FileContentAction):
    def forward_file(self, source_lines, categories):
        processor = converter.FileProcessor(source_lines, self.fs)
        return processor.forward(categories)

    def backward_file(self, source_lines, categories, modified_lines):
        processor = converter.FileProcessor(source_lines, self.fs)
        return processor.backward(categories, modified_lines)

@@ -470,32 +470,472 @@
 mentedError()%0A%0A%0A
+class CopyAction(BaseAction):%0A    def forward(self, categories):%0A        self.fs.copy(self.source, self.destination)%0A%0A    def backward(self, categories):%0A        self.fs.copy(self.destination, self.source)%0A%0A%0Aclass SymLinkAction(BaseAction):%0A    def forward(self, categories):%0A        self.fs.create_symlink(%0A            link_name=self.destination,%0A            link_target=self.source,%0A            relative=False,%0A            force=False)%0A%0A%0A
 class FileConten

Add more actions.