Skip to content

Commit

Permalink
moved path files out to ewlib
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Logan committed Jul 12, 2008
1 parent f3c955b commit fab5f62
Show file tree
Hide file tree
Showing 19 changed files with 210 additions and 330 deletions.
2 changes: 1 addition & 1 deletion _build.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project : {
name : faxien
vsn : "0.29.9.0"
vsn : "0.30.0.0"
},

repositories : ["http://repo.martinjlogan.com/pub", "http://repo.erlware.org/pub"],
Expand Down
4 changes: 2 additions & 2 deletions bin/epkg
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ PREFIX=$(cd $(dirname $(dirname $PROG)); pwd)

#### Fill in values for these variables ####
REL_NAME=faxien
REL_VSN=0.29.8.0
REL_VSN=0.30.0.0
ERTS_VSN=5.6.2
INVOCATION_SUFFIX="-s epkg_cmdln epkg_apply epkg $@ -s init stop -noshell -prefix $PREFIX"
INVOCATION_SUFFIX="-s epkg cmdln_apply epkg $@ -s init stop -noshell -prefix $PREFIX"
###########################################

export ROOTDIR=$PREFIX/application_packages/$ERTS_VSN
Expand Down
4 changes: 2 additions & 2 deletions bin/faxien
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ PREFIX=$(cd $(dirname $(dirname $PROG)); pwd)

#### Fill in values for these variables ####
REL_NAME=faxien
REL_VSN=0.29.9.0
REL_VSN=0.30.0.0
ERTS_VSN=5.6.2
INVOCATION_SUFFIX="-s fax_cmdln faxien_apply faxien $@ -s init stop -noshell -prefix $PREFIX"
INVOCATION_SUFFIX="-s faxien cmdln_apply faxien $@ -s init stop -noshell -prefix $PREFIX"
###########################################

export ROOTDIR=$PREFIX/application_packages/$ERTS_VSN
Expand Down
3 changes: 1 addition & 2 deletions lib/epkg/ebin/epkg.app
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{description, "Manages local erlang/OTP packages. Faxien depends on this for local operations."},

% The version of the applicaton
{vsn, "0.3.12.0"},
{vsn, "0.4.0.0"},

% All modules used by the application.
{modules,
Expand All @@ -16,7 +16,6 @@
epkg_control,
epkg_install,
epkg_manage,
epkg_package_paths,
epkg_util,
epkg_validation
]},
Expand Down
7 changes: 7 additions & 0 deletions lib/epkg/include/epkg.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@

%% Keys that must be present in a control file for it to be considered valid.
-define(MANDITORY_CONTROL_KEYS, [package_owner, description, package_owner_email, categories]).

%% Must be a list of tuples of strings. Commands can use either the _ or the - separator notation.
-define(EPKG_ALIAS_LIST, [
{"cfp", "config-file-path"},
{"raa", "remove-all-apps"},
{"ra", "remove-app"}
]).
33 changes: 24 additions & 9 deletions lib/epkg/src/epkg.erl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
%% API
%%--------------------------------------------------------------------
-export([
cmdln_apply/1,
install_release/1,
install_release/2,
install_erts/1,
Expand Down Expand Up @@ -52,9 +53,24 @@
]).

-include("macros.hrl").
-include("epkg.hrl").
%%====================================================================
%% API
%%====================================================================
%%--------------------------------------------------------------------
%% @doc apply functions from the commandline.
%% @spec (MFA) -> void()
%% @end
%%--------------------------------------------------------------------
cmdln_apply([_Mod]) ->
help();
cmdln_apply([Mod, RawFunc|Args]) ->
?INFO_MSG("mod:func ~p:~p with raw args from commandline: ~w~n", [Mod, RawFunc, Args]),
Func = list_to_atom(
epkg_cmdln:resolve_alias(
epkg_cmdln:translate_dash_to_underscore(epkg_cmdln:resolve_alias(atom_to_list(RawFunc), ?EPKG_ALIAS_LIST)),
?EPKG_ALIAS_LIST)),
epkg_cmdln:cmdln_apply([Mod, Func|Args]).

