コード例 #1
0
ファイル: server.py プロジェクト: BigRep/OctoPrint
def run_server(basedir, configfile, host, port, debug, allow_root, logging_config, verbosity, safe_mode, octoprint_daemon=None):
	"""Initializes the environment and starts up the server."""

	from octoprint import init_platform, __display_version__, FatalStartupError

	def log_startup(recorder=None, safe_mode=None, **kwargs):
		logger = logging.getLogger("octoprint.server")
		logger.info("Starting OctoPrint {}".format(__display_version__))
		if safe_mode:
			logger.info("Starting in SAFE MODE. Third party plugins will be disabled!")

		if recorder and len(recorder):
			logger.info("--- Logged during platform initialization: ---")

			from octoprint.logging.handlers import CombinedLogHandler
			handler = CombinedLogHandler(*logging.getLogger().handlers)
			recorder.setTarget(handler)
			recorder.flush()

			logger.info("----------------------------------------------")

		from octoprint import urllib3_ssl
		if not urllib3_ssl:
			logging.getLogger("octoprint.server")\
				.warn("requests/urllib3 will run in an insecure SSL environment. "
			          "You might see corresponding warnings logged later "
			          "(\"InsecurePlatformWarning\"). It is recommended to either "
			          "update to a Python version >= 2.7.9 or alternatively "
			          "install PyOpenSSL plus its dependencies. For details see "
			          "https://urllib3.readthedocs.org/en/latest/security.html#openssl-pyopenssl")

	try:
		settings, _, safe_mode, plugin_manager = init_platform(basedir,
		                                                       configfile,
		                                                       logging_file=logging_config,
		                                                       debug=debug,
		                                                       verbosity=verbosity,
		                                                       uncaught_logger=__name__,
		                                                       safe_mode=safe_mode,
		                                                       after_safe_mode=log_startup)
	except FatalStartupError as e:
		click.echo(e.message, err=True)
		click.echo("There was a fatal error starting up OctoPrint.", err=True)
	else:
		from octoprint.server import Server
		octoprint_server = Server(settings=settings,
		                          plugin_manager=plugin_manager,
		                          host=host,
		                          port=port,
		                          debug=debug,
		                          safe_mode=safe_mode,
		                          allow_root=allow_root,
		                          octoprint_daemon=octoprint_daemon)
		octoprint_server.run()
コード例 #2
0
ファイル: server.py プロジェクト: FracktalWorks/fw-OctoPrint
def run_server(basedir,
               configfile,
               host,
               port,
               v6_only,
               debug,
               allow_root,
               logging_config,
               verbosity,
               safe_mode,
               ignore_blacklist,
               octoprint_daemon=None):
    """Initializes the environment and starts up the server."""

    from octoprint import init_platform, __display_version__, FatalStartupError

    def log_startup(recorder=None, safe_mode=None, **kwargs):
        from octoprint.logging import get_divider_line

        logger = logging.getLogger("octoprint.startup")

        logger.info(get_divider_line("*"))
        logger.info("Starting fw-OctoPrint {}".format(__display_version__))
        if safe_mode:
            logger.info(
                "Starting in SAFE MODE. Third party plugins will be disabled!")
            if safe_mode == "flag":
                reason = "command line flag"
            elif safe_mode == "settings":
                reason = "setting in config.yaml"
            elif safe_mode == "incomplete_startup":
                reason = "problem during last startup"
            else:
                reason = "unknown"
            logger.info("Reason for safe mode: {}".format(reason))

        if recorder and len(recorder):
            logger.info(
                get_divider_line("-",
                                 "Logged during platform initialization:"))

            from octoprint.logging.handlers import CombinedLogHandler
            handler = CombinedLogHandler(*logging.getLogger().handlers)
            recorder.setTarget(handler)
            recorder.flush()

            logger.info(get_divider_line("-"))

        from octoprint import urllib3_ssl
        if not urllib3_ssl:
            logging.getLogger("octoprint.server")\
             .warn("requests/urllib3 will run in an insecure SSL environment. "
                      "You might see corresponding warnings logged later "
                      "(\"InsecurePlatformWarning\"). It is recommended to either "
                      "update to a Python version >= 2.7.9 or alternatively "
                      "install PyOpenSSL plus its dependencies. For details see "
                      "https://urllib3.readthedocs.org/en/latest/security.html#openssl-pyopenssl")
        logger.info(get_divider_line("*"))

    def log_register_rollover(safe_mode=None,
                              plugin_manager=None,
                              environment_detector=None,
                              **kwargs):
        from octoprint.logging import get_handler, log_to_handler, get_divider_line
        from octoprint.logging.handlers import OctoPrintLogHandler

        def rollover_callback():
            handler = get_handler("file")
            if handler is None:
                return

            logger = logging.getLogger("octoprint.server")

            def _log(message, level=logging.INFO):
                log_to_handler(logger, handler, level, message)

            _log(get_divider_line("-", "Log roll over detected"))
            _log("OctoPrint {}".format(__display_version__))
            if safe_mode:
                _log("SAFE MODE is active. Third party plugins are disabled!")
            plugin_manager.log_all_plugins(only_to_handler=handler)
            environment_detector.log_detected_environment(
                only_to_handler=handler)
            _log(get_divider_line("-"))

        OctoPrintLogHandler.registerRolloverCallback(rollover_callback)

    try:
        components = init_platform(
            basedir,
            configfile,
            logging_file=logging_config,
            debug=debug,
            verbosity=verbosity,
            uncaught_logger=__name__,
            safe_mode=safe_mode,
            ignore_blacklist=ignore_blacklist,
            after_safe_mode=log_startup,
            after_environment_detector=log_register_rollover)
        settings, _, safe_mode, event_manager, connectivity_checker, plugin_manager, environment_detector = components

    except FatalStartupError as e:
        logger = logging.getLogger("octoprint.startup").fatal
        echo = lambda x: click.echo(x, err=True)

        for method in logger, echo:
            method(str(e))
            method("There was a fatal error starting up OctoPrint.")

    else:
        from octoprint.server import Server
        octoprint_server = Server(settings=settings,
                                  plugin_manager=plugin_manager,
                                  event_manager=event_manager,
                                  connectivity_checker=connectivity_checker,
                                  environment_detector=environment_detector,
                                  host=host,
                                  port=port,
                                  v6_only=v6_only,
                                  debug=debug,
                                  safe_mode=safe_mode,
                                  allow_root=allow_root,
                                  octoprint_daemon=octoprint_daemon)
        octoprint_server.run()
