#!/usr/bin/python
# coding: utf8

# PyIndex
# author: Ondrej Sika, http://ondrejsika.com, ondrej@ondrejsika.com


import argparse
import os, sys
import libpyindex


parser = argparse.ArgumentParser()
parser.add_argument("-t", "--type", help="index type, 'html' or 'json'", default="json")
parser.add_argument("-p", "--path", help="path", default=".")
args = parser.parse_args()


index_type = args.type

if index_type == "html":
    index = lambda path: libpyindex.as_html(libpyindex.index(path))
elif index_type == "json":
    index = lambda path: libpyindex.as_json(libpyindex.index(path))
else:
    print "Unknow index_type '%s'" % index_type
    exit()

for directory, x, y in os.walk(args.path):
    file(os.path.join(directory, "index.%s"%index_type), "w").write(index(directory))
