Skip to content

Commit

Permalink
Merge branch 'master' into describe-app
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavisp3 committed Mar 21, 2008
2 parents 3cbf2e8 + b6534f5 commit 01448ea
Show file tree
Hide file tree
Showing 22 changed files with 682 additions and 254 deletions.
58 changes: 52 additions & 6 deletions lib/epkg/src/epkg.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
list/0,
list_lib/0,
list_releases/0,
diff_config/3,
remove_all_apps/1,
remove_app/2,
remove_all/1,
Expand All @@ -38,6 +39,7 @@
remove_all_apps_help/0,
remove_help/0,
remove_all_help/0,
diff_config_help/0,
examples_help/0,
commands_help/0
]).
Expand Down Expand Up @@ -147,9 +149,11 @@ list_help() ->
list_lib() ->
{ok, InstallationPath} = epkg_installed_paths:get_installation_path(),
{ok, TargetErtsVsn} = gas:get_env(epkg, target_erts_vsn, ewr_util:erts_version()),
NameVsnPairs = epkg_manage:list_lib(InstallationPath, TargetErtsVsn),
io:format("~nInstalled Applications (for ERTS ~s):~n", [TargetErtsVsn]),
lists:foreach(fun({Name, Vsn}) -> io:format("~s ~s~n", [Name, Vsn]) end, NameVsnPairs).
LowerBoundErtsVsn = epkg_util:erts_lower_bound_from_target(TargetErtsVsn),
NameVsnsPairs = collect_dups(epkg_manage:list_lib(InstallationPath, TargetErtsVsn)),
io:format("~nInstalled Applications for ERTS versions between ~s and ~s:~n", [LowerBoundErtsVsn, TargetErtsVsn]),
lists:foreach(fun({Name, Vsns}) -> io:format("~s ~s~n", [Name, format_vsns(Vsns)]) end, NameVsnsPairs).


%%--------------------------------------------------------------------
%% @doc
Expand All @@ -159,9 +163,12 @@ list_lib() ->
%%--------------------------------------------------------------------
list_releases() ->
{ok, InstallationPath} = epkg_installed_paths:get_installation_path(),
NameVsnPairs = epkg_manage:list_releases(InstallationPath),
io:format("~nInstalled Releases (Erlang standalone services):~n"),
lists:foreach(fun({Name, Vsn}) -> io:format("~s ~s~n", [Name, Vsn]) end, NameVsnPairs).
{ok, TargetErtsVsn} = gas:get_env(epkg, target_erts_vsn, ewr_util:erts_version()),
LowerBoundErtsVsn = epkg_util:erts_lower_bound_from_target(TargetErtsVsn),
NameVsnsPairs = collect_dups(epkg_manage:list_releases(InstallationPath, TargetErtsVsn)),
io:format("~nInstalled Releases (Erlang standalone services) for ERTS versions between ~s and ~s:~n",
[LowerBoundErtsVsn, TargetErtsVsn]),
lists:foreach(fun({Name, Vsns}) -> io:format("~s ~s~n", [Name, format_vsns(lists:reverse(Vsns))]) end, NameVsnsPairs).

%%--------------------------------------------------------------------
%% @doc
Expand Down Expand Up @@ -240,6 +247,20 @@ remove_all_help() ->
"Usage: remove-all <release-name>: remove a particular rlease for all versions installed.\n",
"Example: remove-all sinan - removes all versions of the sinan release that are currently installed."].

%%--------------------------------------------------------------------
%% @doc Diff two config files
%% @spec diff_config(RelName, RelVsn1, RelVsn2) -> {ok, Diff}
%% @end
%%--------------------------------------------------------------------
diff_config(RelName, RelVsn1, RelVsn2) ->
{ok, epkg_manage:diff_config(RelName, RelVsn1, RelVsn2)}.

