Merge branch 'maintenance' of https://github.com/OctoPrint/OctoPrint into improve/pluginmanager_ui
This commit is contained in:
commit
07c4b17260
12 files changed
+125
-23
No files matched your search
@@ -8,6 +8,7 @@ on:
|
||||
jobs:
|
||||
trigger:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'OctoPrint/OctoPrint'
|
||||
steps:
|
||||
- name: 🚀 Repository Dispatch
|
||||
uses: peter-evans/repository-dispatch@v1
|
||||
|
||||
@@ -9,6 +9,7 @@ on:
|
||||
jobs:
|
||||
trigger:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'OctoPrint/OctoPrint'
|
||||
steps:
|
||||
- name: 🚀 Repository Dispatch
|
||||
uses: peter-evans/repository-dispatch@v1
|
||||
|
||||
@@ -86,6 +86,7 @@ class FatalStartupError(Exception):
|
||||
def init_platform(
|
||||
basedir,
|
||||
configfile,
|
||||
overlays=None,
|
||||
use_logging_file=True,
|
||||
logging_file=None,
|
||||
logging_config=None,
|
||||
@@ -117,7 +118,7 @@ def init_platform(
|
||||
after_preinit_logging(**kwargs)
|
||||
|
||||
try:
|
||||
settings = init_settings(basedir, configfile)
|
||||
settings = init_settings(basedir, configfile, overlays=overlays)
|
||||
except Exception as ex:
|
||||
raise FatalStartupError("Could not initialize settings manager", cause=ex)
|
||||
kwargs["settings"] = settings
|
||||
@@ -220,13 +221,15 @@ def init_platform(
|
||||
)
|
||||
|
||||
|
||||
def init_settings(basedir, configfile):
|
||||
def init_settings(basedir, configfile, overlays=None):
|
||||
"""Inits the settings instance based on basedir and configfile to use."""
|
||||
|
||||
from octoprint.settings import InvalidSettings, settings
|
||||
|
||||
try:
|
||||
return settings(init=True, basedir=basedir, configfile=configfile)
|
||||
return settings(
|
||||
init=True, basedir=basedir, configfile=configfile, overlays=overlays
|
||||
)
|
||||
except InvalidSettings as e:
|
||||
raise FatalStartupError(str(e))
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ def init_platform_for_cli(ctx):
|
||||
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,
|
||||
)
|
||||
|
||||
@@ -180,8 +181,7 @@ def standard_options(hidden=False):
|
||||
"""
|
||||
Decorator to add the standard options shared among all "octoprint" commands.
|
||||
|
||||
Adds the options ``--basedir``, ``--config`` and ``--verbose``. If ``hidden``
|
||||
is set to ``True``, the options will be available on the command but not
|
||||
If ``hidden`` is set to ``True``, the options will be available on the command but not
|
||||
listed in its help page.
|
||||
"""
|
||||
|
||||
@@ -209,6 +209,16 @@ def standard_options(hidden=False):
|
||||
expose_value=False,
|
||||
help="Specify the config file to use.",
|
||||
),
|
||||
factory(
|
||||
"--overlay",
|
||||
"overlays",
|
||||
type=click.Path(),
|
||||
callback=set_ctx_obj_option,
|
||||
is_eager=True,
|
||||
multiple=True,
|
||||
expose_value=False,
|
||||
help="Specify additional config overlays to use.",
|
||||
),
|
||||
factory(
|
||||
"--verbose",
|
||||
"-v",
|
||||
|
||||
@@ -65,6 +65,7 @@ def config(ctx):
|
||||
ctx.obj.settings = init_settings(
|
||||
get_ctx_obj_option(ctx, "basedir", None),
|
||||
get_ctx_obj_option(ctx, "configfile", None),
|
||||
overlays=get_ctx_obj_option(ctx, "overlays", None),
|
||||
)
|
||||
except FatalStartupError as e:
|
||||
click.echo(str(e), err=True)
|
||||
|
||||
@@ -84,6 +84,7 @@ class OctoPrintPluginCommands(click.MultiCommand):
|
||||
self.settings = init_settings(
|
||||
get_ctx_obj_option(ctx, "basedir", None),
|
||||
get_ctx_obj_option(ctx, "configfile", None),
|
||||
overlays=get_ctx_obj_option(ctx, "overlays", None),
|
||||
)
|
||||
self.plugin_manager = init_pluginsystem(
|
||||
self.settings, safe_mode=get_ctx_obj_option(ctx, "safe_mode", False)
|
||||
|
||||
@@ -33,6 +33,7 @@ def run_server(
|
||||
safe_mode,
|
||||
ignore_blacklist,
|
||||
octoprint_daemon=None,
|
||||
overlays=None,
|
||||
):
|
||||
"""Initializes the environment and starts up the server."""
|
||||
|
||||
@@ -113,6 +114,7 @@ def run_server(
|
||||
components = init_platform(
|
||||
basedir,
|
||||
configfile,
|
||||
overlays=overlays,
|
||||
logging_file=logging_config,
|
||||
debug=debug,
|
||||
verbosity=verbosity,
|
||||
@@ -260,6 +262,7 @@ def enable_safemode(ctx, **kwargs):
|
||||
settings = init_settings(
|
||||
get_ctx_obj_option(ctx, "basedir", None),
|
||||
get_ctx_obj_option(ctx, "configfile", None),
|
||||
overlays=get_ctx_obj_option(ctx, "overlays", None),
|
||||
)
|
||||
except FatalStartupError as e:
|
||||
click.echo(str(e), err=True)
|
||||
@@ -297,6 +300,7 @@ def serve_command(ctx, **kwargs):
|
||||
verbosity = get_value("verbosity")
|
||||
safe_mode = "flag" if get_value("safe_mode") else None
|
||||
ignore_blacklist = get_value("ignore_blacklist")
|
||||
overlays = get_value("overlays")
|
||||
|
||||
if v4 and not host:
|
||||
host = "0.0.0.0"
|
||||
@@ -313,6 +317,7 @@ def serve_command(ctx, **kwargs):
|
||||
verbosity,
|
||||
safe_mode,
|
||||
ignore_blacklist,
|
||||
overlays=overlays,
|
||||
)
|
||||
|
||||
|
||||
@@ -350,6 +355,7 @@ if sys.platform != "win32" and sys.platform != "darwin":
|
||||
|
||||
basedir = get_value("basedir")
|
||||
configfile = get_value("configfile")
|
||||
overlays = get_value("overlays")
|
||||
verbosity = get_value("verbosity")
|
||||
safe_mode = "flag" if get_value("safe_mode") else None
|
||||
ignore_blacklist = get_value("ignore_blacklist")
|
||||
@@ -369,6 +375,7 @@ if sys.platform != "win32" and sys.platform != "darwin":
|
||||
pidfile,
|
||||
basedir,
|
||||
configfile,
|
||||
overlays,
|
||||
host,
|
||||
port,
|
||||
v6_only,
|
||||
@@ -383,6 +390,7 @@ if sys.platform != "win32" and sys.platform != "darwin":
|
||||
|
||||
self._basedir = basedir
|
||||
self._configfile = configfile
|
||||
self._overlays = overlays
|
||||
self._host = host
|
||||
self._port = port
|
||||
self._v6_only = v6_only
|
||||
@@ -407,12 +415,14 @@ if sys.platform != "win32" and sys.platform != "darwin":
|
||||
self._safe_mode,
|
||||
self._ignore_blacklist,
|
||||
octoprint_daemon=self,
|
||||
overlays=self._overlays,
|
||||
)
|
||||
|
||||
octoprint_daemon = OctoPrintDaemon(
|
||||
pid,
|
||||
basedir,
|
||||
configfile,
|
||||
overlays,
|
||||
host,
|
||||
port,
|
||||
v6,
|
||||
|
||||
@@ -48,6 +48,7 @@ def user(ctx):
|
||||
settings = init_settings(
|
||||
get_ctx_obj_option(ctx, "basedir", None),
|
||||
get_ctx_obj_option(ctx, "configfile", None),
|
||||
overlays=get_ctx_obj_option(ctx, "overlays", None),
|
||||
)
|
||||
|
||||
group_manager_name = settings.get(["accessControl", "groupManager"])
|
||||
|
||||
@@ -8,7 +8,6 @@ import octoprint.plugin
|
||||
from octoprint.access import ADMIN_GROUP
|
||||
from octoprint.access.permissions import Permissions
|
||||
from octoprint.events import Events
|
||||
from octoprint.plugin.core import FolderOrigin
|
||||
from octoprint.server import NO_CONTENT
|
||||
from octoprint.server.util.flask import no_firstrun_access
|
||||
from octoprint.settings import default_settings
|
||||
@@ -980,22 +979,16 @@ class BackupPlugin(
|
||||
)
|
||||
|
||||
# add list of installed plugins
|
||||
plugins = []
|
||||
plugin_folder = settings.global_get_basefolder("plugins")
|
||||
for plugin in plugin_manager.plugins.values():
|
||||
if plugin.bundled or (
|
||||
isinstance(plugin.origin, FolderOrigin)
|
||||
and plugin.origin.folder == plugin_folder
|
||||
):
|
||||
# ignore anything bundled or from the plugins folder we already include in the backup
|
||||
continue
|
||||
|
||||
plugins.append(
|
||||
{"key": plugin.key, "name": plugin.name, "url": plugin.url}
|
||||
helpers = plugin_manager.get_helpers(
|
||||
"pluginmanager", "generate_plugins_json"
|
||||
)
|
||||
if helpers and "generate_plugins_json" in helpers:
|
||||
plugins = helpers["generate_plugins_json"](
|
||||
settings=settings, plugin_manager=plugin_manager
|
||||
)
|
||||
|
||||
if len(plugins):
|
||||
zip.writestr("plugin_list.json", json.dumps(plugins))
|
||||
if len(plugins):
|
||||
zip.writestr("plugin_list.json", json.dumps(plugins))
|
||||
|
||||
shutil.move(temporary_path, final_path)
|
||||
|
||||
|
||||
@@ -401,6 +401,22 @@ class PluginManagerPlugin(
|
||||
)
|
||||
)
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/export", methods=["GET"])
|
||||
@no_firstrun_access
|
||||
@Permissions.PLUGIN_PLUGINMANAGER_MANAGE.require(403)
|
||||
def export_plugin_list(self):
|
||||
import json
|
||||
|
||||
import flask
|
||||
|
||||
plugins = self.generate_plugins_json(self._settings, self._plugin_manager)
|
||||
|
||||
return flask.Response(
|
||||
json.dumps(plugins),
|
||||
mimetype="text/plain",
|
||||
headers={"Content-Disposition": 'attachment; filename="plugin_list.json"'},
|
||||
)
|
||||
|
||||
def is_blueprint_protected(self):
|
||||
return False
|
||||
|
||||
@@ -1755,6 +1771,24 @@ class PluginManagerPlugin(
|
||||
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def generate_plugins_json(
|
||||
settings, plugin_manager, ignore_bundled=True, ignore_plugins_folder=True
|
||||
):
|
||||
plugins = []
|
||||
plugin_folder = settings.getBaseFolder("plugins")
|
||||
for plugin in plugin_manager.plugins.values():
|
||||
if (ignore_bundled and plugin.bundled) or (
|
||||
ignore_plugins_folder
|
||||
and isinstance(plugin.origin, octoprint.plugin.core.FolderOrigin)
|
||||
and plugin.origin.folder == plugin_folder
|
||||
):
|
||||
# ignore bundled or from the plugins folder already included in the backup
|
||||
continue
|
||||
|
||||
plugins.append({"key": plugin.key, "name": plugin.name, "url": plugin.url})
|
||||
return plugins
|
||||
|
||||
def _to_external_plugin(self, plugin):
|
||||
return {
|
||||
"key": plugin.key,
|
||||
@@ -1898,3 +1932,8 @@ def __plugin_load__():
|
||||
"octoprint.events.register_custom_events": _register_custom_events,
|
||||
"octoprint.access.permissions": __plugin_implementation__.get_additional_permissions,
|
||||
}
|
||||
|
||||
global __plugin_helpers__
|
||||
__plugin_helpers__ = {
|
||||
"generate_plugins_json": __plugin_implementation__.generate_plugins_json,
|
||||
}
|
||||
@@ -61,6 +61,7 @@
|
||||
|
||||
<div class="pull-right">
|
||||
<button class="btn btn-small" data-bind="click: $root.showRepository"><i class="fas fa-plus"></i> {{ _('Get More') }}</button>
|
||||
<a class="btn btn-small" href="/plugin/pluginmanager/export"><i class="fas fa-download"></i> {{ _('Export') }}</a>
|
||||
<button class="btn btn-small" data-bind="click: function() { $root.showPluginSettings(); }" title="{{ _('Plugin Configuration')|edq }}"><i class="fas fa-wrench"></i></button>
|
||||
<a class="btn btn-small" data-toggle="collapse" href="#pluginmanager_info" title="{{ _('Info') }}"><i class="fas fa-lg fa-info-circle text-info" data-bind="css: {'text-error': noticeCount() > 0, 'text-info': noticeCount() <=0 }"></i></a>
|
||||
</div>
|
||||
|
||||
@@ -24,6 +24,7 @@ __license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agp
|
||||
__copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
||||
|
||||
import copy
|
||||
import fnmatch
|
||||
import io
|
||||
import logging
|
||||
import os
|
||||
@@ -47,6 +48,11 @@ try:
|
||||
except ImportError:
|
||||
from collections import KeysView
|
||||
|
||||
try:
|
||||
from os import scandir
|
||||
except ImportError:
|
||||
from scandir import scandir
|
||||
|
||||
from octoprint.util import (
|
||||
CaseInsensitiveSet,
|
||||
atomic_write,
|
||||
@@ -60,7 +66,7 @@ _APPNAME = "OctoPrint"
|
||||
_instance = None
|
||||
|
||||
|
||||
def settings(init=False, basedir=None, configfile=None):
|
||||
def settings(init=False, basedir=None, configfile=None, overlays=None):
|
||||
"""
|
||||
Factory method for initially constructing and consecutively retrieving the :class:`~octoprint.settings.Settings`
|
||||
singleton.
|
||||
@@ -75,6 +81,7 @@ def settings(init=False, basedir=None, configfile=None):
|
||||
``~/Library/Application Support/OctoPrint`` on MacOS.
|
||||
configfile (str): Path of the configuration file (``config.yaml``) to work on. If not set the default will
|
||||
be used: ``<basedir>/config.yaml`` for ``basedir`` as defined above.
|
||||
overlays (list): List of paths to config overlays to put between default settings and config.yaml
|
||||
|
||||
Returns:
|
||||
Settings: The fully initialized :class:`Settings` instance.
|
||||
@@ -89,7 +96,9 @@ def settings(init=False, basedir=None, configfile=None):
|
||||
|
||||
else:
|
||||
if init:
|
||||
_instance = Settings(configfile=configfile, basedir=basedir)
|
||||
_instance = Settings(
|
||||
configfile=configfile, basedir=basedir, overlays=overlays
|
||||
)
|
||||
else:
|
||||
raise ValueError("Settings not initialized yet")
|
||||
|
||||
@@ -659,14 +668,18 @@ class Settings(object):
|
||||
|
||||
OVERLAY_KEY = "__overlay__"
|
||||
|
||||
def __init__(self, configfile=None, basedir=None):
|
||||
def __init__(self, configfile=None, basedir=None, overlays=None):
|
||||
self._logger = logging.getLogger(__name__)
|
||||
|
||||
self._basedir = None
|
||||
|
||||
if overlays is None:
|
||||
overlays = []
|
||||
|
||||
assert isinstance(default_settings, dict)
|
||||
|
||||
self._map = HierarchicalChainMap({}, default_settings)
|
||||
self.load_overlays(overlays)
|
||||
|
||||
self._config = None
|
||||
self._dirty = False
|
||||
@@ -1013,6 +1026,34 @@ class Settings(object):
|
||||
|
||||
self._forget_hashes()
|
||||
|
||||
def load_overlays(self, overlays, migrate=True):
|
||||
for overlay in overlays:
|
||||
if not os.path.exists(overlay):
|
||||
continue
|
||||
|
||||
def process(path):
|
||||
try:
|
||||
overlay_config = self.load_overlay(path, migrate=migrate)
|
||||
self.add_overlay(overlay_config)
|
||||
self._logger.info("Added config overlay from {}".format(path))
|
||||
except Exception:
|
||||
self._logger.exception(
|
||||
"Could not add config overlay from {}".format(path)
|
||||
)
|
||||
|
||||
if os.path.isfile(overlay):
|
||||
process(overlay)
|
||||
|
||||
elif os.path.isdir(overlay):
|
||||
for entry in scandir(overlay):
|
||||
name = entry.name
|
||||
path = entry.path
|
||||
|
||||
if is_hidden_path(path) or not fnmatch.fnmatch(name, "*.yaml"):
|
||||
continue
|
||||
|
||||
process(path)
|
||||
|
||||
def load_overlay(self, overlay, migrate=True):
|
||||
config = None
|
||||
|
||||
|
||||
Reference in new issue
Block a user