#!/usr/bin/env python3

import signal
import logging
import sys



from gi.repository import GObject

GObject.threads_init()
import time

from lib.args import Args
from lib.loghandler import LogHandler
import lib.connection as Connection

def testCallback(args):
    log = logging.getLogger("Test")
    log.info(str(args))


class Voctoconfig(object):

    def __init__(self):
        self.log = logging.getLogger("Voctoconfig")
        self.log.debug("Creating GObject Mainloop")
        self.mainloop = GObject.MainLoop()

    def run(self):
        self.log.info("Running MainLoop")
        try:
            self.mainloop.run()
        except KeyboardInterrupt:
            self.log.info("Terminated via KeyboardInterrupt")

    def quit(self):
        self.log.info("Quitting MainLoop")
        self.mainloop.quit()

def main():
    docolor = (Args.color == 'always') or (Args.color == 'auto' and
                                           sys.stderr.isatty())
    loghandler = LogHandler(docolor, Args.timestamp)
    logging.root.addHandler(loghandler)
    if Args.verbose >= 2:
        level = logging.DEBUG
    elif Args.verbose == 1:
        level = logging.INFO
    else:
        level = logging.WARNING

    logging.root.setLevel(level)
    logging.debug('setting SIGINT handler')
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    Connection.establish(Args.host)
    Connection.enterNonblockingMode()
    Connection.on("message", testCallback)
    mainloop = GObject.MainLoop()
    mainloop.run()
    while True:
        logging.debug("mimimi...")
        Connection.send("message", "test2")
        time.sleep(10)


if __name__ == '__main__':
    main()
[(11, 'gi.repository.GObject.threads_init', 'GObject.threads_init', ([], {}), False, 'from gi.repository import GObject\n'), (19, 'logging.getLogger', 'logging.getLogger', (['"""Test"""'], {}), False, 'import logging\n'), (44, 'lib.loghandler.LogHandler', 'LogHandler', (['docolor', 'Args.timestamp'], {}), False, 'from lib.loghandler import LogHandler\n'), (45, 'logging.root.addHandler', 'logging.root.addHandler', (['loghandler'], {}), False, 'import logging\n'), (53, 'logging.root.setLevel', 'logging.root.setLevel', (['level'], {}), False, 'import logging\n'), (54, 'logging.debug', 'logging.debug', (['"""setting SIGINT handler"""'], {}), False, 'import logging\n'), (55, 'signal.signal', 'signal.signal', (['signal.SIGINT', 'signal.SIG_DFL'], {}), False, 'import signal\n'), (56, 'lib.connection.establish', 'Connection.establish', (['Args.host'], {}), True, 'import lib.connection as Connection\n'), (57, 'lib.connection.enterNonblockingMode', 'Connection.enterNonblockingMode', ([], {}), True, 'import lib.connection as Connection\n'), (58, 'lib.connection.on', 'Connection.on', (['"""message"""', 'testCallback'], {}), True, 'import lib.connection as Connection\n'), (59, 'gi.repository.GObject.MainLoop', 'GObject.MainLoop', ([], {}), False, 'from gi.repository import GObject\n'), (26, 'logging.getLogger', 'logging.getLogger', (['"""Voctoconfig"""'], {}), False, 'import logging\n'), (28, 'gi.repository.GObject.MainLoop', 'GObject.MainLoop', ([], {}), False, 'from gi.repository import GObject\n'), (62, 'logging.debug', 'logging.debug', (['"""mimimi..."""'], {}), False, 'import logging\n'), (63, 'lib.connection.send', 'Connection.send', (['"""message"""', '"""test2"""'], {}), True, 'import lib.connection as Connection\n'), (64, 'time.sleep', 'time.sleep', (['(10)'], {}), False, 'import time\n'), (43, 'sys.stderr.isatty', 'sys.stderr.isatty', ([], {}), False, 'import sys\n')]