# Path: vocto/debug.py
# def gst_log_messages(level):
# 
#     gstLog = logging.getLogger('Gst')
# 
#     def log( level, msg ):
#         if level == Gst.DebugLevel.WARNING:
#             gstLog.warning(msg)
#         if level == Gst.DebugLevel.FIXME:
#             gstLog.warning(msg)
#         elif level == Gst.DebugLevel.ERROR:
#             gstLog.error(msg)
#         elif level == Gst.DebugLevel.INFO:
#             gstLog.info(msg)
#         elif level == Gst.DebugLevel.DEBUG:
#             gstLog.debug(msg)
# 
#     def logFunction(category, level, file, function, line, object, message, *user_data):
#         global gst_log_messages_lastmessage, gst_log_messages_lastlevel, gst_log_messages_repeat
# 
#         msg = message.get()
#         if gst_log_messages_lastmessage != msg:
#             if gst_log_messages_repeat > 2:
#                 log(gst_log_messages_lastlevel,"%s [REPEATING %d TIMES]" % (gst_log_messages_lastmessage, gst_log_messages_repeat))
# 
#             gst_log_messages_lastmessage = msg
#             gst_log_messages_repeat = 0
#             gst_log_messages_lastlevel = level
#             log(level,"%s: %s (in function %s() in file %s:%d)" % (object.name if object else "", msg, function, file, line))
#         else:
#             gst_log_messages_repeat += 1
# 
# 
#     Gst.debug_remove_log_function(None)
#     Gst.debug_add_log_function(logFunction,None)
#     Gst.debug_set_default_threshold(level)
#     Gst.debug_set_active(True)


import gi
import sdnotify
import signal
import logging
import sys
from vocto.debug import gst_log_messages
from gi.repository import Gst, GLib
from lib.loghandler import LogHandler
        from lib.pipeline import Pipeline
        from lib.controlserver import ControlServer
    from lib import args
    from lib.args import Args
    from lib import config
        self.log.debug('Creating ControlServer')
        self.controlserver = ControlServer(self.pipeline)

    def run(self):
        self.log.info('Running. Waiting for connections....')
        try:
            self.mainloop.run()
        except KeyboardInterrupt:
            self.log.info('Terminated via Ctrl-C')

    def quit(self):
        self.log.info('Quitting.')
        self.mainloop.quit()


# run mainclass
def main():
    # parse command-line args
    args.parse()

    docolor = (Args.color == 'always') \
        or (Args.color == 'auto' and sys.stderr.isatty())

    handler = LogHandler(docolor, Args.timestamp)
    logging.root.addHandler(handler)

    levels = { 3 : logging.DEBUG, 2 : logging.INFO, 1 : logging.WARNING, 0 : logging.ERROR }
    logging.root.setLevel(levels[Args.verbose])

    gst_levels = { 3 : Gst.DebugLevel.DEBUG, 2 : Gst.DebugLevel.INFO, 1 : Gst.DebugLevel.WARNING, 0 : Gst.DebugLevel.ERROR }

# Path: vocto/debug.py
# def gst_log_messages(level):
# 
#     gstLog = logging.getLogger('Gst')
# 
#     def log( level, msg ):
#         if level == Gst.DebugLevel.WARNING:
#             gstLog.warning(msg)
#         if level == Gst.DebugLevel.FIXME:
#             gstLog.warning(msg)
#         elif level == Gst.DebugLevel.ERROR:
#             gstLog.error(msg)
#         elif level == Gst.DebugLevel.INFO:
#             gstLog.info(msg)
#         elif level == Gst.DebugLevel.DEBUG:
#             gstLog.debug(msg)
# 
#     def logFunction(category, level, file, function, line, object, message, *user_data):
#         global gst_log_messages_lastmessage, gst_log_messages_lastlevel, gst_log_messages_repeat
# 
#         msg = message.get()
#         if gst_log_messages_lastmessage != msg:
#             if gst_log_messages_repeat > 2:
#                 log(gst_log_messages_lastlevel,"%s [REPEATING %d TIMES]" % (gst_log_messages_lastmessage, gst_log_messages_repeat))
# 
#             gst_log_messages_lastmessage = msg
#             gst_log_messages_repeat = 0
#             gst_log_messages_lastlevel = level
#             log(level,"%s: %s (in function %s() in file %s:%d)" % (object.name if object else "", msg, function, file, line))
#         else:
#             gst_log_messages_repeat += 1
# 
# 
#     Gst.debug_remove_log_function(None)
#     Gst.debug_add_log_function(logFunction,None)
#     Gst.debug_set_default_threshold(level)
#     Gst.debug_set_active(True)


# Path: voctocore/voctocore.py
import gi
import sdnotify
import signal
import logging
import sys
from vocto.debug import gst_log_messages
from gi.repository import Gst, GLib
from lib.loghandler import LogHandler
        from lib.pipeline import Pipeline
        from lib.controlserver import ControlServer
    from lib import args
    from lib.args import Args
    from lib import config

        self.log.debug('Creating ControlServer')
        self.controlserver = ControlServer(self.pipeline)

    def run(self):
        self.log.info('Running. Waiting for connections....')
        try:
            self.mainloop.run()
        except KeyboardInterrupt:
            self.log.info('Terminated via Ctrl-C')

    def quit(self):
        self.log.info('Quitting.')
        self.mainloop.quit()


# run mainclass
def main():
    # parse command-line args
    args.parse()

    docolor = (Args.color == 'always') \
        or (Args.color == 'auto' and sys.stderr.isatty())

    handler = LogHandler(docolor, Args.timestamp)
    logging.root.addHandler(handler)

    levels = { 3 : logging.DEBUG, 2 : logging.INFO, 1 : logging.WARNING, 0 : logging.ERROR }
    logging.root.setLevel(levels[Args.verbose])

    gst_levels = { 3 : Gst.DebugLevel.DEBUG, 2 : Gst.DebugLevel.INFO, 1 : Gst.DebugLevel.WARNING, 0 : Gst.DebugLevel.ERROR }

    gst_log_messages(gst_levels[Args.gstreamer_log])