You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2013/10/03 16:11:32 UTC
[32/50] [abbrv] git commit: updated refs/heads/1867-feature-plugins
to 95d6e35
add `uninstall()`, removed unneeded aplication:load() cruft
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/c877e614
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/c877e614
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/c877e614
Branch: refs/heads/1867-feature-plugins
Commit: c877e61404f5a511038aad1c7ffd2c22bbfcd818
Parents: f090382
Author: Jan Lehnardt <ja...@apache.org>
Authored: Fri Aug 2 22:06:02 2013 +0200
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Thu Oct 3 16:08:36 2013 +0200
----------------------------------------------------------------------
share/www/plugins.html | 16 +++++++-----
src/couch_plugins/src/couch_plugins.erl | 29 +++-------------------
src/couch_plugins/src/couch_plugins_httpd.erl | 13 +++++++---
3 files changed, 23 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/c877e614/share/www/plugins.html
----------------------------------------------------------------------
diff --git a/share/www/plugins.html b/share/www/plugins.html
index b42ed2e..e7ffc26 100644
--- a/share/www/plugins.html
+++ b/share/www/plugins.html
@@ -69,21 +69,24 @@ specific language governing permissions and limitations under the License.
$.get("/_config/plugins/" + name + "/", function(body, textStatus) {
body = JSON.parse(body);
if(body == version) {
- button.html("Already Installed");
+ button.html('Already Installed. Click to Uninstall');
+ button.data('delete', true);
} else {
- button.html("Other Version Installed: " + body);
+ button.html('Other Version Installed: ' + body);
+ button.attr('disabled', true);
}
- button.attr("disabled", true);
});
});
$('.install-plugin').click(function(event) {
var button = $(this);
+ var delete_plugin = button.data('delete') || false;
var plugin_spec = JSON.stringify({
name: button.data('name'),
url: button.data('url'),
version: button.data('version'),
- checksums: button.data('checksums')
+ checksums: button.data('checksums'),
+ "delete": delete_plugin
});
var url = '/_plugins'
$.ajax({
@@ -95,8 +98,9 @@ specific language governing permissions and limitations under the License.
processData: false, // keep our precious JSON
success: function(data, textStatus, jqXhr) {
if(textStatus == "success") {
- button.html("Sucessfully Installed");
- button.attr("disabled", true);
+ var action = delete_plugin ? 'Uninstalled' : 'Installed';
+ button.html('Sucessfully ' + action);
+ button.attr('disabled', true);
} else {
button.html(textStatus);
}
http://git-wip-us.apache.org/repos/asf/couchdb/blob/c877e614/src/couch_plugins/src/couch_plugins.erl
----------------------------------------------------------------------
diff --git a/src/couch_plugins/src/couch_plugins.erl b/src/couch_plugins/src/couch_plugins.erl
index 8b4a22a..3463d3d 100644
--- a/src/couch_plugins/src/couch_plugins.erl
+++ b/src/couch_plugins/src/couch_plugins.erl
@@ -43,9 +43,6 @@ install({Name, _BaseUrl, Version, Checksums}=Plugin) ->
ok = register_plugin(Name, Version),
log("registered plugin"),
- ok = load_plugin(Name),
- log("loaded plugin"),
-
load_config(Name, Version),
log("loaded config"),
@@ -55,10 +52,6 @@ install({Name, _BaseUrl, Version, Checksums}=Plugin) ->
% plugin, you get an `ok`.
-spec uninstall(plugin()) -> ok | {error, string()}.
uninstall({Name, _BaseUrl, Version, _Checksums}) ->
- % unload app
- ok = unload_plugin(Name),
- log("plugin unloaded"),
-
% unload config
ok = unload_config(Name, Version),
log("config unloaded"),
@@ -125,7 +118,7 @@ set_config({{Section, Key}, Value}) ->
ok = couch_config:set(Section, Key, Value).
-spec delete_config({{string(), string()}, _Value}) -> ok.
-delete_config({Section, Key}) ->
+delete_config({{Section, Key}, _Value}) ->
ok = couch_config:delete(Section, Key).
-spec file_names(string(), string()) -> string().
@@ -166,23 +159,6 @@ del_code_path(Name, Version) ->
%% * * *
-%% Load Plugin
-%% This uses `appliction:load(<plugnname>)` to load the plugin
-%% and `appliction:unload(<plugnname>)` to unload the plugin.
-
--spec load_plugin(string()) -> ok | {error, atom()}.
-load_plugin(NameList) ->
- Name = list_to_atom(NameList),
- application:load(Name).
-
--spec unload_plugin(string()) -> ok | {error, atom()}.
-unload_plugin(NameList) ->
- Name = list_to_atom(NameList),
- application:unload(Name).
-
-%% * * *
-
-
-spec untargz(string()) -> {ok, string()} | {error, string()}.
untargz(Filename) ->
% read .gz file
@@ -197,7 +173,8 @@ untargz(Filename) ->
-spec delete_files(string(), string()) -> ok | {error, atom()}.
delete_files(Name, Version) ->
PluginPath = plugin_dir() ++ "/" ++ get_file_slug(Name, Version),
- file:del_dir(PluginPath).
+ mochitemp:rmtempdir(PluginPath).
+
% downloads a pluygin .tar.gz into a local plugins directory
-spec download(string()) -> ok | {error, string()}.
http://git-wip-us.apache.org/repos/asf/couchdb/blob/c877e614/src/couch_plugins/src/couch_plugins_httpd.erl
----------------------------------------------------------------------
diff --git a/src/couch_plugins/src/couch_plugins_httpd.erl b/src/couch_plugins/src/couch_plugins_httpd.erl
index 7a450f4..7a99cd1 100644
--- a/src/couch_plugins/src/couch_plugins_httpd.erl
+++ b/src/couch_plugins/src/couch_plugins_httpd.erl
@@ -20,16 +20,18 @@ handle_req(#httpd{method='POST'}=Req) ->
couch_httpd:validate_ctype(Req, "application/json"),
{PluginSpec} = couch_httpd:json_body_obj(Req),
- ?LOG_DEBUG("Plugin Spec: ~p", [PluginSpec]),
Url = binary_to_list(couch_util:get_value(<<"url">>, PluginSpec)),
Name = binary_to_list(couch_util:get_value(<<"name">>, PluginSpec)),
Version = binary_to_list(couch_util:get_value(<<"version">>, PluginSpec)),
+ Delete = couch_util:get_value(<<"delete">>, PluginSpec),
{Checksums0} = couch_util:get_value(<<"checksums">>, PluginSpec),
Checksums = lists:map(fun({K, V}) ->
{binary_to_list(K), binary_to_list(V)}
end, Checksums0),
-
- case couch_plugins:install({Name, Url, Version, Checksums}) of
+ Plugin = {Name, Url, Version, Checksums},
+ ?LOG_DEBUG("~p", [Plugin]),
+ ?LOG_DEBUG("~p", [Delete]),
+ case do_install(Delete, Plugin) of
ok ->
couch_httpd:send_json(Req, 202, {[{ok, true}]});
Error ->
@@ -38,3 +40,8 @@ handle_req(#httpd{method='POST'}=Req) ->
end;
handle_req(Req) ->
couch_httpd:send_method_not_allowed(Req, "POST").
+
+do_install(false, Plugin)->
+ couch_plugins:install(Plugin);
+do_install(true, Plugin)->
+ couch_plugins:uninstall(Plugin).