Permalink
Browse files

huge refact

  • Loading branch information...
1 parent 06cd768 commit 682dcdce54aca70b1003390442eba3fca255e87a Dmytro Lytovchenko committed Feb 8, 2014
Showing with 345 additions and 324 deletions.
  1. +2 −1 .gitignore
  2. +1 −1 Makefile
  3. +46 −22 include/epm.hrl
  4. +34 −11 src/epm.erl
  5. +30 −36 src/epm_core.erl
  6. +60 −58 src/epm_deps.erl
  7. +6 −8 src/epm_index.erl
  8. +133 −155 src/epm_ops.erl
  9. +33 −32 src/epm_package.erl
View
@@ -5,4 +5,5 @@ ebin/*
epm
*.iml
.idea
-*.plt
+*.plt
+*.log
View
@@ -9,7 +9,7 @@ PLT_LIBS0 = ebin $(wildcard deps/*/ebin)
PLT_LIBS = $(subst deps/riak_pb/ebin,,$(PLT_LIBS0))
DIALYZER_APPS = epm
-DIALYZER_APPS_PATHS = ebin
+DIALYZER_APPS_PATHS = $(wildcard ebin/*.beam)
#$(addsuffix /ebin, $(addprefix apps/, $(DIALYZER_APPS)))
.PHONY: check_plt
View
@@ -3,30 +3,54 @@
-define(DEFAULT_API_MODULES, [github_api]).
-define(epm_index_filename, "epm_index").
+-define(any_author, any_author).
+-define(any_vsn, any_vsn).
+
-define(EXIT(Format, Args), exit(lists:flatten(io_lib:format(Format, Args)))).
+-type platform() :: x86 | x64.
+-type erlangvsn() :: binary().
+
+-record(repoid, { name :: string()
+ }).
+-type repoid() :: #repoid{}.
+
+%% Unified global identifier for package
+-record(pkgid, { author :: string()
+ , pkg_name :: string()
+ , platform :: platform()
+ , vsn :: string()
+ , erlang_vsn :: erlangvsn()
+ }).
+-type pkgid() :: #pkgid{}.
+
+-record(repo, { id :: repoid()
+ , description :: string()
+ , url :: string()
+ %, followers
+ %, pushed
+ , api_module
+ }).
+-type repo() :: #repo{}.
+
+-record(pkg, { id :: pkgid()
+ %, vsn=undefined :: string()
+ , install_dir :: string()
+ , deps=[] :: [pkgid()]
+ , args=[] :: list()
+ , repo :: repoid()
+ }).
+-type pkg() :: #pkg{}.
+
+-record(installed_pkg, { id :: pkgid()
+ , repository :: repoid()
+ , platform :: platform()
+ }).
+-type installed_pkg() :: #installed_pkg{}.
%% State of the application, contains loaded local index, installed apps and
%% remote index
--record(epm_state, { local_available = []
- , installed = []
- , remote_available = []
+-record(epm_state, { local_available=[] :: [pkg()]
+ , installed=[] :: [installed_pkg()]
+ , remote_available=[] :: [pkg()]
+ , repositories=[] :: [repo()]
}).
-
--record(epm_repo, { name
- , owner
- , description
- , homepage
- , followers
- , pushed
- , api_module
- }).
-
--record(epm_package, {user
- , name
- , vsn=undefined
- , app_vsn
- , install_dir
- , deps=[]
- , args=[]
- , repo=#epm_repo{}
- }).
View
@@ -1,21 +1,20 @@
-module(epm).
--export([main/1]).
+-export([main/1
+ , author/1, name/1, vsn/1, erlang_vsn/1, as_string/1, equals/2]).
+
-include("epm.hrl").
main(Args) ->
application:load(sasl),
application:set_env(sasl, sasl_error_logger, false),
- lists:map(fun application:start/1, [sasl, crypto, public_key, ssl, ibrowse, epm]),
+ lists:map(fun application:start/1
+ , [sasl, crypto, public_key, ssl, ibrowse, epm]),
case (catch main_internal(Args)) of
- {'EXIT', ErrorMsg} when is_list(ErrorMsg) ->
- io:format("- ~s~n", [ErrorMsg]);
- {'EXIT', Other} ->
- io:format("~p~n", [Other]);
- _ ->
- ok
+ {'EXIT', Msg} when is_list(Msg) -> io:format("- ~s~n", [Msg]);
+ {'EXIT', Other} -> io:format("~p~n", [Other]);
+ _ -> ok
end,
-
epm_index:close(),
io:format("~n").
@@ -24,10 +23,34 @@ main_internal(Args) ->
Home = epm_util:home_dir(),
EpmHome = epm_util:epm_home_dir(Home),
State = epm_index:open(Home, EpmHome),
- setup_connectivity(),
+ setup_proxy(),
epm_core:execute(State, Args).
-setup_connectivity() ->
+setup_proxy() ->
epm_util:set_http_proxy( epm_cfg:get(proxy_host, none)
, epm_cfg:get(proxy_port, none)),
epm_util:set_net_timeout(epm_cfg:get(net_timeout, 6000)).
+
+%%------------------------------------------------------------------------------
+author(#pkg{id=#pkgid{author=X}}) -> X.
+
+name(#pkg{id=#pkgid{pkg_name=X}}) -> X;
+name(#repo{id=#repoid{name=X}}) -> X.
+
+vsn(#pkg{id=#pkgid{vsn=X}}) -> X.
+
+platform(#pkg{id=#pkgid{platform=X}}) -> X.
+
+erlang_vsn(#pkg{id=#pkgid{erlang_vsn=X}}) -> X.
+
+as_string(#pkgid{author=A, pkg_name=N, vsn=V, platform=P, erlang_vsn=E}) ->
+ lists:flatten(io_lib:format("~s/~s/~s ~s/~s", [A,N,V, P,E]));
+as_string(#repo{id=I, description=_D, url=U}) ->
+ lists:flatten(io_lib:format("Repo ~s url=~s", [I, U])).
+
+equals(#pkgid{}=P1, #pkgid{}=P2) ->
+ (author(P1) == author(P2) orelse author(P2) =:= ?any_author)
+ andalso (name(P1) == name(P2))
+ andalso (vsn(P1) == vsn(P2))
+ andalso (erlang_vsn(P1) == vsn(P2))
+ andalso (platform(P1) == platform(P2)).
View
@@ -18,14 +18,12 @@ execute(State=#epm_state{}, ["install" | Args]) ->
io:format("===============================~n"),
io:format("Packages already installed:~n"),
io:format("===============================~n"),
- [io:format(" + ~s-~s-~s (~s)~n", [U, N, V, AppVsn])
- || #epm_package{user = U, name = N, vsn = V, app_vsn = AppVsn} <- Installed]
+ [io:format(" + ~s~n", [epm:as_string(P)]) || P <- Installed]
end,
io:format("===============================~n"),
io:format("Install the following packages?~n"),
io:format("===============================~n"),
- [io:format(" + ~s-~s-~s~n", [U, N, V])
- || #epm_package{user = U, name = N, vsn = V} <- NotInstalled],
+ [io:format(" + ~s~n", [epm:as_string(P)]) || P <- NotInstalled],
io:format("~n([y]/n) "),
case io:get_chars("", 1) of
C when C == "y"; C == "\n" ->
@@ -47,8 +45,7 @@ execute(State=#epm_state{}, ["remove" | Args]) ->
io:format("===============================~n"),
io:format("Remove the following packages?~n"),
io:format("===============================~n"),
- [io:format(" + ~s-~s-~s~n", [U, N, V])
- || #epm_package{user = U, name = N, vsn = V} <- Installed],
+ [io:format(" + ~s~n", [epm:as_string(P)]) || P <- Installed],
io:format("~n([y]/n) "),
case io:get_chars("", 1) of
C when C == "y"; C == "\n" ->
@@ -70,8 +67,7 @@ execute(State=#epm_state{}, ["update" | Args]) ->
io:format("===============================~n"),
io:format("Update the following packages?~n"),
io:format("===============================~n"),
- [io:format(" + ~s-~s-~s~n", [U, N, V])
- || #epm_package{user = U, name = N, vsn = V} <- Installed],
+ [io:format(" + ~s~n", [epm:as_string(P)]) || P <- Installed],
io:format("~n([y]/n) "),
case io:get_chars("", 1) of
C when C == "y"; C == "\n" ->
@@ -209,15 +205,16 @@ execute(_State=#epm_state{}, _) ->
%% parse input args
%% -----------------------------------------------------------------------------
-%% collect_args(Target, Args, GlobalConfig) -> Results
-%% Target = atom()
-%% Args = [string()]
-%%` GlobalConfig = list()
-%% Results = {[package(), Flags]}
-%% Flags = [atom()]
+-spec collect_args(Target :: atom(), Args :: [string()])
+ -> {[#pkgid{}], [atom()]}.
collect_args(Target, Args) ->
collect_args_internal(Target, Args, [], []).
+-spec collect_args_internal(Target :: atom()
+ , Args :: [string()]
+ , Packages :: [#pkgid{}]
+ , Flags :: [atom()])
+ -> {[#pkgid{}], [atom()]}.
collect_args_internal(_, [], Packages, Flags) ->
{lists:reverse(Packages), lists:reverse(Flags)};
collect_args_internal(Target, [Arg | Rest], Packages, Flags) ->
@@ -226,43 +223,40 @@ collect_args_internal(Target, [Arg | Rest], Packages, Flags) ->
%% split into user and project
{ProjectName, User} = epm_ops:split_package(Arg),
collect_args_internal(Target, Rest
- , [#epm_package{user = User, name = ProjectName}|Packages]
+ , [#pkgid{author=User, pkg_name=ProjectName}|Packages]
, Flags);
{Type, Tag, 0} -> %% tag with no trailing value
case Type of
project ->
- [#epm_package{args = Args} = Package|OtherPackages] = Packages,
+ [#pkg{args = Args} = Package|OtherPackages] = Packages,
collect_args_internal(Target, Rest
- , [Package#epm_package{args = Args ++ [Tag]}|OtherPackages]
+ , [Package#pkg{args = Args ++ [Tag]}|OtherPackages]
, Flags);
global ->
collect_args_internal(Target, Rest, Packages, [Tag|Flags])
end;
{Type, Tag, NumVals} when is_integer(NumVals) -> % tag with trailing value(s)
- if
- length(Rest) < NumVals ->
+ if length(Rest) < NumVals ->
exit("poorly formatted command");
true -> ok
end,
{Vals, Rest1} = lists:split(NumVals, Rest),
- Vals1 =
- case Vals of
- [V] -> V;
- _ -> Vals
- end,
+ Vals1 = case Vals of
+ [V] -> V;
+ _ -> Vals
+ end,
case Type of
- project ->
- %% this tag applies to the last project on the stack
- [#epm_package{args = Args} = Package|OtherPackages] = Packages,
- Vsn = if
- Tag == tag; Tag == branch; Tag == sha -> Vals1;
- true -> Package#epm_package.vsn
- end,
- collect_args_internal( Target, Rest1
- , [Package#epm_package{ vsn = Vsn
- , args = Args ++ [{Tag, Vals1}]
- } | OtherPackages]
- , Flags);
+%% project ->
+%% %% this tag applies to the last project on the stack
+%% [#pkg{args=Args}=Package | OtherPackages] = Packages,
+%% Vsn = if Tag == tag; Tag == branch; Tag == sha -> Vals1;
+%% true -> Package#pkg.vsn
+%% end,
+%% collect_args_internal( Target, Rest1
+%% , [Package#pkg{ vsn = Vsn
+%% , args = Args ++ [{Tag, Vals1}]
+%% } | OtherPackages]
+%% , Flags);
global ->
if Tag == config_set ->
[K, V1] = Vals1,
Oops, something went wrong.

0 comments on commit 682dcdc

Please sign in to comment.