# Path: ravel/clean.py
# def clean():
#     "Try to kill Pox controller and clean Mininet"
#     logger.info("killing Pox controller instance")
#     os.system("pkill -9 -f pox.py")
# 
#     logger.info("cleaning Mininet")
#     mininet.clean.cleanup()
# 
# Path: ravel/cli.py
# def RavelCLI(opts):
#     """Start a RavelConsole instance given a list of command line options
#        opts: parsed OptionParser object"""
#     if opts.custom:
#         ravel.mndeps.custom(opts.custom)
# 
#     if opts.topo:
#         topo = ravel.mndeps.build(opts.topo)
#         if topo is None:
#             print "Invalid mininet topology", opts.topo
#             return
#     else: 
#         topo = ravel.mndeps.build("empty")
# 
#     if opts.script is not None and not os.path.isfile(opts.script):
#         print "{0}: no such script file".format(opts.script)
#         return
# 
#     passwd = None
#     if opts.password:
#         passwd = getpass.getpass("Enter password: ")
# 
#     raveldb = ravel.db.RavelDb(opts.db,
#                                opts.user,
#                                ravel.db.BASE_SQL,
#                                passwd,
#                                opts.reconnect)
# 
#     if opts.noctl:
#         controller = None
#     else:
#         if PoxInstance.is_running():
#             print "Pox instance is already running.  Please shut down " \
#                 "existing controller first (or run ravel.py --clean)."
#             return
# 
#         controller = PoxInstance("ravel.controller.poxmgr")
# 
#     from ravel.network import MininetProvider, EmptyNetProvider
#     if opts.onlydb:
#         net = EmptyNetProvider(raveldb, topo)
#     else:
#         net = MininetProvider(raveldb, topo, controller)
# 
#     if net is None:
#         print "Cannot start network"
# 
#     env = Environment(raveldb, net, Config.AppDirs, opts)
#     env.start()
# 
#     while True:
#         try:
#             if opts.script is not None:
#                 RavelConsole(env).do_exec(opts.script)
# 
#                 if opts.exit:
#                     break
# 
#             RavelConsole(env, quiet=opts.script).cmdloop()
#             break
#         except Exception, e:
#             logger.warning("console crashed: %s", e)
# 
#     env.stop()
# 
# Path: ravel/log.py
# LEVELS = { "debug" : logging.DEBUG,
#            "info" : logging.INFO,
#            "warning" : logging.WARNING,
#            "error" : logging.ERROR,
#            "critical" : logging.CRITICAL
#        }
# DEFAULT_LEVEL = logging.ERROR
# MSG_FORMAT = "%(levelname)s:%(funcName)s: %(message)s"
# class Singleton(type):
# class RavelLogger(Logger, object):
#     def __init__(cls, name, bases, dict_):
#     def __call__(cls, *args, **kw):
#     def __init__(self):
#     def setLogLevel(self, levelname=None):
# 
# Path: ravel/util.py
# class ConnectionType:
# class ConfigParameters(object):
# def update_trigger_path(filename, path):
# def append_path(path):
# def resource_string(name):
# def resource_file(name=None):
# def splitArgs( argstr ):
#     def makeNumeric( s ):
#     def __init__(self):
#     def read(self, cfg):


import os
import sys
from optparse import OptionParser
from ravel.clean import clean
from ravel.cli import RavelCLI
from ravel.log import LEVELS, logger
from ravel.util import Config
#!/usr/bin/env python


# add ravel to path
if "PYTHONPATH" in os.environ:
    sys.path = os.environ["PYTHONPATH"].split(":") + sys.path
    raveldir = os.path.dirname(os.path.abspath(__file__))
    sys.path.append(os.path.abspath(raveldir))


