Permalink
Browse files

refact

  • Loading branch information...
1 parent 9ad75dc commit f631daa1eacd2e192c370ed29cdac81d18ca7761 Dmytro Lytovchenko committed Feb 23, 2014
@@ -0,0 +1,22 @@
+-ifndef(EPM_PRIVATE_RECORDS).
+-define(EPM_PRIVATE_RECORDS, true).
+
+%% Package: Does not specify branches/tags as this info is queried from package
+%% repository online.
+-record(pkg, { id=erlang:error(id_not_set) :: pkgid:pkgid()
+ , deps=[] :: [pkgid:pkgid()]
+ , args=[] :: list()
+ , repo=erlang:error(repo_not_set) :: repoid()
+ }).
+
+%% Unified global identifier for package
+-record(pkgid, { author = ?any_author :: string() | ?any_author
+ , pkg_name = ?any_name :: string() | ?any_name
+ , platform = ?any_platform :: platform()
+ , vsn = ?any_vsn :: string() | ?any_vsn
+ , erlang_vsn = ?any_erlang_vsn :: erlangvsn() | ?any_erlang_vsn
+ %% arguments passed from command line, like: source, {tag|branch|hash, x}
+ , args=[] :: [pkg_arg()]
+ }).
+
+-endif.
No changes.
View
@@ -14,14 +14,8 @@
, as_string/1]).
-include("epm.hrl").
+-include("epm_private_records.hrl").
-%% Package: Does not specify branches/tags as this info is queried from package
-%% repository online.
--record(pkg, { id=erlang:error(id_not_set) :: pkgid:pkgid()
- , deps=[] :: [pkgid:pkgid()]
- , args=[] :: list()
- , repo=erlang:error(repo_not_set) :: repoid()
- }).
-type pkg() :: #pkg{}.
-export_type([pkg/0]).
View
@@ -13,17 +13,10 @@
, as_string/1, matches/2, pkgid_match_spec/1
, fixture_/3, fixture_/4]).
+-include_lib("stdlib/include/ms_transform.hrl").
-include("epm.hrl").
+-include("epm_private_records.hrl").
-%% Unified global identifier for package
--record(pkgid, { author = ?any_author :: string() | ?any_author
- , pkg_name = ?any_name :: string() | ?any_name
- , platform = ?any_platform :: platform()
- , vsn = ?any_vsn :: string() | ?any_vsn
- , erlang_vsn = ?any_erlang_vsn :: erlangvsn() | ?any_erlang_vsn
- %% arguments passed from command line, like: source, {tag|branch|hash, x}
- , args=[] :: [pkg_arg()]
- }).
-type pkgid() :: #pkgid{}.
-export_type([pkgid/0]).
@@ -84,22 +77,30 @@ matches(#pkgid{}=P1, #pkgid{}=P2) ->
).
pkgid_match_spec(#pkgid{ author=A1, pkg_name=N1, platform=P1
- , vsn=V1, erlang_vsn=E1}) ->
- ets:fun2ms(
- fun(Pkg) when ?IS_PKG(Pkg) ->
- Id = pkg:id(Pkg),
- A2 = pkgid:author(Id),
- N2 = pkgid:pkg_name(Id),
- P2 = pkgid:platform(Id),
- V2 = pkgid:vsn(Id),
- E2 = pkgid:erlang_vsn(Id),
- (N1 =:= N2
- andalso (A1 =:= A2 orelse A1 =:= ?any_author)
- andalso (V1 =:= V2 orelse V1 =:= ?any_vsn)
- andalso (E1 =:= E2 orelse E1 =:= ?any_erlang_vsn)
- andalso (P1 =:= P2 orelse P1 =:= ?any_platform)
- )
- end).
+ , vsn=V1, erlang_vsn=E1}) ->
+ ets:fun2ms(fun(#pkg{id=#pkgid{ author=A2, pkg_name=N2, platform=P2
+ , vsn=V2, erlang_vsn=E2}}=Pkg)
+ when (N1 =:= N2
+ andalso (A1 =:= A2 orelse A1 =:= ?any_author)
+ andalso (V1 =:= V2 orelse V1 =:= ?any_vsn)
+ andalso (E1 =:= E2 orelse E1 =:= ?any_erlang_vsn)
+ andalso (P1 =:= P2 orelse P1 =:= ?any_platform)
+ ) -> Pkg end).
+%% ets:fun2ms(
+%% fun(Pkg) when ?IS_PKG(Pkg) ->
+%% Id = pkg:id(Pkg),
+%% A2 = pkgid:author(Id),
+%% N2 = pkgid:pkg_name(Id),
+%% P2 = pkgid:platform(Id),
+%% V2 = pkgid:vsn(Id),
+%% E2 = pkgid:erlang_vsn(Id),
+%% (N1 =:= N2
+%% andalso (A1 =:= A2 orelse A1 =:= ?any_author)
+%% andalso (V1 =:= V2 orelse V1 =:= ?any_vsn)
+%% andalso (E1 =:= E2 orelse E1 =:= ?any_erlang_vsn)
+%% andalso (P1 =:= P2 orelse P1 =:= ?any_platform)
+%% )
+%% end).
%%%-----------------------------------------------------------------------------
fixture_(A, N, V) -> #pkgid{author=A, pkg_name=N, vsn=V}.
View
@@ -4,7 +4,6 @@
, as_string/1]).
-include("epm.hrl").
--include_lib("stdlib/include/ms_transform.hrl").
start() ->
%% Debug
@@ -31,7 +30,7 @@ main_internal(Args) ->
epm_cfg:init(EpmHome),
State = epm_index:open(EpmHome),
setup_proxy(),
- epm_core:execute(State, Args).
+ epm_command_line:execute(State, Args).
setup_proxy() ->
epm_util:set_http_proxy( epm_cfg:get(proxy_host, none)
@@ -67,6 +66,8 @@ setup_proxy() ->
%% Pkgid#pkgid{args = [Arg | lists:delete(Arg, Args)]}.
%%------------------------------------------------------------------------------
+as_string(Pkg) when ?IS_PKG(Pkg) -> pkg:as_string(Pkg);
+as_string(Pkgid) when ?IS_PKGID(Pkgid) -> pkgid:as_string(Pkgid);
as_string(#repo{id=I, description=_D, url=U}) ->
s("[Repo ~s url=~s]", [I, U]);
as_string(#repoid{name=N}) ->
@@ -1,4 +1,4 @@
--module(epm_core).
+-module(epm_command_line).
-export([execute/2]).
-include("epm.hrl").
@@ -37,13 +37,13 @@ execute(State=#epm_state{}, ["remove" | Args]) ->
Installed = epm_ops:get_installed_packages(Packages),
case Installed of
[] ->
- io:format("+ nothing to remove: no matching packages installed~n");
+ epm:p("+ nothing to remove: no matching packages installed~n");
_ ->
- io:format("===============================~n"),
- io:format("Remove the following packages?~n"),
- io:format("===============================~n"),
- [io:format(" + ~s~n", [epm:as_string(P)]) || P <- Installed],
- io:format("~n([y]/n) "),
+ epm:p("===============================~n"
+ "Remove the following packages?~n"
+ "===============================~n"),
+ [epm:p(" + ~s~n", [epm:as_string(P)]) || P <- Installed],
+ epm:p(white, "~n([y]/n) "),
case io:get_chars("", 1) of
C when C == "y"; C == "\n" ->
io:format("~n"),
@@ -59,13 +59,13 @@ execute(State=#epm_state{}, ["update" | Args]) ->
Installed = epm_ops:get_installed_packages(Packages),
case Installed of
[] ->
- io:format("- nothing to update~n");
+ epm:p("- nothing to update~n");
_ ->
- io:format("===============================~n"),
- io:format("Update the following packages?~n"),
- io:format("===============================~n"),
- [io:format(" + ~s~n", [epm:as_string(P)]) || P <- Installed],
- io:format("~n([y]/n) "),
+ epm:p("===============================~n"
+ "Update the following packages?~n"
+ "===============================~n"),
+ [epm:p(" + ~s~n", [epm:as_string(P)]) || P <- Installed],
+ epm:p(white, "~n([y]/n) "),
case io:get_chars("", 1) of
C when C == "y"; C == "\n" ->
io:format("~n"),
@@ -81,14 +81,14 @@ execute(State=#epm_state{}, ["info" | Args]) ->
case Installed of
[] -> ok;
_ ->
- io:format("===============================~n"),
- io:format("INSTALLED~n"),
- io:format("===============================~n"),
+ epm:p("===============================~n"
+ "INSTALLED~n"
+ "===============================~n"),
F = fun(Package, Count) when ?IS_PKG(Package) ->
case Count of
0 -> ok;
- _ -> io:format("~n")
+ _ -> epm:p("~n")
end,
epm_ops:print_installed_package_info(Package),
Count + 1
@@ -101,7 +101,7 @@ execute(State=#epm_state{}, ["info" | Args]) ->
_ ->
case Installed of
[] -> ok;
- _ -> io:format("~n")
+ _ -> epm:p("~n")
end,
epm_ops:print_not_installed_package_info(State, NotInstalled, true)
end;
@@ -260,7 +260,8 @@ collect_args_internal(Target, [Arg | Rest], Pkgids, Flags) ->
[K, V1] = Vals1,
K1 = list_to_atom(K),
case K1 of
- repo_plugins -> epm_cfg:set(K1, epm_util:eval(V1 ++ "."));
+ repo_plugins ->
+ epm_cfg:set(K1, epm_util:parse_erlang_term(V1 ++ "."));
_ -> ok
end;
true -> ok
View
@@ -89,11 +89,11 @@ list_global_packages() ->
%% @doc Search local index (installed)
list_local_matching(Pkgid) when ?IS_PKGID(Pkgid) ->
- Q = epm:pkgid_match_spec(Pkgid),
+ Q = pkgid:pkgid_match_spec(Pkgid),
ets:select(?local_pkgs, Q).
list_global_matching(Pkgid) when ?IS_PKGID(Pkgid) ->
- Q = epm:pkgid_match_spec(Pkgid),
+ Q = pkgid:pkgid_match_spec(Pkgid),
ets:select(?global_pkgs, Q).
delete_local(Key={_User, _Name, _Vsn}) ->
View
@@ -248,16 +248,16 @@ print_not_installed_internal(Packages, RepoPlugins, IsExact) ->
0 -> ok;
_ -> io:format("~n")
end,
- io:format("~s~n", [epm:as_string(Repo)]),
+ epm:p("~s~n", [epm:as_string(Repo)]),
if Tags =/= [] ->
- io:format(" tags:~n"),
- [io:format(" ~s~n", [Tag]) || Tag <- Tags];
+ epm:p(" tags:~n"),
+ [epm:p(" ~s~n", [Tag]) || Tag <- Tags];
true -> ok
end,
if
Branches =/= [] ->
- io:format(" branches:~n"),
- [io:format(" ~s~n", [Branch]) || Branch <- Branches];
+ epm:p(" branches:~n"),
+ [epm:p(" ~s~n", [Branch]) || Branch <- Branches];
true -> ok
end,
Count + 1
@@ -282,7 +282,7 @@ fetch_not_installed_package_info([Pkg | Tail]
%% -----------------------------------------------------------------------------
-spec remove_package(#epm_state{}, pkgid:pkgid()) -> #epm_state{}.
remove_package(State=#epm_state{}, Pkgid) when ?IS_PKGID(Pkgid) ->
- io:format("+ removing package ~s~n" , [epm:as_string(Pkgid)]),
+ epm:p("+ removing package ~s~n" , [epm:as_string(Pkgid)]),
%RemoveCmd = "rm -rf " ++ InstallDir,
%epm_util:print_cmd_output("~s~n", [RemoveCmd]),
%epm_util:do_cmd(RemoveCmd, fail),
@@ -294,7 +294,7 @@ remove_package(State=#epm_state{}, Pkgid) when ?IS_PKGID(Pkgid) ->
%% -----------------------------------------------------------------------------
-spec update_package(#epm_state{}, pkgid:pkgid()) -> #epm_state{}.
update_package(State=#epm_state{}, Pkgid) when ?IS_PKGID(Pkgid) ->
- io:format("+ updating package ~s~n" , [pkgid:as_string(Pkgid)]),
+ epm:p("+ updating package ~s~n" , [pkgid:as_string(Pkgid)]),
%Repo = Package#pkg.repo,
%Vsn = Package#pkg.vsn,
%% switch to build home dir
View
@@ -1,9 +1,9 @@
-module(epm_util).
-include("epm.hrl").
--export([ git/1
+-export([git/1
, home_dir/0, epm_home_dir/1, set_net_timeout/1, set_http_proxy/2
- ]).
+ , parse_erlang_term/1]).
git(Params) ->
os:cmd(string:join(["git"|Params], " ")) .
@@ -94,19 +94,19 @@ epm_home_dir(Home) ->
end
end.
-%% %% TODO: Bleeding eyes
-%% eval(Str) ->
-%% case erl_scan:string(Str) of
-%% {ok, Tokens, _} ->
-%% case erl_parse:parse_exprs(Tokens) of
-%% {ok, Forms} ->
-%% {value, Terms, _} = erl_eval:exprs(Forms, []),
-%% Terms;
-%% _ -> error
-%% end;
-%% _ -> error
-%% end.
-%%
+%% TODO: Bleeding eyes
+parse_erlang_term(Str) ->
+ case erl_scan:string(Str) of
+ {ok, Tokens, _} ->
+ case erl_parse:parse_exprs(Tokens) of
+ {ok, Forms} ->
+ {value, Terms, _} = erl_eval:exprs(Forms, []),
+ Terms;
+ _ -> error
+ end;
+ _ -> error
+ end.
+
%% %% TODO: Bleeding eyes
%% add_to_path(InstallDir) ->
%% case file:list_dir(InstallDir) of
View
@@ -23,7 +23,7 @@ get_source(Pkg, DestDir) when ?IS_PKG(Pkg) ->
?EPM_FAIL("[index error] repository was set, but not found for package ~s"
, [epm:as_string(Pkg)]);
Repo ->
- epm:p("repo ~p", [Repo]),
+ %% epm:p("[debug] repo ~p~n", [Repo]),
ApiMod = Repo#repo.api_module,
ApiMod:get_source(Pkg, DestDir)
end.
@@ -36,4 +36,4 @@ install_dir_name(Pkg) when ?IS_PKG(Pkg) ->
A = pkgid:author(Id),
N = pkgid:pkg_name(Id),
#repo{short_name=RepoSN} = epm_index:get_repo(RepoId),
- epm:s("~s.~s.~s", [N, A, RepoSN]).
+ epm:s("~s.~s.~s", [N, A, RepoSN]).

0 comments on commit f631daa

Please sign in to comment.