%% @private
diff_config_help() ->
["\nHelp for diff_config\n",
"Usage: diff-config <release-name> <rel-vsn1> <rel-vsn2>: diff config files for two versions of a release\n",
"Example: diff-config sinan 0.8.8 0.8.10 - Diff config file for installed versions of sinan 0.8.8 and 0.8.10."].

%%--------------------------------------------------------------------
%% @doc
%% Return the version of the current Epkg release.
Expand Down Expand Up @@ -325,3 +346,28 @@ help_for_command(Command) ->
print_help_list(HelpList) ->
lists:foreach(fun(HelpString) -> io:format("~s~n", [HelpString]) end, HelpList).


%%--------------------------------------------------------------------
%% @private
%% @doc used to format the output of the list functions
%% @end
%%--------------------------------------------------------------------
format_vsns(Vsns) when length(Vsns) > 5 ->
SortedVsns = lists:sort(fun(V1, V2) -> ewr_util:is_version_greater(V1, V2) end, Vsns),
lists:flatten([ewr_util:join(lists:reverse(lists:nthtail(length(Vsns) - 5, lists:reverse(SortedVsns))), " | "), " | ..."]);
format_vsns(Vsns) ->
SortedVsns = lists:sort(fun(V1, V2) -> ewr_util:is_version_greater(V1, V2) end, Vsns),
ewr_util:join(SortedVsns, " | ").

collect_dups([]) ->
[];
collect_dups([{Name, Vsn}|NameAndVsnPairs]) ->
collect_dups(NameAndVsnPairs, [{Name, [Vsn]}]).

collect_dups([{Name, Vsn}|T], [{Name, Vsns}|Acc]) ->
collect_dups(T, [{Name, [Vsn|Vsns]}|Acc]);
collect_dups([{Name, Vsn}|T], Acc) ->
collect_dups(T, [{Name, [Vsn]}|Acc]);
collect_dups([], Acc) ->
Acc.

1 change: 1 addition & 0 deletions lib/epkg/src/epkg_install.erl
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ remove_redundant_paths([], _, _) ->
%%--------------------------------------------------------------------
install_non_release_package(PackagePath, InstalledPackageDir, PackageInstallationPath) ->
ewl_file:mkdir_p(PackageInstallationPath),
?INFO_MSG("copying ~s to ~s~n", [PackagePath, InstalledPackageDir]),
ewl_file:copy_dir(PackagePath, InstalledPackageDir),
build_if_build_file(InstalledPackageDir).

Expand Down
56 changes: 37 additions & 19 deletions lib/epkg/src/epkg_installed_paths.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
application_container_path/2,
erts_container_path/1,
executable_container_path/1,
release_file_container_path/3,
release_container_path/1
]).

Expand All @@ -49,7 +50,9 @@
list_app_vsns/3,
package_dir_to_name_and_vsn/1,
get_installation_path/0,
find_config_file_path/2,
installed_config_file_path/0,
installed_config_file_path/4,
installed_release_rel_file_path/3
]).

Expand All @@ -70,7 +73,7 @@ release_container_path(InstallationPath) ->
%% @end
%%--------------------------------------------------------------------
application_container_path(InstallationPath, ErtsVsn) ->
lists:flatten([InstallationPath, "/application_packages/", ErtsVsn, "/lib/"]).
filename:join([InstallationPath, "application_packages", ErtsVsn, "lib"]).

%%--------------------------------------------------------------------
%% @doc Returns a path to the directory where executable files sit.
Expand All @@ -88,6 +91,14 @@ executable_container_path(InstallationPath) when is_list(InstallationPath) ->
erts_container_path(InstallationPath) ->
lists:flatten([InstallationPath, "/erts_packages/"]).

%%--------------------------------------------------------------------
%% @doc Returns a path to the directory under which the release file sits.
%% @spec release_file_container_path(InstallationPath, RelName, RelVsn) -> string()
%% @end
%%--------------------------------------------------------------------
release_file_container_path(InstallationPath, RelName, RelVsn) ->
lists:flatten([installed_release_dir_path(InstallationPath, RelName, RelVsn), "/release/"]).

