Skip to content
Browse files

dialyzed

  • Loading branch information...
1 parent 682dcdc commit 8370e0292013531db4632752c9779e9841e9c896 Dmytro Lytovchenko committed Feb 8, 2014
Showing with 74 additions and 73 deletions.
  1. +6 −6 include/epm.hrl
  2. +30 −12 src/epm.erl
  3. +13 −13 src/epm_core.erl
  4. +1 −1 src/epm_deps.erl
  5. +22 −36 src/epm_index.erl
  6. +2 −5 src/epm_ops.erl
View
12 include/epm.hrl
@@ -1,25 +1,25 @@
-define(epm_version, "1.0.0-dev").
-define(epm_year, 2014).
-define(DEFAULT_API_MODULES, [github_api]).
--define(epm_index_filename, "epm_index").
-define(any_author, any_author).
-define(any_vsn, any_vsn).
+-define(any_platform, any_platform).
-define(EXIT(Format, Args), exit(lists:flatten(io_lib:format(Format, Args)))).
--type platform() :: x86 | x64.
+-type platform() :: x86 | x64 | ?any_platform.
-type erlangvsn() :: binary().
-record(repoid, { name :: string()
}).
-type repoid() :: #repoid{}.
%% Unified global identifier for package
--record(pkgid, { author :: string()
+-record(pkgid, { author=?any_author :: string() | ?any_author
, pkg_name :: string()
- , platform :: platform()
- , vsn :: string()
- , erlang_vsn :: erlangvsn()
+ , platform=?any_platform :: platform()
+ , vsn=?any_vsn :: string() | ?any_vsn
+ , erlang_vsn=?any_vsn :: erlangvsn() | ?any_vsn
}).
-type pkgid() :: #pkgid{}.
View
42 src/epm.erl
@@ -1,6 +1,12 @@
-module(epm).
-export([main/1
- , author/1, name/1, vsn/1, erlang_vsn/1, as_string/1, equals/2]).
+ , author/1
+ , name/1
+ , vsn/1
+ , erlang_vsn/1
+ , as_string/1
+ , equals/2
+ , platform/1]).
-include("epm.hrl").
@@ -32,25 +38,37 @@ setup_proxy() ->
epm_util:set_net_timeout(epm_cfg:get(net_timeout, 6000)).
%%------------------------------------------------------------------------------
-author(#pkg{id=#pkgid{author=X}}) -> X.
+author(#pkg{id=#pkgid{author=X}}) -> X;
+author(#pkgid{author=X}) -> X.
name(#pkg{id=#pkgid{pkg_name=X}}) -> X;
+name(#pkgid{pkg_name=X}) -> X;
name(#repo{id=#repoid{name=X}}) -> X.
-vsn(#pkg{id=#pkgid{vsn=X}}) -> X.
+vsn(#pkg{id=#pkgid{vsn=X}}) -> X;
+vsn(#pkgid{vsn=X}) -> X.
-platform(#pkg{id=#pkgid{platform=X}}) -> X.
+platform(#pkg{id=#pkgid{platform=X}}) -> X;
+platform(#pkgid{platform=X}) -> X.
-erlang_vsn(#pkg{id=#pkgid{erlang_vsn=X}}) -> X.
+erlang_vsn(#pkg{id=#pkgid{erlang_vsn=X}}) -> X;
+erlang_vsn(#pkgid{erlang_vsn=X}) -> X.
+%%------------------------------------------------------------------------------
+as_string(#pkg{id=Id}) -> as_string(Id);
+as_string(#pkgid{author=?any_author, pkg_name=N, vsn=V, platform=P, erlang_vsn=E}) ->
+ lists:flatten(io_lib:format("Package ~s/~s ~s/~s", [N,V, P,E]));
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]));
+ lists:flatten(io_lib:format("Package by ~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])).
+ lists:flatten(io_lib:format("Repo ~s url=~s", [I, U]));
+as_string(#repoid{name=N}) ->
+ lists:flatten(io_lib:format("Repo id ~s", [N]));
+as_string(undefined) -> "undefined".
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)).
+ (author(P1) =:= author(P2) orelse author(P2) =:= ?any_author)
+ andalso (name(P1) =:= name(P2))
+ andalso (vsn(P1) =:= vsn(P2) orelse vsn(P1) =:= ?any_vsn)
+ andalso (erlang_vsn(P1) =:= erlang_vsn(P2) orelse erlang_vsn(P1) =:= ?any_vsn)
+ andalso (platform(P1) =:= platform(P2)).
View
26 src/epm_core.erl
@@ -88,15 +88,15 @@ execute(State=#epm_state{}, ["info" | Args]) ->
io:format("INSTALLED~n"),
io:format("===============================~n"),
- lists:foldl(
- fun(Package, Count) ->
- case Count of
- 0 -> ok;
- _ -> io:format("~n")
+ F = fun(Package=#pkg{}, Count) ->
+ case Count of
+ 0 -> ok;
+ _ -> io:format("~n")
+ end,
+ epm_ops:print_installed_package_info(Package),
+ Count + 1
end,
- epm_ops:print_installed_package_info(Package),
- Count + 1
- end, 0, lists:reverse(Installed))
+ lists:foldl(F, 0, lists:reverse(Installed))
end,
case NotInstalled of
@@ -227,11 +227,11 @@ collect_args_internal(Target, [Arg | Rest], Packages, Flags) ->
, Flags);
{Type, Tag, 0} -> %% tag with no trailing value
case Type of
- project ->
- [#pkg{args = Args} = Package|OtherPackages] = Packages,
- collect_args_internal(Target, Rest
- , [Package#pkg{args = Args ++ [Tag]}|OtherPackages]
- , Flags);
+%% project ->
+%% [#pkg{args = Args} = Package|OtherPackages] = Packages,
+%% collect_args_internal(Target, Rest
+%% , [Package#pkg{args = Args ++ [Tag]}|OtherPackages]
+%% , Flags);
global ->
collect_args_internal(Target, Rest, Packages, [Tag|Flags])
end;
View
2 src/epm_deps.erl
@@ -17,7 +17,7 @@
package_dependencies(Packages) ->
_RepoPlugins = epm_cfg:get(repo_plugins, ?DEFAULT_API_MODULES),
G = digraph:new(),
- UpdatedPackages = [],
+ UpdatedPackages = dict:new(),
%% UpdatedPackages = package_dependencies_internal(
%% Packages, RepoPlugins, G, undefined, dict:new()),
Deps = digraph_utils:topsort(G),
View
58 src/epm_index.erl
@@ -17,48 +17,24 @@
-include("epm.hrl").
--define(local_index, epm_index).
+-define(local_index, epm_local_index).
+-define(local_index_file, "epm_local_index").
+
+-define(global_index, epm_index).
+-define(global_index_file, "epm_index").
%%------------------------------------------------------------------------------
close() ->
- dets:close(?local_index).
-
-open(Home, EpmHome) ->
- File = filename:join([EpmHome, ?epm_index_filename]),
+ dets:close(?local_index),
+ dets:close(?global_index).
- %% TODO: delete this later
- Insert =
- case filelib:is_regular(filename:join([Home, ?epm_index_filename])) of
- true ->
- DetsPath = filename:join([Home, ?epm_index_filename]),
- case dets:open_file(?local_index, [{type, set}, {file, DetsPath}]) of
- {ok, _} ->
- Rows = dets:match(?local_index, '$1'),
- dets:close(?local_index),
+open(_Home, EpmHome) ->
+ LocalIndexFile = ?local_index_file,
+ open_dets_file(LocalIndexFile, ?local_index),
- [{{User, Name, Vsn}
- , #pkg{ id = #pkgid{author=User, pkg_name=Name, vsn=Vsn}
- , install_dir = InstallDir
- , deps = Deps
- %, repo = github_api:info(User, Name)
- }}
- || [{{User, Name, Vsn}, InstallDir, Deps}] <- Rows];
- _ -> []
- end;
- false -> []
- end,
+ IndexFile = filename:join([EpmHome, ?global_index_file]),
+ open_dets_file(IndexFile , ?global_index),
- case dets:open_file(?local_index, [{type, set}, {file, File}]) of
- {ok, _} ->
- %% TODO: delete this later
- [dets:insert(?local_index, I) || I <- Insert],
- file:delete(filename:join([Home, ?epm_index_filename])),
- ok;
- {error, {file_error, _, eacces}} ->
- ?EXIT("insufficient access to epm index file: ~s", [File]);
- {error, Reason} ->
- ?EXIT("failed to open epm index file (~s): ~p", [File, Reason])
- end,
State = #epm_state{},
State.
@@ -74,3 +50,13 @@ delete_local(Key={_User, _Name, _Vsn}) ->
insert_local(Key={_User, _Name, _Vsn}, Package=#pkg{}) ->
dets:insert(?local_index, {Key, Package}).
+
+%% @private
+open_dets_file(File, Table) ->
+ case dets:open_file(Table, [{type, set}, {file, File}]) of
+ {ok, _} -> ok;
+ {error, {file_error, _, eacces}} ->
+ ?EXIT("insufficient access to epm index file: ~s", [File]);
+ {error, Reason} ->
+ ?EXIT("failed to open epm index file (~s): ~p", [File, Reason])
+ end.
View
7 src/epm_ops.erl
@@ -208,11 +208,8 @@ print_installed_package_info(Package) ->
case Package#pkg.deps of
[] -> ok;
Deps ->
- io:format(" dependencies: ~n ~s~n", [string:join([
- case U of
- none -> lists:flatten(io_lib:format("~s/~s", [N,V]));
- _ -> lists:flatten(io_lib:format("~s/~s/~s", [U,N,V]))
- end || {U,N,V} <- Deps], "\n ")])
+ io:format(" dependencies: ~n ~s~n",
+ [string:join(lists:map(fun epm:as_string/1, Deps), "\n ")])
end.
print_not_installed_package_info(State=#epm_state{}, Packages) ->

0 comments on commit 8370e02

Please sign in to comment.
Something went wrong with that request. Please try again.