#!/usr/bin/env python
import sys
import os
from yak import main

miniman = """yak: Usage: yak [SOURCE_DIR] [OUTPUT_DIR]

Use 'yak --build-base' to create a basic Yak blog structure in the current directory.

After running that command, be sure to edit the configuration file '_config.py' before baking your blog.
"""
buildnotice = """Basic Yak blog structure has been created in the current working directory.

Be sure to edit the '_config.py' configuration file before baking your blog."""

def build_base():
    from pkgutil import get_data
    open('_config.py', 'w').write(get_data('yak', 'data/_config.py'))
    os.mkdir('_static')
    open('_static/style.css', 'w').write(get_data('yak', 'data/style.css'))
    open('_static/favicon.ico', 'w').write(get_data('yak', 'data/favicon.ico'))
    os.mkdir('_templates')
    open('_templates/post.html', 'w').write(get_data('yak', 'data/post.html'))
    open('_templates/atom.xml', 'w').write(get_data('yak', 'data/atom.xml'))
    open('_templates/archive.html', 'w').write(get_data('yak', 'data/archive.html'))
    open('_templates/index.html', 'w').write(get_data('yak', 'data/index.html'))
    open('_templates/base.html', 'w').write(get_data('yak', 'data/base.html'))
    os.mkdir('_posts')
    open('_posts/2008-08-08-beijing-olympics.md', 'w').write(get_data('yak', 'data/2008-08-08-beijing-olympics.md'))
    print buildnotice

if len(sys.argv) == 3:
    main(sys.argv[1], sys.argv[2])
elif len(sys.argv) == 2:
    if sys.argv[1] == '--build-base':
        build_base()
    elif sys.argv[1] == '--help' or sys.argv[1] == '-h':
        print miniman
    else:
        main(sys.argv[1], sys.argv[1] + os.sep + '_site')
elif len(sys.argv) == 1:
    main(os.getcwd(), os.getcwd() + os.sep + '_site')
else:
    print miniman