def optParser():
    desc = "Ravel console"
    usage = "%prog [options]\ntype %prog -h for details"

    parser = OptionParser(description=desc, usage=usage)
    parser.add_option("--clean", "-c", action="store_true", default=False,
                      help="cleanup Ravel and Mininet")
    parser.add_option("--onlydb", "-o", action="store_true", default=False,
                      help="start without Mininet")
    parser.add_option("--reconnect", "-r", action="store_true", default=False,
                      help="reconnect to existing database, skipping db reinit")
    parser.add_option("--noctl", "-n", action="store_true", default=False,
                      help="start without controller (Mininet will still "
                      "attempt to connect to a remote controller)")
    parser.add_option("--db", "-d", type="string", default=Config.DbName,

# Path: ravel/clean.py
# def clean():
#     "Try to kill Pox controller and clean Mininet"
#     logger.info("killing Pox controller instance")
#     os.system("pkill -9 -f pox.py")
# 
#     logger.info("cleaning Mininet")
#     mininet.clean.cleanup()
# 
# Path: ravel/cli.py
# def RavelCLI(opts):
#     """Start a RavelConsole instance given a list of command line options
#        opts: parsed OptionParser object"""
#     if opts.custom:
#         ravel.mndeps.custom(opts.custom)
# 
#     if opts.topo:
#         topo = ravel.mndeps.build(opts.topo)
#         if topo is None:
#             print "Invalid mininet topology", opts.topo
#             return
#     else: 
#         topo = ravel.mndeps.build("empty")
# 
#     if opts.script is not None and not os.path.isfile(opts.script):
#         print "{0}: no such script file".format(opts.script)
#         return
# 
#     passwd = None
#     if opts.password:
#         passwd = getpass.getpass("Enter password: ")
# 
#     raveldb = ravel.db.RavelDb(opts.db,
#                                opts.user,
#                                ravel.db.BASE_SQL,
#                                passwd,
#                                opts.reconnect)
# 
#     if opts.noctl:
#         controller = None
#     else:
#         if PoxInstance.is_running():
#             print "Pox instance is already running.  Please shut down " \
#                 "existing controller first (or run ravel.py --clean)."
#             return
# 
#         controller = PoxInstance("ravel.controller.poxmgr")
# 
#     from ravel.network import MininetProvider, EmptyNetProvider
#     if opts.onlydb:
#         net = EmptyNetProvider(raveldb, topo)
#     else:
#         net = MininetProvider(raveldb, topo, controller)
# 
#     if net is None:
#         print "Cannot start network"
# 
#     env = Environment(raveldb, net, Config.AppDirs, opts)
#     env.start()
# 
#     while True:
#         try:
#             if opts.script is not None:
#                 RavelConsole(env).do_exec(opts.script)
# 
#                 if opts.exit:
#                     break
# 
#             RavelConsole(env, quiet=opts.script).cmdloop()
#             break
#         except Exception, e:
#             logger.warning("console crashed: %s", e)
# 
#     env.stop()
# 
# Path: ravel/log.py
# LEVELS = { "debug" : logging.DEBUG,
#            "info" : logging.INFO,
#            "warning" : logging.WARNING,
#            "error" : logging.ERROR,
#            "critical" : logging.CRITICAL
#        }
# DEFAULT_LEVEL = logging.ERROR
# MSG_FORMAT = "%(levelname)s:%(funcName)s: %(message)s"
# class Singleton(type):
# class RavelLogger(Logger, object):
#     def __init__(cls, name, bases, dict_):
#     def __call__(cls, *args, **kw):
#     def __init__(self):
#     def setLogLevel(self, levelname=None):
# 
# Path: ravel/util.py
# class ConnectionType:
# class ConfigParameters(object):
# def update_trigger_path(filename, path):
# def append_path(path):
# def resource_string(name):
# def resource_file(name=None):
# def splitArgs( argstr ):
#     def makeNumeric( s ):
#     def __init__(self):
#     def read(self, cfg):


# Path: ravel.py
import os
import sys
from optparse import OptionParser
from ravel.clean import clean
from ravel.cli import RavelCLI
from ravel.log import LEVELS, logger
from ravel.util import Config

#!/usr/bin/env python


# add ravel to path
if "PYTHONPATH" in os.environ:
    sys.path = os.environ["PYTHONPATH"].split(":") + sys.path
    raveldir = os.path.dirname(os.path.abspath(__file__))
    sys.path.append(os.path.abspath(raveldir))


def optParser():
    desc = "Ravel console"
    usage = "%prog [options]\ntype %prog -h for details"

    parser = OptionParser(description=desc, usage=usage)
    parser.add_option("--clean", "-c", action="store_true", default=False,
                      help="cleanup Ravel and Mininet")
    parser.add_option("--onlydb", "-o", action="store_true", default=False,
                      help="start without Mininet")
    parser.add_option("--reconnect", "-r", action="store_true", default=False,
                      help="reconnect to existing database, skipping db reinit")
    parser.add_option("--noctl", "-n", action="store_true", default=False,
                      help="start without controller (Mininet will still "
                      "attempt to connect to a remote controller)")
    parser.add_option("--db", "-d", type="string", default=Config.DbName,

                      help="Postgresql database name (default: %s)" % Config.DbName)