Browse Source

change update_addon to delete/download if the repo_url was changed

pull/258/head
Juan Pablo Giménez 5 years ago
parent
commit
0a1b8245a6
1 changed files with 22 additions and 3 deletions
  1. +22
    -3
      modules/addon/endpoints.py

+ 22
- 3
modules/addon/endpoints.py View File

@@ -145,9 +145,9 @@ def plugins():
def download_addon(name): def download_addon(name):


plugin = cbpi.cache["plugins"].get(name) plugin = cbpi.cache["plugins"].get(name)
plugin["loading"] = True
if plugin is None: if plugin is None:
return ('', 404) return ('', 404)
plugin["loading"] = True
try: try:
Repo.clone_from(plugin.get("repo_url"), "./modules/plugins/%s/" % (name)) Repo.clone_from(plugin.get("repo_url"), "./modules/plugins/%s/" % (name))
cbpi.notify("Download successful", "Plugin %s downloaded successfully" % name) cbpi.notify("Download successful", "Plugin %s downloaded successfully" % name)
@@ -158,9 +158,28 @@ def download_addon(name):


@blueprint.route('/<name>/update', methods=['POST']) @blueprint.route('/<name>/update', methods=['POST'])
def update_addon(name): def update_addon(name):
"""
Updates a addon

:param name: plugin name
:return: HTTP 204 if ok - HTTP 500 if plugin not exists
"""
plugin = cbpi.cache["plugins"].get(name)
if plugin is None:
return ('', 404)
plugin["loading"] = True

repo = Repo("./modules/plugins/%s/" % (name)) repo = Repo("./modules/plugins/%s/" % (name))
o = repo.remotes.origin
info = o.pull()
if repo.remotes.origin.url == plugin.get('repo_url'):
o = repo.remotes.origin
_info = o.pull()
else:
# url has changed the plugin needs to be re-downloaded
deletePlugin(name)
return download_addon(name)

reload(name)
plugin["loading"] = False
cbpi.notify("Plugin Updated", "Plugin %s updated successfully. Please restart the system" % name) cbpi.notify("Plugin Updated", "Plugin %s updated successfully. Please restart the system" % name)
return ('', 204) return ('', 204)




Loading…
Cancel
Save