%%====================================================================
%% Package Paths
%%====================================================================
Expand Down Expand Up @@ -140,7 +151,7 @@ installed_release_dir_path(RelName, RelVsn) ->
%% @end
%%--------------------------------------------------------------------
installed_release_rel_file_path(InstallationPath, RelName, RelVsn) ->
lists:flatten([installed_release_file_dir(InstallationPath, RelName, RelVsn), RelName, ".rel"]).
filename:join([release_file_container_path(InstallationPath, RelName, RelVsn), RelName ++ ".rel"]).

%%--------------------------------------------------------------------
%% @doc Returns the path to the cmds directory in an installed release.
Expand All @@ -156,7 +167,23 @@ installed_release_cmds_dir_path(InstallationPath, RelName, RelVsn) ->
%% @end
%%--------------------------------------------------------------------
installed_release_bin_dir_path(InstallationPath, RelName, RelVsn) ->
ewl_file:join_paths(installed_release_dir_path(InstallationPath, RelName, RelVsn), "bin").
filename:join([installed_release_dir_path(InstallationPath, RelName, RelVsn), "bin"]).

%%--------------------------------------------------------------------
%% @doc return the path to config.
%% @spec installed_config_file_path(InstallationPath, RelName, RelVsn, ConfigFileName) -> string()
%% @end
%%--------------------------------------------------------------------
installed_config_file_path(InstallationPath, RelName, RelVsn, ConfigFileName) ->
filename:join([release_file_container_path(InstallationPath, RelName, RelVsn), ConfigFileName]).

%% @spec installed_config_file_path() -> string()
%% @equiv installed_config_file_path(InstallationPath, "faxien", CurrentFaxienVsn, "faxien.config")
installed_config_file_path() ->
%% @todo this is not compatible with composable apps - this must run with faxien. Fix this.
{ok, InstallationPath} = get_installation_path(),
{ok, Version} = faxien:version(),
installed_config_file_path(InstallationPath, "faxien", Version, "faxien.config").

%%====================================================================
%% Other External Functions
Expand Down Expand Up @@ -288,34 +315,25 @@ get_installation_path() ->
end.

%%--------------------------------------------------------------------
%% @doc return the path to config.
%% @spec installed_config_file_path() -> string()
%% @doc Return the path to a config file within an installed release.
%% @spec config_file_path(RelName, RelVsn) -> ConfigFilePath
%% @end
%%--------------------------------------------------------------------
installed_config_file_path() ->
find_config_file_path(RelName, RelVsn) ->
{ok, InstallationPath} = get_installation_path(),
config_file_path(InstallationPath).
RelDirPath = release_file_container_path(InstallationPath, RelName, RelVsn),
[RelConfigFilePath] = ewl_file:find(RelDirPath, ".*config"),
RelConfigFilePath.

%%%===================================================================
%%% Internal Functions
%%%===================================================================

%%--------------------------------------------------------------------
%% @private
%% @doc based on the installation path return the path to config
%% @end
%%--------------------------------------------------------------------
config_file_path(InstallationPath) ->
%% @todo this is not compatible with composable apps - this must run with faxien. Fix this.
{ok, Version} = faxien:version(),
lists:flatten([installed_release_file_dir(InstallationPath, "faxien", Version), "faxien.config"]).


installed_release_file_dir(InstallationPath, RelName, RelVsn) ->
lists:flatten([epkg_installed_paths:installed_release_dir_path(InstallationPath, RelName, RelVsn), "/release/"]).

%%====================================================================
%% Test Functions
%% Test% Functions
%%====================================================================

