#!/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, 0, 11, 22), 'gi.repository.GObject.threads_init', 'GObject.threads_init', ({}, {}), '()', False, 'from gi.repository import GObject\n'), ((19, 10, 19, 35), 'logging.getLogger', 'logging.getLogger', ({(19, 28, 19, 34): '"""Test"""'}, {}), "('Test')", False, 'import logging\n'), ((44, 17, 44, 52), 'lib.loghandler.LogHandler', 'LogHandler', ({(44, 28, 44, 35): 'docolor', (44, 37, 44, 51): 'Args.timestamp'}, {}), '(docolor, Args.timestamp)', False, 'from lib.loghandler import LogHandler\n'), ((45, 4, 45, 39), 'logging.root.addHandler', 'logging.root.addHandler', ({(45, 28, 45, 38): 'loghandler'}, {}), '(loghandler)', False, 'import logging\n'), ((53, 4, 53, 32), 'logging.root.setLevel', 'logging.root.setLevel', ({(53, 26, 53, 31): 'level'}, {}), '(level)', False, 'import logging\n'), ((54, 4, 54, 43), 'logging.debug', 'logging.debug', ({(54, 18, 54, 42): '"""setting SIGINT handler"""'}, {}), "('setting SIGINT handler')", False, 'import logging\n'), ((55, 4, 55, 48), 'signal.signal', 'signal.signal', ({(55, 18, 55, 31): 'signal.SIGINT', (55, 33, 55, 47): 'signal.SIG_DFL'}, {}), '(signal.SIGINT, signal.SIG_DFL)', False, 'import signal\n'), ((56, 4, 56, 35), 'lib.connection.establish', 'Connection.establish', ({(56, 25, 56, 34): 'Args.host'}, {}), '(Args.host)', True, 'import lib.connection as Connection\n'), ((57, 4, 57, 37), 'lib.connection.enterNonblockingMode', 'Connection.enterNonblockingMode', ({}, {}), '()', True, 'import lib.connection as Connection\n'), ((58, 4, 58, 42), 'lib.connection.on', 'Connection.on', ({(58, 18, 58, 27): '"""message"""', (58, 29, 58, 41): 'testCallback'}, {}), "('message', testCallback)", True, 'import lib.connection as Connection\n'), ((59, 15, 59, 33), 'gi.repository.GObject.MainLoop', 'GObject.MainLoop', ({}, {}), '()', False, 'from gi.repository import GObject\n'), ((26, 19, 26, 51), 'logging.getLogger', 'logging.getLogger', ({(26, 37, 26, 50): '"""Voctoconfig"""'}, {}), "('Voctoconfig')", False, 'import logging\n'), ((28, 24, 28, 42), 'gi.repository.GObject.MainLoop', 'GObject.MainLoop', ({}, {}), '()', False, 'from gi.repository import GObject\n'), ((62, 8, 62, 34), 'logging.debug', 'logging.debug', ({(62, 22, 62, 33): '"""mimimi..."""'}, {}), "('mimimi...')", False, 'import logging\n'), ((63, 8, 63, 43), 'lib.connection.send', 'Connection.send', ({(63, 24, 63, 33): '"""message"""', (63, 35, 63, 42): '"""test2"""'}, {}), "('message', 'test2')", True, 'import lib.connection as Connection\n'), ((64, 8, 64, 22), 'time.sleep', 'time.sleep', ({(64, 19, 64, 21): '(10)'}, {}), '(10)', False, 'import time\n'), ((43, 43, 43, 62), 'sys.stderr.isatty', 'sys.stderr.isatty', ({}, {}), '()', False, 'import sys\n')]