#!/usr/bin/env python
"""
A script that crawls a directory and builds an index.html file as required.
"""
import argparse
import ghtalks
import os

def serve(head, header, footer):
    root = os.getcwd()
    crwl = ghtalks.Crawl()
    crwl.crawl_directories(os.path.join(root, '.'))
    index = ghtalks.Index(crwl.generate_talks(), head, header, footer)
    index.generate_output()
    index.write()

if __name__ == "__main__":

    parser = argparse.ArgumentParser()
    parser.add_argument('-s', '--serve', action='store_true',
                        help='Write the index.html file')
    parser.add_argument('-hd', '--head', default='head.html',
                        help='Location of head.html file')
    parser.add_argument('-hr', '--header', default='header.html',
                        help='Location of header.html file')
    parser.add_argument('-fr', '--footer', default='footer.html',
                        help='Location of footer.html file')
    args = parser.parse_args()
    if args.serve:
        serve(args.head, args.header, args.footer)