%%--------------------------------------------------------------------
%% @doc
Expand Down Expand Up @@ -306,9 +322,7 @@ config_file_path(RelName, RelVsn) ->
%% @end
%%--------------------------------------------------------------------
config_file_path(RelName) ->
{ok, TargetErtsVsn} = gas:get_env(epkg, target_erts_vsn, ewr_util:erts_version()),
{ok, RelVsn} = epkg_manage:find_highest_local_release_vsn(RelName, TargetErtsVsn),
config_file_path(RelName, RelVsn).
config_file_path(RelName, epkg_manage:find_highest_local_release_vsn(RelName)).

%% @private
config_file_path_help() ->
Expand Down Expand Up @@ -378,26 +392,27 @@ commands_help() ->
"config-file-path display the path to a release config file."
].


%%--------------------------------------------------------------------
%% @doc
%% Print the help screen for a specific command.
%% @spec help(Command::atom()) -> ok
%% @end
%%--------------------------------------------------------------------
help(Command) when is_atom(Command) ->
help_for_command(Command).
help_for_command(atom_to_list(Command)).

%%====================================================================
%% Internal functions
%%====================================================================

help_for_command(Command) ->
StrCommand = atom_to_list(Command),
Func = list_to_atom(StrCommand ++ "_help"),
help_for_command(RawCommand) ->
Command = epkg_cmdln:resolve_alias(
epkg_cmdln:translate_dash_to_underscore(
epkg_cmdln:resolve_alias(RawCommand, ?EPKG_ALIAS_LIST)), ?EPKG_ALIAS_LIST),
Func = list_to_atom(Command ++ "_help"),
case catch ?MODULE:Func() of
{'EXIT', _Reason} ->
io:format("That command does not have detailed help associated with it~n");
io:format("The command ~s does not have detailed help associated with it~n", [Command]);
HelpList ->
print_help_list(HelpList)
end.
Expand Down
111 changes: 61 additions & 50 deletions lib/epkg/src/epkg_cmdln.erl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
%%%-------------------------------------------------------------------
%%% @copyright Martin Logan, Eric Merritt, Erlware
%%% @author Martin Logan
%%% @doc Commandline handling
%%%
%%% @doc Commandline entry point for epkg
%%% @author Martin Logan
%%% @copyright 2007 Erlware
%%% @end
%%%-------------------------------------------------------------------
-module(epkg_cmdln).
Expand All @@ -17,23 +17,11 @@
%% External exports
%%--------------------------------------------------------------------
-export([
translate_dash_to_underscore/1,
resolve_alias/2,
cmdln_apply/1
]).

%%--------------------------------------------------------------------
%% Internal exports
%%--------------------------------------------------------------------
-export([
epkg_apply/1
]).

%%--------------------------------------------------------------------
%% Macros
%%--------------------------------------------------------------------

%%--------------------------------------------------------------------
%% Records
%%--------------------------------------------------------------------

%%====================================================================
%% External functions
%%====================================================================
Expand All @@ -52,44 +40,60 @@
%% <pre>
%%
%% Example Command Line Invocation:
%% erl -s epkg_util epkg_apply file list_dir \"/home/jdoe\" -s init stop
%% erl -s fax_util faxien_apply file list_dir \"/home/jdoe\" -s init stop
%%
%% Variables:
%% MFSList - a list containing the mod func and a list of args to apply comming via erl -s
%%
%% Types:
%% MFAList = [Mod, Func|Args] Example [file, list_dir, "/var/log"]
%% </pre>
%% @spec epkg_apply(MFAList) -> void()
%% @spec faxien_apply(MFAList) -> void()
%% @end
%%--------------------------------------------------------------------
epkg_apply([_Mod]) ->
epkg:help();
epkg_apply([Mod, RawFunc|Args]) ->
Func = sub_func(RawFunc),
?INFO_MSG("mod:func ~p:~p with raw args from commandline: ~w~n", [Mod, Func, Args]),
TokedArgs = lists:map(fun(ArgAtom) -> convert_string_to_terms(atom_to_list(ArgAtom)) end, no_space(Args)),
Result = apply_from_commandline(Mod, Func, TokedArgs),
cmdln_apply([Mod, Func|Args]) ->
TokedArgs = lists:map(fun(ArgAtom) -> convert_string_to_terms(atom_to_list(ArgAtom)) end, no_space(Args)),
Result = apply_from_commandline(Mod, Func, TokedArgs),
?INFO_MSG("apply the following: apply(~w, ~w, ~p) -> ~p~n", [Mod, Func, TokedArgs, Result]),
handle_apply_result(Result).

