def _detect_python(self): result = dict(version="unknown", pip="unknown") # determine python version try: result["version"] = get_python_version_string() except Exception: self._logger.exception("Error detecting python version") # determine if we are running from a virtual environment try: if hasattr(sys, "real_prefix") or (hasattr(sys, "base_prefix") and os.path.realpath(sys.prefix) != os.path.realpath(sys.base_prefix)): result["virtualenv"] = sys.prefix except Exception: self._logger.exception( "Error detecting whether we are running in a virtual environment" ) # try to find pip version try: import pkg_resources result["pip"] = pkg_resources.get_distribution("pip").version except Exception: self._logger.exception("Error detecting pip version") return result
def on_open(self, info): self._pluginManager.register_message_receiver(self.on_plugin_message) self._remoteAddress = self._get_remote_address(info) self._logger.info("New connection from client: %s" % self._remoteAddress) self._userManager.register_login_status_listener(self) self._groupManager.register_listener(self) plugin_signature = lambda impl: "{}:{}".format( impl._identifier, impl._plugin_version ) template_plugins = list( map( plugin_signature, self._pluginManager.get_implementations(octoprint.plugin.TemplatePlugin), ) ) asset_plugins = list( map( plugin_signature, self._pluginManager.get_implementations(octoprint.plugin.AssetPlugin), ) ) ui_plugins = sorted(set(template_plugins + asset_plugins)) import hashlib plugin_hash = hashlib.md5() plugin_hash.update(",".join(ui_plugins).encode("utf-8")) config_hash = settings().config_hash # connected => update the API key, might be necessary if the client was left open while the server restarted self._emit( "connected", { "version": octoprint.server.VERSION, "display_version": octoprint.server.DISPLAY_VERSION, "branch": octoprint.server.BRANCH, "python_version": get_python_version_string(), "plugin_hash": plugin_hash.hexdigest(), "config_hash": config_hash, "debug": octoprint.server.debug, "safe_mode": octoprint.server.safe_mode, "online": self._connectivityChecker.online, "permissions": [permission.as_dict() for permission in Permissions.all()], }, ) self._eventManager.fire( Events.CLIENT_OPENED, {"remoteAddress": self._remoteAddress} ) self._register()
def _check_environment(self): import pkg_resources local_pip = LocalPipCaller() # check python and setuptools version versions = dict(python=get_python_version_string(), setuptools=pkg_resources.get_distribution("setuptools").version, pip=local_pip.version_string) supported = get_comparable_version(versions["python"]) >= get_comparable_version(MINIMUM_PYTHON) \ and get_comparable_version(versions["setuptools"]) >= get_comparable_version(MINIMUM_SETUPTOOLS) \ and get_comparable_version(versions["pip"]) >= get_comparable_version(MINIMUM_PIP) self._environment_supported = supported self._environment_versions = versions self._environment_ready.set()