#!/usr/bin/env python
from graphite import settings
from optparse import OptionParser
import os
import django

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "graphite.settings")
django.setup()

from graphite.storage import write_index


if __name__ == "__main__":
    description = "A tool to generate the search index file used by"\
        " graphite-web."
    prog = "build-index"
    version = "1.0"
    epilog = "Defaults are read from graphite.settings, it is unlikely"\
        " that you would want to run this program with anything except the"\
        " defaults."
    parser = OptionParser(description=description, prog=prog, version=version,
        epilog=epilog)
    parser.add_option("-i", "--index", default=settings.INDEX_FILE,
        help="default: %default")
    (options, args) = parser.parse_args()
    write_index(options.index)
