# coding=utf-8 from __future__ import absolute_import import octoprint.plugin from octoprint.util.pip import create_pip_caller class CleanupLoggingPlugin(octoprint.plugin.StartupPlugin): def on_after_startup(self): import pkg_resources try: pkg_resources.get_distribution("logging") except pkg_resources.DistributionNotFound: self._logger.info("logging not installed, skipping cleanup") return self._logger.info("Found PrintTimeGenius' logging left over, removing...") pip_caller = create_pip_caller() pip_code, pip_out, pip_err = pip_caller.execute("uninstall", "-y", "logging") self._logger.info("pip uninstall logging returned status code {}".format(pip_code)) self._logger.info("STDOUT:\n{}".format("\n".join(pip_out))) self._logger.warn("STDERR:\n{}".format("\n".join(pip_err))) if pip_code == 0: self._logger.info("logging successfully removed") else: self._logger.warn("logging could not be removed") __plugin_name__ = "Cleanup Logging Package" __plugin_author__ = "Gina Häußge" __plugin_homepage__ = "https://faq.octoprint.org/cannot-import-nullhandler" __plugin_description__ = "Cleans up an errant logging module installed by older versions of PrintTimeGenius and wreaking havoc among OctoPrint installs in the field." __plugin_license__ = "AGPLv3" __plugin_pythoncompat__ = ">=2.7,<3" __plugin_implementation__ = CleanupLoggingPlugin()