def run_server(chatrooms, use_default_logging=True):
    """Sets up and serves specified chatrooms. Main entrypoint to Hermes.

    :param chatrooms: Dictionary of chatrooms to serve.
    :param use_default_logging: (optional) Boolean. Set to True if Hermes should setup its default logging configuration.
    """
    if use_default_logging:
        configure_logging()

    logger.info('Starting Hermes chatroom server...')

    bots = []
    for name, params in chatrooms.items():

        bot_class = params.get('CLASS', 'hermes.Chatroom')
        if type(bot_class) == type:
            pass
        else:
            bot_class_path = bot_class.split('.')
            if len(bot_class_path) == 1:
                module, classname = '__main__', bot_class_path[-1]
            else:
                module, classname = '.'.join(bot_class_path[:-1]), bot_class_path[-1]
            _ = __import__(module, globals(), locals(), [classname])
            bot_class = getattr(_, classname)
        bot = bot_class(name, params)
        bots.append(bot)

    while True:
        try:
            logger.info("Connecting to servers...")
            sockets = _get_sockets(bots)
            if len(sockets.keys()) == 0:
                logger.info('No chatrooms defined. Exiting.')
                return

            _listen(sockets)
        except socket.error, ex:
            if ex.errno == 9:
                logger.exception('broken socket detected')
            else:
                logger.exception('Unknown socket error %d' % (ex.errno,))
        except Exception:
            logger.exception('Unexpected exception')
            time.sleep(1)
def run_server ( chatrooms , use_default_logging = True ) : if use_default_logging : configure_logging ( ) logger . info ( 'Starting Hermes chatroom server...' ) bots = [ ] for name , params in chatrooms . items ( ) : bot_class = params . get ( 'CLASS' , 'hermes.Chatroom' ) if type ( bot_class ) == type : pass else : bot_class_path = bot_class . split ( '.' ) if len ( bot_class_path ) == 1 : module , classname = '__main__' , bot_class_path [ - 1 ] else : module , classname = '.' . join ( bot_class_path [ : - 1 ] ) , bot_class_path [ - 1 ] _ = __import__ ( module , globals ( ) , locals ( ) , [ classname ] ) bot_class = getattr ( _ , classname ) bot = bot_class ( name , params ) bots . append ( bot ) while True : try : logger . info ( "Connecting to servers..." ) sockets = _get_sockets ( bots ) if len ( sockets . keys ( ) ) == 0 : logger . info ( 'No chatrooms defined. Exiting.' ) return _listen ( sockets ) except socket . error , ex : if ex . errno == 9 : logger . exception ( 'broken socket detected' ) else : logger . exception ( 'Unknown socket error %d' % ( ex . errno , ) ) except Exception : logger . exception ( 'Unexpected exception' ) time . sleep ( 1 )
Sets up and serves specified chatrooms. Main entrypoint to Hermes.

    :param chatrooms: Dictionary of chatrooms to serve.
    :param use_default_logging: (optional) Boolean. Set to True if Hermes should setup its default logging configuration.