%package_dir_to_name_and_vsn_test() ->
Expand Down
79 changes: 71 additions & 8 deletions lib/epkg/src/epkg_manage.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
remove_all_apps/3,
remove_release/4,
remove_all_releases/3,
diff_config/3,
list_lib/2,
list_releases/1
list_releases/2,
find_highest_local_release_vsn/2,
find_highest_local_app_vsn/2
]).

%%--------------------------------------------------------------------
Expand All @@ -33,24 +36,44 @@
%%--------------------------------------------------------------------
%% @doc
%% Returns a list of all applications currently installed.
%% @spec list_lib(InstallationPath, ErtsVsn) -> [{Name, Vsn}]
%% @spec list_lib(InstallationPath, TargetErtsVsn) -> [{Name, Vsn}]
%% @end
%%--------------------------------------------------------------------
list_lib(InstallationPath, ErtsVsn) ->
list_lib(InstallationPath, TargetErtsVsn) ->
Fun = fun(ErtsVsn) -> list_lib_for_erts_vsn(InstallationPath, TargetErtsVsn) end,
Series = epkg_util:erts_series(TargetErtsVsn),
?INFO_MSG("listing lib dirs for erts vsns ~p~n", [Series]),
lists:sort(fun({N, _}, {N1, _}) -> N > N1 end,
lists:flatten([lists:map(fun(ErtsVsn) -> list_lib_for_erts_vsn(InstallationPath, ErtsVsn) end, Series)])).


list_lib_for_erts_vsn(InstallationPath, ErtsVsn) ->
LibDir = epkg_installed_paths:application_container_path(InstallationPath, ErtsVsn),
Paths = filelib:wildcard(LibDir ++ "/*"),
name_and_vsn(Paths).

%%--------------------------------------------------------------------
%% @doc
%% Returns a list of all releases currently installed.
%% @spec list_releases(InstallationPath) -> [{Name, Vsn}]
%% @spec list_releases(InstallationPath, TargetErtsVsn) -> [{Name, Vsn}]
%% @end
%%--------------------------------------------------------------------
list_releases(InstallationPath) ->
RelDir = epkg_installed_paths:release_container_path(InstallationPath),
Paths = filelib:wildcard(RelDir ++ "/*"),
name_and_vsn(Paths).
list_releases(InstallationPath, TargetErtsVsn) ->
RelDir = epkg_installed_paths:release_container_path(InstallationPath),
Series = epkg_util:erts_series(TargetErtsVsn),
?INFO_MSG("listing lib dirs for erts vsns ~p~n", [Series]),
lists:sort(fun({N, _}, {N1, _}) -> N > N1 end,
lists:flatten([lists:map(fun(ErtsVsn) -> list_releases_for_erts_vsn(InstallationPath, ErtsVsn) end, Series)])).

list_releases_for_erts_vsn(InstallationPath, ErtsVsn) ->
RelDir = epkg_installed_paths:release_container_path(InstallationPath),
Paths = filelib:wildcard(RelDir ++ "/*"),
lists:filter(fun({RelName, RelVsn}) ->
RelFilePath = epkg_installed_paths:installed_release_rel_file_path(InstallationPath, RelName, RelVsn),
ErtsVsn_ = epkg_util:consult_rel_file(erts_vsn, RelFilePath),
ErtsVsn_ == ErtsVsn
end,
name_and_vsn(Paths)).

%%--------------------------------------------------------------------
%% @doc
Expand Down Expand Up @@ -132,6 +155,46 @@ remove_all_releases(InstallationPath, RelName, Force) ->
RelVsns = epkg_installed_paths:list_release_vsns(InstallationPath, RelName),
lists:foreach(fun(RelVsn) -> remove_release(InstallationPath, RelName, RelVsn, Force) end, RelVsns).