コード例 #3
0
ファイル: __init__.py プロジェクト: tinkercnc/OctoPrint
def init_platform_for_cli(ctx):
    """
    Performs a basic platform initialization for the CLI.

    Plugin implementations will be initialized, but only with a subset of the usual
    property injections:

       * _identifier and everything else parsed from metadata
       * _logger
       * _connectivity_checker
       * _environment_detector
       * _event_bus
       * _plugin_manager
       * _settings

    Returns: the same list of components as returned by ``init_platform``
    """

    from octoprint import (
        init_custom_events,
        init_platform,
        init_settings_plugin_config_migration_and_cleanup,
    )
    from octoprint import octoprint_plugin_inject_factory as opif
    from octoprint import settings_plugin_inject_factory as spif

    components = init_platform(
        get_ctx_obj_option(ctx, "basedir", None),
        get_ctx_obj_option(ctx, "configfile", None),
        overlays=get_ctx_obj_option(ctx, "overlays", None),
        safe_mode=True,
        disable_color=get_ctx_obj_option(ctx, "no_color", False),
    )

    (
        settings,
        logger,
        safe_mode,
        event_manager,
        connectivity_checker,
        plugin_manager,
        environment_detector,
    ) = components

    init_custom_events(plugin_manager)
    octoprint_plugin_inject_factory = opif(
        settings,
        {
            "plugin_manager": plugin_manager,
            "event_bus": event_manager,
            "connectivity_checker": connectivity_checker,
            "environment_detector": environment_detector,
        },
    )
    settings_plugin_inject_factory = spif(settings)

    plugin_manager.implementation_inject_factories = [
        octoprint_plugin_inject_factory,
        settings_plugin_inject_factory,
    ]
    plugin_manager.initialize_implementations()

    init_settings_plugin_config_migration_and_cleanup(plugin_manager)

    return components
コード例 #4
0
def run_server(basedir,
               configfile,
               host,
               port,
               debug,
               allow_root,
               logging_config,
               verbosity,
               safe_mode,
               octoprint_daemon=None):
    """Initializes the environment and starts up the server."""

    from octoprint import init_platform, __display_version__, FatalStartupError

    def log_startup(recorder=None, safe_mode=None, **kwargs):
        logger = logging.getLogger("octoprint.server")
        logger.info("Starting OctoPrint {}".format(__display_version__))
        if safe_mode:
            logger.info(
                "Starting in SAFE MODE. Third party plugins will be disabled!")

        if recorder and len(recorder):
            logger.info("--- Logged during platform initialization: ---")

            from octoprint.logging.handlers import CombinedLogHandler
            handler = CombinedLogHandler(*logging.getLogger().handlers)
            recorder.setTarget(handler)
            recorder.flush()

            logger.info("----------------------------------------------")

        from octoprint import urllib3_ssl
        if not urllib3_ssl:
            logging.getLogger("octoprint.server")\
             .warn("requests/urllib3 will run in an insecure SSL environment. "
                      "You might see corresponding warnings logged later "
                      "(\"InsecurePlatformWarning\"). It is recommended to either "
                      "update to a Python version >= 2.7.9 or alternatively "
                      "install PyOpenSSL plus its dependencies. For details see "
                      "https://urllib3.readthedocs.org/en/latest/security.html#openssl-pyopenssl")

    try:
        settings, _, safe_mode, plugin_manager = init_platform(
            basedir,
            configfile,
            logging_file=logging_config,
            debug=debug,
            verbosity=verbosity,
            uncaught_logger=__name__,
            safe_mode=safe_mode,
            after_safe_mode=log_startup)
    except FatalStartupError as e:
        click.echo(e.message, err=True)
        click.echo("There was a fatal error starting up OctoPrint.", err=True)
    else:
        from octoprint.server import Server
        octoprint_server = Server(settings=settings,
                                  plugin_manager=plugin_manager,
                                  host=host,
                                  port=port,
                                  debug=debug,
                                  safe_mode=safe_mode,
                                  allow_root=allow_root,
                                  octoprint_daemon=octoprint_daemon)
        octoprint_server.run()
