# Copyright (c) 2010, Robert Escriva
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
#     * Redistributions of source code must retain the above copyright notice,
#       this list of conditions and the following disclaimer.
#     * Redistributions in binary form must reproduce the above copyright
#       notice, this list of conditions and the following disclaimer in the
#       documentation and/or other materials provided with the distribution.
#     * Neither the name of Firmant nor the names of its contributors may be
#       used to endorse or promote products derived from this software without
#       specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


import collections
import logging

from firmant.i18n import _
from firmant.utils import class_name


class Writer(object):
    '''Handle writing parsed objects to the filesystem.
    '''

    def __init__(self, settings, objs, urlmapper):
        self.settings = settings
        self.objs = objs
        self.urlmapper = urlmapper
        self.log = logging.getLogger(class_name(self.__class__))

    def urls(self):
        '''Return a list of rooted paths that this writer will write.

        Each path is assumed to be rooted relative to the webroot of the blog.

        It is assumed that all paths begin with '/' and those ending with a '/'
        implicitly include the additional path component 'index.html'.

            >>> w = Writer(None, None, None)
            >>> w.urls()
            []

        '''
        return []

    def write(self):
        '''Write the objects to the filesystem.

            >>> w = Writer(None, None, None)
            >>> w.write()

        '''
        pass

    def write_preconditions(self):
        '''Returns true if and only if it is acceptable to proceed with writing.

        Normal conditions::

            >>> # If the output dir is not set, log a critical error:
            >>> from pysettings.settings import Settings
            >>> w = Writer(Settings(OUTPUT_DIR='foo'), None, None)
            >>> w.log = Mock('log')
            >>> w.write_preconditions()
            True

        Error conditions::

            >>> # If the output dir is not set, log a critical error:
            >>> from pysettings.settings import Settings
            >>> w = Writer(Settings(), None, None)
            >>> w.log = Mock('log')
            >>> w.write_preconditions()
            Called log.critical('``OUTPUT_DIR`` not defined in settings.')
            False

        '''
        # Fail if we do not have an output directory.
        if getattr(self.settings, 'OUTPUT_DIR', None) is None:
            self.log.critical(_('``OUTPUT_DIR`` not defined in settings.'))
            return False
        return True

@@ -1550,16 +1550,178 @@
 MAGE.%0A%0A%0A
+'''Writers create the filesystem to be published.%0A%0AEach writer will handle a subset of the objs, and create a portion of the%0Aoutputted directory hierarchy.%0A'''%0A%0A%0A
 import c
@@ -1890,16 +1890,286 @@
 esystem.
+%0A%0A    It is assumed that a writer will have the following methods::%0A%0A        - write:  Write all objects to the filesystem.%0A        - write_preconditions:  Tests that the writer is able to write.  If this%0A          returns False, it is likely that the writer would fail.
 %0A    '''
@@ -2415,16 +2415,9 @@
  '''
-Return a
+A
  lis
@@ -2421,23 +2421,16 @@
 list of 
-rooted 
 paths th
@@ -2434,18 +2434,17 @@
  that th
-is
+e
  writer 
@@ -2495,15 +2495,8 @@
  be 
-rooted 
 rela
@@ -2527,17 +2527,23 @@
 he blog.
-%0A
+  It is
 %0A       
@@ -2547,31 +2547,22 @@
     
-It is assumed
+implicit
  that 
-all 
 path
@@ -2582,106 +2582,135 @@
 '/' 
-and those ending with a '/'%0A        implicitly include the additional path component 'index.html'.
+(e.g. the path 'foo/bar' translates%0A        to a request URI of '/foo/bar').  This method returns nothing in the%0A        base::
 %0A%0A  
@@ -2780,23 +2780,8 @@
 ls()
-%0A            %5B%5D
 %0A%0A  
@@ -2802,17 +2802,12 @@
     
-return %5B%5D
+pass
 %0A%0A  
@@ -2870,24 +2870,72 @@
 ilesystem.%0A%0A
+        This method does nothing in the base::%0A%0A
             

PyLint firmant.writers