def get_settings(configuration):
    """
    Retrieves the location of the config.ini file for the standalone apps. It will first look at the
    command line arguments. If the file specified on the command line doesn't exist, an error will
    be thrown. Then the SGTK_BROWSER_INTEGRATION_CONFIG_LOCATION environment variable will be evaluated.
    If the value points to a non existing path, an error will be thrown. Then the config.ini
    file in the current folder will be parsed. If the file is missing, a settings object with only
    default settings will be returned.

    :param configuration: Path to the configuration path. Can be None.

    :returns: The location where to read the configuration file from.

    :raises MissingConfigurationFileError: Raised when the user supplied configuration file
        doesn't exist on disk.
    """

    # First check the command line.
    if configuration is not None:
        location = configuration
    # Then check the environment variable.
    elif "SGTK_BROWSER_INTEGRATION_CONFIG_LOCATION" in os.environ:
        location = os.environ["SGTK_BROWSER_INTEGRATION_CONFIG_LOCATION"]
    else:
        # Nothing has been found!
        location = None

    # If the user specified a location and it doesn't exist, raise an error.
    if location and not os.path.exists(location):
        raise MissingConfigurationFileError(location)

    # Create an absolute path to the file.
    app_dir = os.path.abspath(os.path.dirname(__file__))

    # If no location was specified, simply read from the local directory.
    if location is None:
        location = os.path.join(app_dir, "config.ini")

    get_logger("settings").debug("Using configuration file at '%s'" % location)
    return Settings(
        location,
        # Go back up a folder to retrieve the root of the package and drill
        # into the resource files to look for the keys
        os.path.join(
            os.path.dirname(app_dir),
            "resources", "keys"
        )
    )
Esempio n. 2
0
def __init_websockets(splash, app_bootstrap, settings):
    """
    Initializes the local websocket server.

    :pram splash: Splash widget.
    :param app_bootstrap: The application bootstrap instance.
    :param settings: The application's settings.

    :returns: The tk_framework_desktopserver.Server instance and a boolean indicating if the
        Desktop should keep launching.
    """
    if not __is_64bit_python():
        # Do not import if Python is not 64-bits
        logger.warning("Interpreter is not 64-bits, can't load desktop server")
        return None, True

    if not settings.integration_enabled:
        # Do not import if server is disabled.
        logger.info("Integration was disabled in config.ini.")
        return None, True

    # First try to import the framework. If it fails, let the user decide if the Desktop should
    # keep launching.
    try:
        splash.show()
        splash.set_message("Initializing browser integration")
        # Import framework
        import tk_framework_desktopserver
        app_bootstrap.add_logger_to_logfile(
            tk_framework_desktopserver.get_logger())
    except Exception, e:
        return None, __handle_unexpected_exception_during_websocket_init(
            splash, app_bootstrap, e)
def __init_websockets(splash, app_bootstrap, settings):
    """
    Initializes the local websocket server.

    :pram splash: Splash widget.
    :param app_bootstrap: The application bootstrap instance.
    :param settings: The application's settings.

    :returns: The tk_framework_desktopserver.Server instance and a boolean indicating if the
        Desktop should keep launching.
    """
    if not __is_64bit_python():
        # Do not import if Python is not 64-bits
        logger.warning("Interpreter is not 64-bits, can't load desktop server")
        return None, True

    if not settings.integration_enabled:
        # Do not import if server is disabled.
        logger.info("Integration was disabled in config.ini.")
        return None, True

    # First try to import the framework. If it fails, let the user decide if the Desktop should
    # keep launching.
    try:
        splash.show()
        splash.set_message("Initializing browser integration")
        # Import framework
        import tk_framework_desktopserver
        app_bootstrap.add_logger_to_logfile(tk_framework_desktopserver.get_logger())
    except Exception, e:
        return None, __handle_unexpected_exception_during_websocket_init(splash, app_bootstrap, e)
def get_logger(debug):
    """
    Configures the logging for the app.

    :param debug: True if debug is needed, False otherwise.

    :returns: The root logger for the app.
    """
    # Make sure logger output goes to stdout
    logger = tk_framework_desktopserver.get_logger()
    handler = logging.StreamHandler()
    formatter = logging.Formatter('%(asctime)s [%(name)s.%(levelname)s] %(message)s')
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    if debug:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    return logger
def get_logger(debug):
    """
    Configures the logging for the app.

    :param debug: True if debug is needed, False otherwise.

    :returns: The root logger for the app.
    """
    # Make sure logger output goes to stdout
    logger = tk_framework_desktopserver.get_logger()
    handler = logging.StreamHandler()
    formatter = logging.Formatter(
        '%(asctime)s [%(name)s.%(levelname)s] %(message)s')
    handler.setFormatter(formatter)
    logger.addHandler(handler)

    if debug:
        logger.setLevel(logging.DEBUG)
    else:
        logger.setLevel(logging.INFO)

    return logger