Last active
December 27, 2020 17:45
-
-
Save cp2004/9f4e02dd1e5bb56726637412c04060ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import absolute_import, unicode_literals | |
import octoprint.plugin | |
import threading | |
class BackupTestPlugin(octoprint.plugin.StartupPlugin): | |
def on_after_startup(self): | |
# waits for a minute, then tries to create a backup | |
t = threading.Timer(interval=60, function=self.create_backup) | |
t.daemon = True | |
t.start() | |
# a minute later, this is delted again | |
t2 = threading.Timer(interval=120, function=self.delete_backup) | |
t2.daemon = True | |
t2.start() | |
def create_backup(self): | |
self._logger.info("Starting backup") | |
helpers = self._plugin_manager.get_helpers("backup", "create_backup") | |
if helpers and "create_backup" in helpers: | |
helpers["create_backup"](exclude=[], filename="TestBackup") | |
else: | |
# Fall back to API call here if necessary | |
pass | |
def delete_backup(self): | |
self._logger.info("Deleting backup") | |
helpers = self._plugin_manager.get_helpers("backup", "delete_backup") | |
if helpers and "delete_backup" in helpers: | |
helpers["delete_backup"]("TestBackup") | |
else: | |
# Fall back to API call here if necessary | |
pass | |
__plugin_name__ = "Backup Test" | |
__plugin_version__ = "1.0.0" | |
__plugin_description__ = "Test backup helpers" | |
__plugin_pythoncompat__ = ">=2.7,<4" | |
__plugin_implementation__ = BackupTestPlugin() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment