# 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
# def resource_file(name=None):
#     """Search for a file within the distribution and return its absolute path.
#        If no name is passed, returns the absolute path to the distribution's
#        top-level directory
#        name: the name of the file
#        returns: absolute path to the file"""
#     install_path = os.path.dirname(os.path.abspath(__file__))
#     install_path = os.path.normpath(
#         os.path.join(install_path, ".."))
# 
#     if name is None:
#         return install_path
# 
#     return os.path.abspath(os.path.join(install_path, name))


import psycopg2
from ravel.log import logger
from ravel.util import resource_file
                nodes[host] = node_count
                self.cursor.execute("INSERT INTO hosts (hid, ip, mac, name) "
                                    "VALUES ({0}, '{1}', '{2}', '{3}');"
                                    .format(node_count, ip, mac, host))

            for link in topo.links():
                h1,h2 = link
                if h1 in topo.switches() and h2 in topo.switches():
                    ishost = 0
                else:
                    ishost = 1

                sid = nodes[h1]
                nid = nodes[h2]
                self.cursor.execute("INSERT INTO tp(sid, nid, ishost, isactive) "
                                    "VALUES ({0}, {1}, {2}, {3});"
                                    .format(sid, nid, ishost, 1))

                # bidirectional edges
                self.cursor.execute("INSERT INTO tp(sid, nid, ishost, isactive) "
                                    "VALUES ({1}, {0}, {2}, {3});"
                                    .format(sid, nid, ishost, 1))

                self.cursor.execute("INSERT INTO ports(sid, nid, port) "
                                    "VALUES ({0}, {1}, {2}), ({1}, {0}, {3});"
                                    .format(sid, nid,
                                            topo.port(h1, h2)[0],
                                            topo.port(h1, h2)[1]))

        except psycopg2.DatabaseError, e:

# 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
# def resource_file(name=None):
#     """Search for a file within the distribution and return its absolute path.
#        If no name is passed, returns the absolute path to the distribution's
#        top-level directory
#        name: the name of the file
#        returns: absolute path to the file"""
#     install_path = os.path.dirname(os.path.abspath(__file__))
#     install_path = os.path.normpath(
#         os.path.join(install_path, ".."))
# 
#     if name is None:
#         return install_path
# 
#     return os.path.abspath(os.path.join(install_path, name))


# Path: ravel/db.py
import psycopg2
from ravel.log import logger
from ravel.util import resource_file

                nodes[host] = node_count
                self.cursor.execute("INSERT INTO hosts (hid, ip, mac, name) "
                                    "VALUES ({0}, '{1}', '{2}', '{3}');"
                                    .format(node_count, ip, mac, host))

            for link in topo.links():
                h1,h2 = link
                if h1 in topo.switches() and h2 in topo.switches():
                    ishost = 0
                else:
                    ishost = 1

                sid = nodes[h1]
                nid = nodes[h2]
                self.cursor.execute("INSERT INTO tp(sid, nid, ishost, isactive) "
                                    "VALUES ({0}, {1}, {2}, {3});"
                                    .format(sid, nid, ishost, 1))

                # bidirectional edges
                self.cursor.execute("INSERT INTO tp(sid, nid, ishost, isactive) "
                                    "VALUES ({1}, {0}, {2}, {3});"
                                    .format(sid, nid, ishost, 1))

                self.cursor.execute("INSERT INTO ports(sid, nid, port) "
                                    "VALUES ({0}, {1}, {2}), ({1}, {0}, {3});"
                                    .format(sid, nid,
                                            topo.port(h1, h2)[0],
                                            topo.port(h1, h2)[1]))

        except psycopg2.DatabaseError, e:

            logger.warning("error loading topology: %s", self.fmt_errmsg(e))