def __init__(self, configuration=""):
        super(PeoplePoker, self).__init__()

        # TODO Push logging setup into a config file
        self.logger = logging.getLogger()
        self.logger.setLevel(logging.DEBUG)

        formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')

        console_handler = logging.StreamHandler()

        console_handler.setLevel(logging.DEBUG)
        console_handler.setFormatter(formatter)

        self.logger.addHandler(console_handler)

        self.logger.info("Starting up at %s..." % dt.now())

        # Get all of the provider classes and instantiate them
        self.providers = self.get_providers()
        self.provider_instances = self.get_provider_instances()

        self.logger.info("Providers: " + pformat([(type, \
                [provider.__name__ for provider in providers]) \
                for type, providers in self.providers.iteritems()]))

        self.logger.info("Instances: " + pformat([(type, \
                [provider.__class__.__name__ for provider in providers]) \
                for type, providers in self.provider_instances.iteritems()]))

        parser = ConfigObj('config.ini')

        # Initialize the database connection
        self.session = create_db_session(parser["database%s" % configuration])

        # Start any server providers (like the ZMQ server provider)
        for provider in self.provider_instances['server']:
            self.logger.info("Starting server for %s" % provider)

            self.threads.append(provider)

        for thread in self.threads:
            thread.start()
Example #2
0
# XXX
sys.path.append(os.path.abspath('..'))

from bottle import route, run, request, response, abort
from datetime import datetime as dt
from configobj import ConfigObj
from sqlalchemy import and_
from sqlalchemy.orm.exc import MultipleResultsFound, NoResultFound

from spp.models import ModelEncoder, Status, User
from spp.utilities import create_db_session

parser = ConfigObj('config.ini')

# Initialize the database connection
session = create_db_session(parser["database"])


def json_or_jsonp(o, request, response):
    """Return json or jsonp depending on the request"""
    output = json.dumps(o, cls=ModelEncoder)

    if 'callback' in request.GET:
        response.set_content_type('text/javascript')

        output = "%s(%s)" % (request.GET['callback'], output)
    else:
        response.set_content_type('application/json')

    return output