コード例 #5
0
ファイル: server.py プロジェクト: ByReaL/OctoPrint
def run_server(basedir, configfile, host, port, debug, allow_root, logging_config, verbosity, safe_mode,
               ignore_blacklist, octoprint_daemon=None):
	"""Initializes the environment and starts up the server."""

	from octoprint import init_platform, __display_version__, FatalStartupError

	def log_startup(recorder=None, safe_mode=None, **kwargs):
		from octoprint.logging import get_divider_line

		logger = logging.getLogger("octoprint.startup")

		logger.info(get_divider_line("*"))
		logger.info("Starting OctoPrint {}".format(__display_version__))
		if safe_mode:
			logger.info("Starting in SAFE MODE. Third party plugins will be disabled!")

		if recorder and len(recorder):
			logger.info(get_divider_line("-", "Logged during platform initialization:"))

			from octoprint.logging.handlers import CombinedLogHandler
			handler = CombinedLogHandler(*logging.getLogger().handlers)
			recorder.setTarget(handler)
			recorder.flush()

			logger.info(get_divider_line("-"))

		from octoprint import urllib3_ssl
		if not urllib3_ssl:
			logging.getLogger("octoprint.server")\
				.warn("requests/urllib3 will run in an insecure SSL environment. "
			          "You might see corresponding warnings logged later "
			          "(\"InsecurePlatformWarning\"). It is recommended to either "
			          "update to a Python version >= 2.7.9 or alternatively "
			          "install PyOpenSSL plus its dependencies. For details see "
			          "https://urllib3.readthedocs.org/en/latest/security.html#openssl-pyopenssl")
		logger.info(get_divider_line("*"))

	def log_register_rollover(safe_mode=None, plugin_manager=None, environment_detector=None, **kwargs):
		from octoprint.logging import get_handler, log_to_handler, get_divider_line
		from octoprint.logging.handlers import OctoPrintLogHandler

		def rollover_callback():
			handler = get_handler("file")
			if handler is None:
				return

			logger = logging.getLogger("octoprint.server")

			def _log(message, level=logging.INFO):
				log_to_handler(logger, handler, level, message)

			_log(get_divider_line("-", "Log roll over detected"))
			_log("OctoPrint {}".format(__display_version__))
			if safe_mode:
				_log("SAFE MODE is active. Third party plugins are disabled!")
			plugin_manager.log_all_plugins(only_to_handler=handler)
			environment_detector.log_detected_environment(only_to_handler=handler)
			_log(get_divider_line("-"))

		OctoPrintLogHandler.registerRolloverCallback(rollover_callback)

	try:
		components = init_platform(basedir, configfile,
		                           logging_file=logging_config,
		                           debug=debug,
		                           verbosity=verbosity,
		                           uncaught_logger=__name__,
		                           safe_mode=safe_mode,
                                   ignore_blacklist=ignore_blacklist,
		                           after_safe_mode=log_startup,
		                           after_environment_detector=log_register_rollover)

		settings, _, safe_mode, event_manager, connectivity_checker, plugin_manager, environment_detector = components

	except FatalStartupError as e:
		logger = logging.getLogger("octoprint.startup").fatal
		echo = lambda x: click.echo(x, err=True)

		for method in logger, echo:
			method(str(e))
			method("There was a fatal error starting up OctoPrint.")

	else:
		from octoprint.server import Server
		octoprint_server = Server(settings=settings,
		                          plugin_manager=plugin_manager,
		                          event_manager=event_manager,
		                          connectivity_checker=connectivity_checker,
		                          environment_detector=environment_detector,
		                          host=host,
		                          port=port,
		                          debug=debug,
		                          safe_mode=safe_mode,
		                          allow_root=allow_root,
		                          octoprint_daemon=octoprint_daemon)
		octoprint_server.run()