%%====================================================================
%% Internal functions
%%====================================================================

%%--------------------------------------------------------------------
%% @private
%% @doc change any -'s into _'s in the function to be applied.
%% @doc change any -'s into _'s and resolve any alias's in the function to be applied.
%% @spec translate_dash_to_underscore(Func, AliasList) -> ResolvedFunc
%% where
%% Func = atom() | string()
%% AliasList = {string(), string()}
%% ResolvedFunc = atom() | string()
%% @end
%%--------------------------------------------------------------------
sub_func(Func) ->
case regexp:gsub(atom_to_list(Func), "-", "_") of
{ok, NewFunc, _} ->
list_to_atom(NewFunc);
_ ->
Func
translate_dash_to_underscore(Func) when is_atom(Func) ->
list_to_atom(translate_dash_to_underscore(atom_to_list(Func)));
translate_dash_to_underscore(Func) ->
case regexp:gsub(Func, "-", "_") of
{ok, NewFunc, _} -> NewFunc;
_ -> Func
end.

%%--------------------------------------------------------------------
%% @doc translate one string to another if there is a translation in the alias list.
%% @spec (FuncName, AliasList) -> NewFuncName
%% where
%% FuncName = string()
%% NewFuncName = string()
%% AliasList = [{FuncName, NewFuncName}]
%% @end
%%--------------------------------------------------------------------
resolve_alias(FuncName, [{FuncName, Func}|_]) ->
Func;
resolve_alias(FuncName, [_|T]) ->
resolve_alias(FuncName, T);
resolve_alias(Func, []) ->
Func.

%%====================================================================
%% Internal functions
%%====================================================================

%%--------------------------------------------------------------------
%% @private
%% @doc the place where all functions are applied from. The final catch all for exceptions.
Expand Down Expand Up @@ -132,8 +136,7 @@ handle_apply_result({error, PrintableError}) ->
io:format("~nSuggestions:~n"),
print_error_specific_error_msg(PrintableError),
print_logfile_info(),
io:format(" - Remember that if you are trying to install a package that 'epkg install <args...>'~n"),
io:format(" is for releases, while 'epkg install_app <args...>' is for applications~n").
ok.

