#!/usr/bin/env python
# -*- coding: utf-8 -*-

import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('post_gen_project')

import shutil
import os

ROOT = os.getcwd()
DOC_SOURCES = 'doc_sources'
DOCS = 'docs'
DOC_TYPE_FILES_MAP = {
    'mkdocs': ['index.md', '/mkdocs.yml'],
    'sphinx': ['conf.py', 'index.rst', 'make.bat', 'Makefile']
}

def move_doc_files(which):
    logger.info('Initializing docs for %s' % which)
    if not os.path.exists(DOCS):
        os.mkdir(DOCS)
    for item in DOC_TYPE_FILES_MAP[which]:
        dst, name = (ROOT, item[1:]) if item.startswith('/') else (DOCS, item)
        src_path = os.path.join(DOC_SOURCES, which, name)
        dst_path = os.path.join(dst, name)
        logger.info('Moving %s to %s.' % (src_path, dst_path))
        if os.path.exists(dst_path):
            os.unlink(dst_path)
        os.rename(src_path, dst_path)

{% if cookiecutter.docs_tool == "mkdocs" %}

move_doc_files("mkdocs")

{% elif cookiecutter.docs_tool == "sphinx" %}

move_doc_files("sphinx")

{% endif %}

logger.info("Removing all temporary documentation sources")
shutil.rmtree(DOC_SOURCES)

logger.info('Removing all temporary license files')
shutil.rmtree('licenses')

logger.info('Removing jinja2 macros')
shutil.rmtree('macros')

@@ -895,165 +895,84 @@
 h)%0A%0A
-%7B%25 if cookiecutter.docs_tool == %22mkdocs%22 %25%7D%0A%0Amove_doc_files(%22mkdocs%22)%0A%0A%7B%25 elif cookiecutter.docs_tool == %22sphinx%22 %25%7D%0A%0Amove_doc_files(%22sphinx%22)%0A%0A%7B%25 endif %25%7D%0A%0A
+%0Adef tidy_up():%0A    for dir in %5BDOC_SOURCES, 'licenses', 'macros'%5D:%0A        
 logg
@@ -981,31 +981,25 @@
 .info(%22Remov
-ing all
+e
  temporary d
@@ -1001,197 +1001,106 @@
 ary 
-documentation sources%22)%0Ashutil.rmtree(DOC_SOURCES)%0A%0Alogger.info('Removing all temporary license files')%0Ashutil.rmtree('licenses')%0A%0Alogger.info('Removing jinja2 macros')%0Ashutil.rmtree('macros'
+folder: %25s%22 %25 dir)%0A        shutil.rmtree(dir)%0A%0Amove_doc_files(%22%7B%7Bcookiecutter.docs_tool%7D%7D%22)%0Atidy_up(
 )%0A

use of jinja2 templating not necessary -> make a valid Python module