#!/usr/bin/env python

import exceptions
import cmd
import getopt
import multiprocessing
import os
import string
import sys
import ConfigParser
import MySQLdb
import redwood.filters
import redwood.connection.connect as rconn
from redwood.shell.controller import SessionController


def main(argv):

    if(len(argv) != 1):
        print "Please provide database configuration file"
        sys.exit(1)

    print '\033[1;31m\n\n#################################\nWelcome to Redwood\n#################################\n\033[1;m'

    print "Establishing connection to database...\n",
    print "...running with {} cores".format(multiprocessing.cpu_count())
    print "...loading filters from ./Filters directory if exists"

    cnx = rconn.connect_with_config(argv[0])

    sc = SessionController()
    sc.preloop(cnx)
    sc.cmdloop()

    cnx.close()

if __name__ == "__main__":
    main(sys.argv[1:])
