#!/usr/bin/env python
import os
import sys
import shutil
from omdox import settings
from omdox import feedback
from omdox.render import render
from omdox.builder import get_contents_dict, clean, build


feedback.header('Rendering starting', indent=False)
# set working directory
cwd = os.getcwd()
# if there is no layout.html in this directory then fail
if not os.path.exists('./layout.html'):
    print_error('layout.html not found, are you in the right directory?')
    sys.exit()
# clean up
feedback.info('Cleaning old builds')
clean(cwd)
# get the contents
contents_dict = get_contents_dict(cwd)
# now build
for directory, contents_list in contents_dict.items():
    build(cwd, directory, contents_list)
# now feedback
for error in feedback.errors:
    feedback.error(error)
feedback.header('Rendering complete', indent=False)
