Trim some duplicate code.

This commit is contained in:
Joe DeVivo 2012-09-21 14:29:49 -07:00
parent d6a047726f
commit 30ea57c9e6

View File

@ -80,6 +80,16 @@ upgrade(Node, NewVersion) ->
start(Node), start(Node),
ok. ok.
all_the_app_configs(DevPath) ->
case filelib:is_dir(DevPath) of
true ->
Devs = filelib:wildcard(DevPath ++ "/dev/dev*"),
[ Dev ++ "/etc/app.config" || Dev <- Devs];
_ ->
lager:debug("~s is not a directory.", [DevPath]),
[]
end.
update_app_config(all, Config) -> update_app_config(all, Config) ->
lager:info("rtdev:update_app_config(all, ~p)", [Config]), lager:info("rtdev:update_app_config(all, ~p)", [Config]),
[ update_app_config(DevPath, Config) || {_Name, DevPath} <- proplists:delete(root, rt:config(rtdev_path))]; [ update_app_config(DevPath, Config) || {_Name, DevPath} <- proplists:delete(root, rt:config(rtdev_path))];
@ -89,13 +99,7 @@ update_app_config(Node, Config) when is_atom(Node) ->
ConfigFile = io_lib:format("~s/dev/dev~b/etc/app.config", [Path, N]), ConfigFile = io_lib:format("~s/dev/dev~b/etc/app.config", [Path, N]),
update_app_config_file(ConfigFile, Config); update_app_config_file(ConfigFile, Config);
update_app_config(DevPath, Config) -> update_app_config(DevPath, Config) ->
case filelib:is_dir(DevPath) of [update_app_config_file(AppConfig, Config) || AppConfig <- all_the_app_configs(DevPath)].
true ->
Devs = filelib:wildcard(DevPath ++ "/dev/dev*"),
AppConfigs = [ Dev ++ "/etc/app.config" || Dev <- Devs],
[update_app_config_file(AppConfig, Config) || AppConfig <- AppConfigs];
_ -> lager:debug("~s is not a directory.", [DevPath])
end.
update_app_config_file(ConfigFile, Config) -> update_app_config_file(ConfigFile, Config) ->
lager:info("rtdev:update_app_config_file(~s, ~p)", [ConfigFile, Config]), lager:info("rtdev:update_app_config_file(~s, ~p)", [ConfigFile, Config]),
@ -126,13 +130,7 @@ get_backends() ->
end. end.
get_backends(DevPath) -> get_backends(DevPath) ->
case filelib:is_dir(DevPath) of [get_backend(AppConfig) || AppConfig <- all_the_app_configs(DevPath)].
true ->
Devs = filelib:wildcard(DevPath ++ "/dev/dev*"),
AppConfigs = [ Dev ++ "/etc/app.config" || Dev <- Devs],
[get_backend(AppConfig) || AppConfig <- AppConfigs];
_ -> lager:debug("~s is not a directory.", [DevPath])
end.
get_backend(AppConfig) -> get_backend(AppConfig) ->
{ok, [Config]} = file:consult(AppConfig), {ok, [Config]} = file:consult(AppConfig),