Skip to content

Commit

Permalink
switch install_plugin to accept list of plugins to install, #45
Browse files Browse the repository at this point in the history
  • Loading branch information
jneilliii committed Nov 8, 2022
1 parent cb52421 commit 3c70422
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 28 deletions.
11 changes: 6 additions & 5 deletions octoprint_simplyprint/websocket/simplyprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,16 +599,17 @@ def _on_start_finished(fut: asyncio.Future):
elif demand == "plugin_install":
def _on_install_finished(install_success: asyncio.Future):
if install_success.result():
self._logger.info("Restarting OctoPrint after plugin install.")
self._logger.info("Restarting OctoPrint after plugin install(s).")
self._loop.run_in_executor(
None, self.sys_manager.restart_octoprint
)
else:
self._logger.debug("Failed to install plugin")
install_success: asyncio.Future = self._loop.run_in_executor( # type: ignore
None, self.sys_manager.install_plugin, args
)
install_success.add_done_callback(_on_install_finished)
if args.get("plugins", False):
install_success: asyncio.Future = self._loop.run_in_executor( # type: ignore
None, self.sys_manager.install_plugin, args["plugins"]
)
install_success.add_done_callback(_on_install_finished)
elif demand == "plugin_uninstall":
def _on_uninstall_finished(uninstall_success: asyncio.Future):
if uninstall_success.result():
Expand Down
48 changes: 26 additions & 22 deletions octoprint_simplyprint/websocket/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,29 +213,33 @@ def update_simplyprint(self) -> None:
if self.install_plugin(data):
self.restart_octoprint()

def install_plugin(self, plugin_data: Dict[str, str]) -> bool:
name = plugin_data['name']
url = plugin_data["install_url"]
self.logger.info(
f"Installing OctoPrint Plugin '{name}' at "
f"request from SimplyPrint from {url}"
)
key = plugin_data.get("key")
if key is not None and key not in self.installed_plugins:
self.installed_plugins.append(key)
self.settings.set(["sp_installed_plugins"], self.installed_plugins)
self.settings.save()
args: List[str] = ["install", url, "--no-cache-dir"]
try:
code, stdout, stderr = self._call_pip(*args)
except Exception:
self.logger.exception(f"Failed to install plugin: {name}")
return False
if code != 0:
self.logger.error(
f"Failed to install plugin {name}, returned with {code}\n"
f"{stdout}\n{stderr}"
def install_plugin(self, plugins: List[Dict[str, str]]) -> bool:
install_error = False
for plugin_data in plugins:
name = plugin_data['name']
url = plugin_data["install_url"]
self.logger.info(
f"Installing OctoPrint Plugin '{name}' at "
f"request from SimplyPrint from {url}"
)
key = plugin_data.get("key")
if key is not None and key not in self.installed_plugins:
self.installed_plugins.append(key)
self.settings.set(["sp_installed_plugins"], self.installed_plugins)
self.settings.save()
args: List[str] = ["install", url, "--no-cache-dir"]
try:
code, stdout, stderr = self._call_pip(*args)
except Exception:
self.logger.exception(f"Failed to install plugin: {name}")
install_error = True
if code != 0:
self.logger.error(
f"Failed to install plugin {name}, returned with {code}\n"
f"{stdout}\n{stderr}"
)
install_error = True
if install_error:
return False
return True

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
# Remember to bump the version in octoprint_simplyprint/__init__.py as well
plugin_version = "4.0.2dev1"
plugin_version = "4.0.2dev2"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit 3c70422

Please sign in to comment.