%%--------------------------------------------------------------------
%% @doc Find the highest version of a particular release that is installed locally.
%% @spec find_highest_local_release_vsn(ReleaseName, TargetErtsVsn) -> {ok, HighestVsn} | {error, Reason}
%% @end
%%--------------------------------------------------------------------
find_highest_local_release_vsn(ReleaseName, TargetErtsVsn) ->
{ok, InstallationPath} = epkg_installed_paths:get_installation_path(),
NameAndVsns = lists:filter(fun({Name, _}) -> ReleaseName == Name end,
list_releases(InstallationPath, TargetErtsVsn)),
highest_vsn([Vsn || {Name, Vsn} <- NameAndVsns]).

%%--------------------------------------------------------------------
%% @doc Find the highest version of a particular application that is installed locally.
%% @spec find_highest_local_app_vsn(AppName, TargetErtsVsn) -> {ok, HighestVsn} | {error, Reason}
%% @end
%%--------------------------------------------------------------------
find_highest_local_app_vsn(AppName, TargetErtsVsn) ->
{ok, InstallationPath} = epkg_installed_paths:get_installation_path(),
NameAndVsns = lists:filter(fun({Name, _}) -> AppName == Name end,
list_lib(InstallationPath, TargetErtsVsn)),
highest_vsn([Vsn || {Name, Vsn} <- NameAndVsns]).

highest_vsn(Vsns) when length(Vsns) > 0 ->
HighestLocalVsn = hd(lists:sort(fun(A, B) -> ewr_util:is_version_greater(A, B) end, Vsns)),
{ok, HighestLocalVsn};
highest_vsn([]) ->
{error, app_not_installed};
highest_vsn(Error) ->
{error, Error}.

%%--------------------------------------------------------------------
%% @doc Diff two config files
%% @spec diff_config(RelName, RelVsn1, RelVsn2) -> Diff
%% @end
%%--------------------------------------------------------------------
diff_config(RelName, RelVsn1, RelVsn2) ->
Rel1ConfigFilePath = epkg_installed_paths:find_config_file_path(RelName, RelVsn1),
Rel2ConfigFilePath = epkg_installed_paths:find_config_file_path(RelName, RelVsn2),
ewl_config_diff:config_files(Rel1ConfigFilePath, Rel2ConfigFilePath).

%%====================================================================
%% Internal functions
%%====================================================================
Expand Down
14 changes: 12 additions & 2 deletions lib/epkg/src/epkg_package_paths.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
%% API
-export([
package_dir_path/3,
release_package_library_path/1,
release_package_control_file_path/1,
release_package_rel_file_path/3,
release_package_app_package_path/3,
Expand Down Expand Up @@ -44,7 +45,15 @@ release_package_rel_file_path(ReleasePackagePath, RelName, RelVsn) ->
%% @end
%%--------------------------------------------------------------------
release_package_app_package_path(ReleasePackagePath, AppName, AppVsn) ->
ReleasePackagePath ++ "/lib/" ++ AppName ++ "-" ++ AppVsn.
filename:join([ReleasePackagePath, "lib", AppName ++ "-" ++ AppVsn]).

%%--------------------------------------------------------------------
%% @doc Return the path to the directory that contains the releases libraries.
%% @spec release_package_library_path(ReleasePackagePath) -> string()
%% @end
%%--------------------------------------------------------------------
release_package_library_path(ReleasePackagePath) ->
filename:join([ReleasePackagePath, "lib"]).

%%--------------------------------------------------------------------
%% @doc Return the path to an app package within a release package.
Expand All @@ -65,11 +74,12 @@ release_package_control_file_path(ReleasePackagePath) ->
%%====================================================================
%% Internal functions
%%====================================================================

%%--------------------------------------------------------------------
%% @private
%% @doc Return the directory that contains the .rel, .boot, and .script files.
%% @end
%%--------------------------------------------------------------------
rel_file_base_dir(ReleasePackagePath, RelVsn) ->
lists:flatten([ReleasePackagePath, "/releases/", RelVsn]).
filename:join([ReleasePackagePath, "releases", RelVsn]).

Loading

0 comments on commit 01448ea

Please sign in to comment.