コード例 #1
0
ファイル: main.py プロジェクト: agile/sevabot
def main(settings="settings.py", verbose=False, daemon=False):
    """
    Application entry point.
    """

    # Expose settings global module
    try:
        settings = imp.load_source("settings", settings)
    except Exception:
        sys.exit("Could not load settings file: %s" % settings)

    # Config logging
    level = getattr(logging, getattr(settings, "LOG_LEVEL", "INFO"), "INFO")
    logging.basicConfig(level=level, stream=sys.stdout, format=settings.LOG_FORMAT)

    # Setup logging file
    if getattr(settings, "LOG_FILE", None):
        if not settings.LOG_FILE.startswith("/"):
            log_path = settings.LOG_FILE
        else:
            log_path = os.path.join(os.path.dirname(settings.__file__), settings.LOG_FILE)

        formatter = logging.Formatter(settings.LOG_FORMAT)

        hdlr = logging.handlers.RotatingFileHandler(log_path,
            encoding="utf-8",
            maxBytes=settings.LOG_ROTATE_MAX_SIZE,
            backupCount=settings.LOG_ROTATE_COUNT)

        hdlr.setFormatter(formatter)

        logger.addHandler(hdlr)

    logger.info("Starting sevabot")

    for skype_logger_name in ["Skype4Py.utils.EventHandlingBase", "Skype4Py.skype.Skype",
                              "Skype4Py.api.darwin.SkypeAPI"]:
        skype_logger = logging.getLogger(skype_logger_name)
        skype_logger.setLevel(logging.WARN)

    # Detach from the controlling terminal
    if daemon:
        create_daemon()

    from sevabot.bot import modules

    modules.load_modules()

    sevabot = get_bot()

    logger.info("Skype API connection established")

    sevabot.start()

    api.configure(sevabot, settings, server)

    server.run(settings.HTTP_HOST, settings.HTTP_PORT, debug=False)

    # Should be never reached
    return 0
コード例 #2
0
ファイル: main.py プロジェクト: benh57/sevabot
def main(settings="settings.py", verbose=False):
    """
    Application entry point.
    """

    # Expose settings global module
    try:
        settings = imp.load_source("settings", settings)
    except Exception:
        sys.exit("Could not load settings file: %s" % settings)

    # Config logging
    level = verbose if logging.DEBUG else logging.INFO
    logging.basicConfig(level=level, stream=sys.stdout, format=LOG_FORMAT)
    logger.info("Starting sevabot")

    for skype_logger_name in ["Skype4Py.utils.EventHandlingBase", "Skype4Py.skype.Skype",
                              "Skype4Py.api.darwin.SkypeAPI"]:
        skype_logger = logging.getLogger(skype_logger_name)
        skype_logger.setLevel(logging.WARN)

    from sevabot.bot import modules

    modules.load_modules()

    sevabot = get_bot()

    logger.info("Skype API connection established")

    sevabot.start()

    api.configure(sevabot, settings, server)

    server.run(settings.HTTP_HOST, settings.HTTP_PORT, debug=False)

    # Should be never reached
    return 0
コード例 #3
0
def main(settings="settings.py", verbose=False, daemon=False):
    """
    Application entry point.
    """

    # Expose settings global module
    try:
        settings = imp.load_source("settings", settings)
    except Exception:
        sys.exit("Could not load settings file: %s" % settings)

    # Config logging

    level = getattr(logging,
                    getattr(settings, "LOG_LEVEL", "INFO").upper(), "INFO")

    logging.basicConfig(level=level,
                        stream=sys.stdout,
                        format=settings.LOG_FORMAT)

    # Setup logging file
    if getattr(settings, "LOG_FILE", None):
        if not settings.LOG_FILE.startswith("/"):
            log_path = settings.LOG_FILE
        else:
            log_path = os.path.join(os.path.dirname(settings.__file__),
                                    settings.LOG_FILE)

        formatter = logging.Formatter(settings.LOG_FORMAT)

        hdlr = logging.handlers.RotatingFileHandler(
            log_path,
            encoding="utf-8",
            maxBytes=settings.LOG_ROTATE_MAX_SIZE,
            backupCount=settings.LOG_ROTATE_COUNT)

        hdlr.setFormatter(formatter)

        logger.addHandler(hdlr)

    logger.info("Starting sevabot")

    for skype_logger_name in [
            "Skype4Py.utils.EventHandlingBase", "Skype4Py.skype.Skype",
            "Skype4Py.api.darwin.SkypeAPI"
    ]:
        skype_logger = logging.getLogger(skype_logger_name)
        skype_logger.setLevel(logging.WARN)

    # Detach from the controlling terminal
    if daemon:
        create_daemon()

    from sevabot.bot import modules

    sevabot = get_bot()

    logger.info("Skype API connection established")

    sevabot.start()

    modules.load_modules(sevabot)

    api.configure(sevabot, settings, server)

    server.run(settings.HTTP_HOST, settings.HTTP_PORT, debug=False)

    # Should be never reached
    return 0