#!/usr/bin/env python

import sys
from optparse import OptionParser
from ceres import CeresTree


parser = OptionParser(usage='''%prog [options] <path/to/tree/root/> [property=value]*''')
parser.add_option('--verbose', action='store_true')

options, args = parser.parse_args()

if not args:
  print "You must specify a root directory for the tree"
  parser.print_usage()
  sys.exit(1)


root_dir = args[0]
props = {}

for arg in args[1:]:
  prop, value = arg.split('=', 1)

  try:  # convert numeric types
    value = float(value)
  except:
    try:
      value = int(value)
    except:
      pass

  props[prop] = value

if options.verbose:
  print "Creating tree at %s with props=%s" % (root_dir, props)

tree = CeresTree.createTree(root_dir, **props)
