diff options
author | Håkan Mattsson <[email protected]> | 2010-03-09 18:46:31 +0100 |
---|---|---|
committer | Håkan Mattsson <[email protected]> | 2010-04-19 13:17:32 +0200 |
commit | 512b1a258c083021f199e6cad2da479e7fdfd6dd (patch) | |
tree | 7d2fc07d031daa0032eff26c12085a0c4339ca66 /lib/reltool/src/reltool.erl | |
parent | 2846d03cb026ec9f33ea32747b4a231e1239b1ae (diff) | |
download | otp-512b1a258c083021f199e6cad2da479e7fdfd6dd.tar.gz otp-512b1a258c083021f199e6cad2da479e7fdfd6dd.tar.bz2 otp-512b1a258c083021f199e6cad2da479e7fdfd6dd.zip |
Add function to return status about the configuration
It is called reltool:get_status/1. The API functions in reltool
that may take PidOrOptions as input and actually gets Options
does now print out the warnings.
Diffstat (limited to 'lib/reltool/src/reltool.erl')
-rw-r--r-- | lib/reltool/src/reltool.erl | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/lib/reltool/src/reltool.erl b/lib/reltool/src/reltool.erl index ff200d0eb8..351a3d59cf 100644 --- a/lib/reltool/src/reltool.erl +++ b/lib/reltool/src/reltool.erl @@ -21,7 +21,7 @@ %% Public -export([ start/0, start/1, start_link/1, debug/0, % GUI - start_server/1, get_server/1, stop/1, + start_server/1, get_server/1, get_status/1, stop/1, get_config/1, get_config/3, get_rel/2, get_script/2, create_target/2, get_target_spec/1, eval_target_spec/3, install/2 @@ -96,20 +96,45 @@ stop(Pid) when is_pid(Pid) -> end. %% Internal library function --spec eval_server(server(), fun((server_pid()) -> term())) -> +-spec eval_server(server(), boolean(), fun((server_pid()) -> term())) -> {ok, server_pid()} | {error, reason()}. -eval_server(Pid, Fun) when is_pid(Pid) -> +eval_server(Pid, DisplayWarnings, Fun) + when is_pid(Pid), is_boolean(DisplayWarnings) -> Fun(Pid); -eval_server(Options, Fun) when is_list(Options), is_function(Fun, 1) -> +eval_server(Options, DisplayWarnings, Fun) + when is_list(Options), is_boolean(DisplayWarnings), is_function(Fun, 1) -> case start_server(Options) of {ok, Pid} -> - Res = Fun(Pid), - stop(Pid), - Res; + apply_fun(Pid, DisplayWarnings, Fun); {error, Reason} -> {error, Reason} end. +apply_fun(Pid, false, Fun) -> + Res = Fun(Pid), + stop(Pid), + Res; +apply_fun(Pid, true, Fun) -> + case get_status(Pid) of + {ok, Warnings} -> + [io:format("~p: ~s\n", [?APPLICATION, W]) || W <- Warnings], + apply_fun(Pid, false, Fun); + {error, Reason} -> + stop(Pid), + {error, Reason} + end. + +%% Get status about the configuration +-type warning() :: string(). +-spec get_status(server()) -> + {ok, [warning()]} | {error, reason()}. +get_status(PidOrOptions) + when is_pid(PidOrOptions); is_list(PidOrOptions) -> + eval_server(PidOrOptions, false, + fun(Pid) -> + reltool_server:get_status(Pid) + end). + %% Get reltool configuration -spec get_config(server()) -> {ok, config()} | {error, reason()}. get_config(PidOrOption) -> @@ -119,7 +144,7 @@ get_config(PidOrOption) -> {ok, config()} | {error, reason()}. get_config(PidOrOptions, InclDef, InclDeriv) when is_pid(PidOrOptions); is_list(PidOrOptions) -> - eval_server(PidOrOptions, + eval_server(PidOrOptions, true, fun(Pid) -> reltool_server:get_config(Pid, InclDef, InclDeriv) end). @@ -128,7 +153,7 @@ get_config(PidOrOptions, InclDef, InclDeriv) -spec get_rel(server(), rel_name()) -> {ok, rel_file()} | {error, reason()}. get_rel(PidOrOptions, RelName) when is_pid(PidOrOptions); is_list(PidOrOptions) -> - eval_server(PidOrOptions, + eval_server(PidOrOptions, true, fun(Pid) -> reltool_server:get_rel(Pid, RelName) end). %% Get contents of boot script file @@ -136,21 +161,22 @@ get_rel(PidOrOptions, RelName) {ok, script_file()} | {error, reason()}. get_script(PidOrOptions, RelName) when is_pid(PidOrOptions); is_list(PidOrOptions) -> - eval_server(PidOrOptions, + eval_server(PidOrOptions, true, fun(Pid) -> reltool_server:get_script(Pid, RelName) end). %% Generate a target system -spec create_target(server(), target_dir()) -> ok | {error, reason()}. create_target(PidOrOptions, TargetDir) when is_pid(PidOrOptions); is_list(PidOrOptions) -> - eval_server(PidOrOptions, + eval_server(PidOrOptions, true, fun(Pid) -> reltool_server:gen_target(Pid, TargetDir) end). %% Generate a target system -spec get_target_spec(server()) -> {ok, target_spec()} | {error, reason()}. get_target_spec(PidOrOptions) when is_pid(PidOrOptions); is_list(PidOrOptions) -> - eval_server(PidOrOptions, fun(Pid) -> reltool_server:gen_spec(Pid) end). + eval_server(PidOrOptions, true, + fun(Pid) -> reltool_server:gen_spec(Pid) end). %% Generate a target system -spec eval_target_spec(target_spec(), root_dir(), target_dir()) -> |