# 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/cmdlog.py
# class CmdLog(object):
#     def __init__(self):
#     def logline(self, line):
#     def __del__(self):


import cmd
import importlib
import os
import re
import sys
import time
import tempfile
import psycopg2
import sqlparse
import ravel.util
from sqlparse.tokens import Keyword
from ravel.log import logger
from ravel.cmdlog import cmdLogger
    # is dropped before 'table'
    return sorted(components, key=lambda x: x.typ)

class AppConsole(cmd.Cmd):
    "Superclass for an application's sub-shell"

    def __init__(self, db, env, components):
        """db: a ravel.db.RavelDb instance
           env: a ravel.env.Environment instance of the CLI's executing environment
           components: list of the app's SQL components (tables, view, etc.)"""
        self.db = db
        self.env = env
        self.components = components
        self.logOn = False
        cmd.Cmd.__init__(self)

    def emptyline(self):
        "Don't repeat the last line when hitting return on empty line"
        return

    def onecmd(self, line):
        "Run command and report execution time for each execution line"  
        if line:
            if self.logOn:
                startTime = time.time()
                stop = cmd.Cmd.onecmd(self, line)
                endTime = time.time()
                elapsed = round((endTime - startTime)*1000, 3)
                cmdLogger.logline('cmd: '+line)
                logger.info("Execution time: {0}ms".format(elapsed))

# 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/cmdlog.py
# class CmdLog(object):
#     def __init__(self):
#     def logline(self, line):
#     def __del__(self):


# Path: ravel/app.py
import cmd
import importlib
import os
import re
import sys
import time
import tempfile
import psycopg2
import sqlparse
import ravel.util
from sqlparse.tokens import Keyword
from ravel.log import logger
from ravel.cmdlog import cmdLogger

    # is dropped before 'table'
    return sorted(components, key=lambda x: x.typ)

class AppConsole(cmd.Cmd):
    "Superclass for an application's sub-shell"

    def __init__(self, db, env, components):
        """db: a ravel.db.RavelDb instance
           env: a ravel.env.Environment instance of the CLI's executing environment
           components: list of the app's SQL components (tables, view, etc.)"""
        self.db = db
        self.env = env
        self.components = components
        self.logOn = False
        cmd.Cmd.__init__(self)

    def emptyline(self):
        "Don't repeat the last line when hitting return on empty line"
        return

    def onecmd(self, line):
        "Run command and report execution time for each execution line"  
        if line:
            if self.logOn:
                startTime = time.time()
                stop = cmd.Cmd.onecmd(self, line)
                endTime = time.time()
                elapsed = round((endTime - startTime)*1000, 3)
                cmdLogger.logline('cmd: '+line)
                logger.info("Execution time: {0}ms".format(elapsed))

                cmdLogger.logline('start time: {0}'.format(time.asctime(time.localtime(startTime))))