#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
    Build the Documentation
    ~~~~~~~~~~~~~~~~~~~~~~~

    This command builds the documentation for Zine or a plugin.

    :copyright: (c) 2009 by the Zine Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
"""
import sys
from os.path import isdir, join, dirname, pardir, abspath
from optparse import OptionParser


sys.path.append(dirname(__file__))
import _init_zine
from zine.docs.builder import walk


def main():
    parser = OptionParser(usage='%prog [options] [path]')
    options, args = parser.parse_args()
    if not args:
        path = join(dirname(__file__), pardir, 'zine', 'docs')
    elif len(args) == 1:
        path = join(args[0], 'docs')
        if not isdir(path):
            parser.error('source folder missing')
    else:
        parser.error('incorrect number of arguments')
    path = abspath(path)
    print 'Building docs from', path

    def callback(filename):
        print filename
    walk(path, callback)
    print 'All done.'


if __name__ == '__main__':
    main()
