PluginSettings.get_plugin_data_folder moved to OctoPrintPlugin.get_plugin_data_folder

That way plugins don't need to implement the SettingsPlugin mixin in order to access their data folder, which is now an injected property in OctoPrintPlugin. Plugin authors should still always use the getter since that will also make sure the folder actually does exist (lazy creation).

PluginSettings.get_plugin_data_folder has been marked as deprecated.
This commit is contained in:
Gina Häußge committed 2015-06-24 13:59:45 +02:00
1 parent fca8becb20
commit 67a0fd11dd
4 files changed
+36 -10

No files matched your search

+3 -5
View File
@@ -426,12 +426,10 @@ class PluginSettings(object):
filename += ".log"
return os.path.join(self.settings.getBaseFolder("logs"), filename)
@deprecated("PluginSettings.get_plugin_data_folder has been replaced by OctoPrintPlugin.get_plugin_data_folder",
includedoc="Replaced by :func:`~octoprint.plugin.types.OctoPrintPlugin.get_plugin_data_folder`",
since="1.2.0")
def get_plugin_data_folder(self):
"""
Retrieves the path to a data folder specifically for the plugin.
Plugins may use this for storing additional data.
"""
path = os.path.join(self.settings.getBaseFolder("data"), self.plugin_key)
if not os.path.isdir(path):
os.makedirs(path)
+24 -1
View File
@@ -69,9 +69,32 @@ class OctoPrintPlugin(Plugin):
The :class:`~octoprint.server.LifecycleManager` instance. Injected by the plugin core system upon initialization
of the implementation.
.. attribute:: _data_folder
Path to the data folder for the plugin to use for any data it might have to persist. Should always be accessed
through :meth:`get_plugin_data_folder` since that function will also ensure that the data folder actually exists
and if not creating it before returning it. Injected by the plugin core system upon initialization of the
implementation.
.. automethod:: get_plugin_data_folder
"""
pass
def get_plugin_data_folder(self):
"""
Retrieves the path to a data folder specifically for the plugin, ensuring it exists and if not creating it
before returning it.
Plugins may use this folder for storing additional data they need for their operation.
"""
if self._data_folder is None:
raise RuntimeError("self._plugin_data_folder is None, has the plugin been initialized yet?")
import os
if not os.path.isdir(self._data_folder):
os.makedirs(self._data_folder)
return self._data_folder
class ReloadNeedingPlugin(Plugin):
pass
+2 -1
View File
@@ -196,7 +196,8 @@ class Server():
file_manager=fileManager,
printer=printer,
app_session_manager=appSessionManager,
plugin_lifecycle_manager=pluginLifecycleManager
plugin_lifecycle_manager=pluginLifecycleManager,
data_folder=os.path.join(settings().getBaseFolder("data"), name)
)
def settings_plugin_inject_factory(name, implementation):