Merge branch 'devel' into dev/settingsOverlays

This commit is contained in:
Gina Häußge committed 2016-06-24 14:31:41 +02:00
commit 3893b700f6
6 files changed
+139 -24

No files matched your search

+44 -3
View File
@@ -493,9 +493,9 @@ class PluginManager(object):
cmd.finalize_options()
self._python_install_dir = cmd.install_lib
self._python_prefix = sys.prefix
self._python_prefix = os.path.realpath(sys.prefix)
self._python_virtual_env = hasattr(sys, "real_prefix") \
or (hasattr(sys, "base_prefix") and sys.prefix != sys.base_prefix)
or (hasattr(sys, "base_prefix") and os.path.realpath(sys.prefix) != os.path.realpath(sys.base_prefix))
@property
def plugins(self):
@@ -616,7 +616,11 @@ class PluginManager(object):
# of the virtual env, so this check is necessary
plugin.managable = os.access(plugin.location, os.W_OK) \
and (not self._python_virtual_env
or plugin.location.startswith(self._python_prefix))
or is_sub_path_of(plugin.location, self._python_prefix)
or is_editable_install(self._python_install_dir,
package_name,
module_name,
plugin.location))
plugin.enabled = False
result[key] = plugin
@@ -1258,6 +1262,43 @@ class PluginManager(object):
raise ValueError("Invalid hook definition, neither a callable nor a 2-tuple (callback, order): {!r}".format(hook))
def is_sub_path_of(path, parent):
"""
Tests if `path` is a sub path (or identical) to `path`.
>>> is_sub_path_of("/a/b/c", "/a/b")
True
>>> is_sub_path_of("/a/b/c", "/a/b2")
False
>>> is_sub_path_of("/a/b/c", "/b/c")
False
>>> is_sub_path_of("/foo/bar/../../a/b/c", "/a/b")
True
>>> is_sub_path_of("/a/b", "/a/b")
True
"""
rel_path = os.path.relpath(os.path.realpath(path),
os.path.realpath(parent))
return not (rel_path == os.pardir or
rel_path.startswith(os.pardir + os.sep))
def is_editable_install(install_dir, package, module, location):
package_link = os.path.join(install_dir, "{}.egg-link".format(package))
if os.path.isfile(package_link):
expected_target = os.path.normcase(os.path.realpath(location))
try:
with open(package_link) as f:
contents = f.readlines()
for line in contents:
target = os.path.normcase(os.path.realpath(os.path.join(line.strip(), module)))
if target == expected_target:
return True
except:
pass
return False
class InstalledEntryPoint(pkginfo.Installed):
def __init__(self, entry_point, metadata_version=None):
+10
View File
@@ -741,6 +741,16 @@ class UiPlugin(OctoPrintPlugin, SortablePlugin):
"""
return None
def get_ui_preemptive_caching_enabled(self):
"""
Allows to control whether the view provided by the plugin should be preemptively
cached on server startup (default) or not.
Returns:
bool: Whether to enable preemptive caching or not
"""
return True
def get_ui_data_for_preemptive_caching(self):
"""
Allows defining additional data to be persisted in the preemptive cache configuration, on