# Path: bitsd/common.py
# LOG = logging.getLogger('tornado.general')


import bitsd.properties
import bitsd.server as server
import bitsd.listener as listener
import bitsd.persistence as persistence
import tornado.ioloop
import signal
import time
import sys
import logging
from bitsd.common import LOG
from tornado.options import parse_command_line
from tornado.options import parse_config_file, options
from tornado.log import enable_pretty_logging




# Signal code adapted from https://gist.github.com/kachayev/1387470

def sig_handler(sig, frame):
    """Catch signal and init callback.

    Reference:
    http://codemehanika.org/blog/2011-10-28-graceful-stop-tornado.html
    """
    LOG.warning('Caught signal: %s', sig)
    tornado.ioloop.IOLoop.instance().add_callback(shutdown)


def shutdown():
    """Stop server and add callback to stop i/o loop."""
    io_loop = tornado.ioloop.IOLoop.instance()
    LOG.info('Shutting down in 2 seconds')
    io_loop.add_timeout(time.time() + 2, io_loop.stop)


def main():
    """Entry point for bitsd."""
    enable_pretty_logging()

    try:
        parse_config_file('/etc/bitsd.conf')
    except IOError:

# Path: bitsd/common.py
# LOG = logging.getLogger('tornado.general')


# Path: bitsd/main.py
import bitsd.properties
import bitsd.server as server
import bitsd.listener as listener
import bitsd.persistence as persistence
import tornado.ioloop
import signal
import time
import sys
import logging
from bitsd.common import LOG
from tornado.options import parse_command_line
from tornado.options import parse_config_file, options
from tornado.log import enable_pretty_logging





# Signal code adapted from https://gist.github.com/kachayev/1387470

def sig_handler(sig, frame):
    """Catch signal and init callback.

    Reference:
    http://codemehanika.org/blog/2011-10-28-graceful-stop-tornado.html
    """
    LOG.warning('Caught signal: %s', sig)
    tornado.ioloop.IOLoop.instance().add_callback(shutdown)


def shutdown():
    """Stop server and add callback to stop i/o loop."""
    io_loop = tornado.ioloop.IOLoop.instance()
    LOG.info('Shutting down in 2 seconds')
    io_loop.add_timeout(time.time() + 2, io_loop.stop)


def main():
    """Entry point for bitsd."""
    enable_pretty_logging()

    try:
        parse_config_file('/etc/bitsd.conf')
    except IOError:

        LOG.warning('Config file not found, using defaults and command line.')