%%----------------------------------------------------------------------------
%% @private
Expand Down Expand Up @@ -179,6 +182,8 @@ sanitize_error({error, {{_Type, {error, Reason}}, _Trace}}) when is_list(_Trace)
{error, Reason};
sanitize_error({Reason, _Trace}) when is_tuple(Reason), is_list(_Trace) ->
{error, Reason};
sanitize_error(function_clause) ->
{error, function_clause};
sanitize_error({error, Error}) ->
{error, Error};
sanitize_error(Error) ->
Expand All @@ -189,6 +194,9 @@ sanitize_error(Error) ->
%% @doc Print out a custom error message to the user based on a sanitized error term.
%% @end
%%----------------------------------------------------------------------------
print_error_specific_error_msg(no_publish_repos) ->
io:format(" - No publish repos have been configured. Add publish repos with 'faxien add-publish-repo <repo-name>'~n" ++
" Suggested repos are http://repo.erlware.org/writable and http://repo.martinjlogan.com/writable~n");
print_error_specific_error_msg({unable_to_pull_from_repos, Msg}) ->
io:format(" - " ++ Msg ++ "~n Please request that the package compiled for your local~n" ++
" architecture be published to an accessible repository.~n");
Expand All @@ -200,12 +208,14 @@ print_error_specific_error_msg({unhandled, _Error}) ->
io:format(" - Please report this unhandled error to Erlware at erlware-questions@googlegroups.com or contact@erlware.org.~n");
print_error_specific_error_msg(bad_package) ->
io:format(" - The package specified is not valid. Make sure OTP standards have been followed.~n"),
io:format(" - You may have tried to run publish incorrectly try 'epkg help publish' for more information.~n");
io:format(" - You may have tried to run publish incorrectly try 'faxien help publish' for more information.~n");
print_error_specific_error_msg(function_clause) ->
io:format(" - The function you are calling exists but you are most likely calling it with a bad value. Check the docs.~n");
print_error_specific_error_msg({error,request_timeout}) ->
io:format(" - The request has timed out. Specify a larger timeout value.~n");
print_error_specific_error_msg({package_not_found, PackageName}) ->
io:format(" - Please request that a " ++ PackageName ++ " package be compiled and published for your local architecture.~n" ++
" If the package is available locally, publish it with 'epkg publish <package name>'~n");
" If the package is available locally, publish it with 'faxien publish <package name>'~n");
print_error_specific_error_msg({undef, _}) ->
[{Mod, Func, Args}|_] = erlang:get_stacktrace(),
ArgStr = case length(Args) of
Expand All @@ -219,10 +229,10 @@ print_error_specific_error_msg({undef, _}) ->
[Func, ArgStr]),
PropList =
fun([], Acc, _) ->
[" But the function with ", Acc, " arguments exists."];
[" But the function ", atom_to_list(Func), " with ", Acc, " arguments exists."];
([A], Acc, _) ->
ArityStr = io_lib:format(" and ~p", [A]),
[" But the function with ",
[" But the function ", atom_to_list(Func), " with ",
lists:reverse([ArityStr | Acc]),
" arguments exists."];
([A | As], Acc, Y) ->
Expand All @@ -235,14 +245,14 @@ print_error_specific_error_msg({undef, _}) ->
PropList(Arities, [integer_to_list(Arity)], PropList)
end,
io:format(" - ~s~n", [lists:flatten(Error ++ Exists)]),
io:format(" - Type 'epkg help' for information on the allowed commands. Or visit www.erlware.org for more info.~n");
io:format(" - Type 'faxien help' for information on the allowed commands. Or visit www.erlware.org for more info.~n");
print_error_specific_error_msg(_PrintableError) ->
io:format(" - Make sure you have the correct permissions to run Epkg~n").
io:format(" - Make sure you have the correct permissions to run Faxien~n").

%%-------------------------------------------------------------------
%% @private
%% @doc
%% Prints information about how to find the epkg logfiles.
%% Prints information about how to find the faxien logfiles.
%%
%% @spec print_logfile_info() -> void()
%% @end
Expand Down Expand Up @@ -285,7 +295,7 @@ no_space([A1, A2|T], Acc) ->

%%----------------------------------------------------------------------------
%% @private
%% @doc Take a commandline string and convert it into a term taking into account some of the nuances of epkg. This really comes down
%% @doc Take a commandline string and convert it into a term taking into account some of the nuances of faxien. This really comes down
%% to two cases:
%% the fact that 2.1 gets turned into 2.111111 or somesuch by parse_term. This needs to be a vsn string not a float but the user
%% should not have to enter "2.1" from the commandline.
Expand All @@ -300,7 +310,8 @@ convert_string_to_terms(ArgString) ->
{match, _, _} ->
ArgString;
_ ->
ScanableArg = ArgString ++ ". ",
ScanableArg = ArgString ++ ". ",
?INFO_MSG("scanning and parsing ~p~n", [ScanableArg]),
{ok, Toks, _Line} = erl_scan:string(ScanableArg, 1),
case catch erl_parse:parse_term(Toks) of
{ok, Term} ->
Expand Down
Loading

0 comments on commit fab5f62

Please sign in to comment.