Browse files

command line flags, help

  • Loading branch information...
1 parent 2976ccf commit a95775638aafb47aa1815ce815d38abbbe78abc0 Dmytro Lytovchenko committed Feb 9, 2014
Showing with 362 additions and 296 deletions.
  1. +4 −0 Makefile
  2. +16 −11 include/epm.hrl
  3. +15 −2 src/epm.erl
  4. +23 −0 src/epm_api_github.erl
  5. +75 −77 src/epm_core.erl
  6. +9 −2 src/epm_deps.erl
  7. +37 −31 src/epm_ops.erl
  8. +167 −161 src/epm_util.erl
  9. +16 −12 src/{api_behavior.erl → gen_epm_api.erl}
View
4 Makefile
@@ -2,6 +2,10 @@
compile:
rebar get-deps compile escriptize
+.PHONY: clean
+clean:
+ rm ebin/* *.log
+
#-------------------------------------------------------------------------------
OTP_PLT = .epm_otp.plt
COMBO_PLT = .epm_combo.plt
View
27 include/epm.hrl
@@ -2,36 +2,41 @@
-define(epm_year, 2014).
-define(DEFAULT_API_MODULES, [github_api]).
--define(any_author, any_author).
--define(any_platform, any_platform).
--define(any_vsn, any_vsn).
--define(any_erlang_vsn, any_erlang_vsn).
+-define(any_name, any_n).
+-define(any_author, any_a).
+-define(any_platform, any_p).
+-define(any_vsn, any_v).
+-define(any_erlang_vsn, any_e).
-define(EPM_FAIL(Format, Args), begin exit({error, epm:s(Format, Args)}) end).
-define(EPM_EXIT(Format, Args), begin exit({ok, epm:s(Format, Args)}) end).
-type platform() :: x86 | x64 | ?any_platform.
-type erlangvsn() :: binary().
+-type api_module() :: epm_api_github.
+-type pkg_arg() :: source | {tag|branch|hash, string()}.
-record(repoid, { name :: string()
}).
-type repoid() :: #repoid{}.
%% Unified global identifier for package
--record(pkgid, { author=?any_author :: string() | ?any_author
- , pkg_name :: string()
- , platform=?any_platform :: platform()
- , vsn=?any_vsn :: string() | ?any_vsn
- , erlang_vsn=?any_erlang_vsn :: erlangvsn() | ?any_erlang_vsn
- }).
+-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{}.
-record(repo, { id :: repoid()
, description :: string()
, url :: string()
%, followers
%, pushed
- , api_module
+ , api_module=epm_api_github :: api_module()
}).
-type repo() :: #repo{}.
View
17 src/epm.erl
@@ -8,7 +8,7 @@
, matches/2
, platform/1
, p/3, p/2, p/1
- , s/2, pkgid_match_spec/1]).
+ , s/2, pkgid_match_spec/1, args/1, arg_bool/2, arg/2, set_arg_bool/3]).
-include("epm.hrl").
-include_lib("stdlib/include/ms_transform.hrl").
@@ -58,15 +58,28 @@ platform(#pkgid{platform=X}) -> X.
erlang_vsn(#pkg{id=#pkgid{erlang_vsn=X}}) -> X;
erlang_vsn(#pkgid{erlang_vsn=X}) -> X.
+args(#pkgid{args=X}) -> X.
+
+arg_bool(Arg, #pkgid{args=X}) -> lists:member(Arg, X).
+
+arg(Arg, #pkgid{args=X}) -> proplists:get_value(Arg, X).
+
+set_arg_bool(Arg, false, #pkgid{args=Args}=Pkgid) ->
+ Pkgid#pkgid{args = lists:delete(Arg, Args)};
+set_arg_bool(Arg, true, #pkgid{args=Args}=Pkgid) ->
+ Pkgid#pkgid{args = [Arg | lists:delete(Arg, Args)]}.
+
%%------------------------------------------------------------------------------
as_string(#pkg{id=Id}) -> as_string(Id);
-as_string(#pkgid{author=A, pkg_name=N, vsn=V, platform=P, erlang_vsn=E}) ->
+as_string(#pkgid{ author=A, pkg_name=N, vsn=V, platform=P, erlang_vsn=E
+ , args=Args}) ->
"["
++ case A of ?any_author -> ""; _ -> s("~s/", [A]) end
++ N
++ case V of ?any_vsn -> ""; _ -> s(", ~s", [V]) end
++ case P of ?any_platform -> ""; _ -> s(", ~s", [P]) end
++ case E of ?any_erlang_vsn -> ""; _ -> s(", ~s", [E]) end
+ ++ case Args of [] -> ""; _ -> s(" ~p", [Args]) end
++ "]";
as_string(#repo{id=I, description=_D, url=U}) ->
s("[Repo ~s url=~s]", [I, U]);
View
23 src/epm_api_github.erl
@@ -0,0 +1,23 @@
+%%%-------------------------------------------------------------------
+%%% @author Dmytro Lytovchenko <dmytro.lytovchenko@gmail.com>
+%%% @doc Handles Github repositories
+%%% @end
+%%% Created : 09. Feb 2014 8:16 PM
+%%%-------------------------------------------------------------------
+-module(epm_api_github).
+-behaviour(gen_epm_api).
+
+%% API
+-export([get_source/2]).
+
+-include("epm.hrl").
+
+-spec get_source(Pkg :: pkg(), DestDir :: string()) -> ok | {error, any()}.
+get_source(Pkg=#pkg{id=#pkgid{author=A, pkg_name=N}}, DestDir) ->
+ Url = get_vcs_url(Pkg),
+ epm_util:git(["clone", Url, DestDir ++ epm:s("/~s_~s", [A, N])]).
+
+get_vcs_url(#pkg{id=#pkgid{author=?any_author}}) -> {error, author};
+get_vcs_url(#pkg{id=#pkgid{pkg_name=?any_name}}) -> {error, pkg_name};
+get_vcs_url(#pkg{id=#pkgid{author=A, pkg_name=N}}) ->
+ epm:s("https://github.com/~s/~s.git", [A, N]).
View
152 src/epm_core.erl
@@ -151,51 +151,50 @@ execute(_State=#epm_state{}, ["config" | Args]) ->
end;
execute(_State=#epm_state{}, _) ->
- io:format("Usage: epm commands~n~n"),
- io:format(" install [<user>/]<project> {project options}, ... {global options}~n"),
- io:format(" project options:~n"),
- io:format(" --tag <tag>~n"),
- io:format(" --branch <branch>~n"),
- io:format(" --sha <sha>~n"),
- io:format(" --with-deps (default)~n"),
- io:format(" --without-deps~n"),
- io:format(" --prebuild-command <cmd>~n"),
- io:format(" --build-command <cmd>~n"),
- io:format(" --test-command <cmd>~n"),
- io:format(" global options:~n"),
- io:format(" --verbose~n"),
- io:format(" --config-set <key> <value>~n~n"),
- io:format(" remove [<user>/]<project> {project options}, ... {global options}~n"),
- io:format(" project options:~n"),
- io:format(" --tag <tag>~n"),
- io:format(" --branch <branch>~n"),
- io:format(" --sha <sha>~n"),
- io:format(" global options:~n"),
- io:format(" --verbose~n~n"),
- io:format(" --config-set <key> <value>~n~n"),
- io:format(" update [<user>/]<project> {project options}, ... {global options}~n"),
- io:format(" project options:~n"),
- io:format(" --tag <tag>~n"),
- io:format(" --branch <branch>~n"),
- io:format(" --sha <sha>~n"),
- io:format(" --with-deps~n"),
- io:format(" --without-deps (default)~n"),
- io:format(" global options:~n"),
- io:format(" --verbose~n~n"),
- io:format(" --config-set <key> <value>~n~n"),
- io:format(" info [<user>/]<project>, ... {global options}~n"),
- io:format(" global options:~n"),
- io:format(" --config-set <key> <value>~n~n"),
- io:format(" search <project>, ... {global options}~n"),
- io:format(" global options:~n"),
- io:format(" --config-set <key> <value>~n~n"),
- io:format(" list~n~n"),
- io:format(" latest~n~n"),
- io:format(" config {options}~n"),
- io:format(" options:~n"),
- io:format(" --get (default)~n"),
- io:format(" --set <key> <value>~n"),
- io:format(" --remove <key>~n"),
+ epm:p("Usage: epm commands~n~n"
+ " install [<author>/]<project> {project options}, ... {global options}~n"
+ " project options:~n"
+ " --source :: requests source install (does not build)~n"
+ " --platform x86|x64, --vsn <v>, --tag <t>, --branch <b>, --hash <h>~n"
+%% " --with-deps (default)~n"
+%% " --without-deps~n"
+%% " --prebuild-command <cmd>~n"
+%% " --build-command <cmd>~n"
+%% " --test-command <cmd>~n"
+ " global options:~n"
+%% " --verbose~n"
+ " --config-set <key> <value>~n~n"
+%% " remove [<user>/]<project> {project options}, ... {global options}~n"
+%% " project options:~n"
+%% " --tag <tag>~n"
+%% " --branch <branch>~n"
+%% " --sha <sha>~n"
+%% " global options:~n"
+%% " --verbose~n~n"
+%% " --config-set <key> <value>~n~n"
+%% " update [<user>/]<project> {project options}, ... {global options}~n"
+%% " project options:~n"
+%% " --tag <tag>~n"
+%% " --branch <branch>~n"
+%% " --sha <sha>~n"
+%% " --with-deps~n"
+%% " --without-deps (default)~n"
+%% " global options:~n"
+%% " --verbose~n~n"
+%% " --config-set <key> <value>~n~n"
+%% " info [<user>/]<project>, ... {global options}~n"
+%% " global options:~n"
+%% " --config-set <key> <value>~n~n"
+%% " search <project>, ... {global options}~n"
+%% " global options:~n"
+%% " --config-set <key> <value>~n~n"
+%% " list~n~n"
+%% " latest~n~n"
+ " config {options}~n"
+ " options:~n"
+ " --get (default)~n"
+ " --set <key> <value>~n"
+ " --remove <key>~n"),
ok.
%% -----------------------------------------------------------------------------
@@ -209,32 +208,32 @@ collect_args(Target, Args) ->
-spec collect_args_internal(Target :: atom()
, Args :: [string()]
- , Packages :: [#pkgid{}]
+ , Pkgids :: [#pkgid{}]
, Flags :: [atom()])
-> {[#pkgid{}], [atom()]}.
collect_args_internal(_, [], Packages, Flags) ->
{lists:reverse(Packages), lists:reverse(Flags)};
-collect_args_internal(Target, [Arg | Rest], Packages, Flags) ->
+collect_args_internal(Target, [Arg | Rest], Pkgids, Flags) ->
case parse_tag(Target, Arg) of
undefined -> %% if not a tag then must be a project name
%% split into user and project
{ProjectName, User} = epm_ops:split_package(Arg),
collect_args_internal(Target, Rest
- , [#pkgid{author=User, pkg_name=ProjectName}|Packages]
+ , [#pkgid{author=User, pkg_name=ProjectName}|Pkgids]
, 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 ->
+ %% Update head of Pkgids with additional arg
+ [#pkgid{args=Args} = Pkgid|Tail] = Pkgids,
+ Pkgid1 = Pkgid#pkgid{ args = Args ++ [Tag] },
+ collect_args_internal(Target, Rest, [Pkgid1 | Tail], Flags);
global ->
- collect_args_internal(Target, Rest, Packages, [Tag|Flags])
+ collect_args_internal(Target, Rest, Pkgids, [Tag|Flags])
end;
{Type, Tag, NumVals} when is_integer(NumVals) -> % tag with trailing value(s)
if length(Rest) < NumVals ->
- exit("poorly formatted command");
+ ?EPM_FAIL("poorly formatted command", []);
true -> ok
end,
{Vals, Rest1} = lists:split(NumVals, Rest),
@@ -243,17 +242,15 @@ collect_args_internal(Target, [Arg | Rest], Packages, Flags) ->
_ -> Vals
end,
case Type of
-%% 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);
+ project ->
+ %% Update head of Pkgids with additional arg
+ %% this tag applies to the last project on the stack
+ [#pkgid{args=Args}=Pkgid | Tail] = Pkgids,
+ Vsn = if Tag == tag; Tag == branch; Tag == hash -> Vals1;
+ true -> Pkgid#pkgid.vsn
+ end,
+ Pkgid2 = Pkgid#pkgid{ vsn = Vsn, args = Args ++ [{Tag, Vals1}] },
+ collect_args_internal( Target, Rest1, [Pkgid2 | Tail], Flags);
global ->
if Tag == config_set ->
[K, V1] = Vals1,
@@ -264,7 +261,7 @@ collect_args_internal(Target, [Arg | Rest], Packages, Flags) ->
end;
true -> ok
end,
- collect_args_internal(Target, Rest1, Packages, [{Tag, Vals1}|Flags])
+ collect_args_internal(Target, Rest1, Pkgids, [{Tag, Vals1}|Flags])
end
end.
@@ -273,19 +270,20 @@ collect_args_internal(Target, [Arg | Rest], Packages, Flags) ->
%% Arg = string()
%% Tag = atom()
%% HasValue = bool()
+parse_tag(install, "--source") -> {project, source, 0};
parse_tag(install, "--tag") -> {project, tag, 1};
parse_tag(install, "--branch") -> {project, branch, 1};
-parse_tag(install, "--sha") -> {project, sha, 1};
-parse_tag(install, "--prebuild-command") -> {project, prebuild_command, 1};
-parse_tag(install, "--build-command") -> {project, build_command, 1};
-parse_tag(install, "--test-command") -> {project, test_command, 1};
+parse_tag(install, "--hash") -> {project, hash, 1};
+%% parse_tag(install, "--prebuild-command") -> {project, prebuild_command, 1};
+%% parse_tag(install, "--build-command") -> {project, build_command, 1};
+%% parse_tag(install, "--test-command") -> {project, test_command, 1};
-parse_tag(info, "--tag") -> {project, tag, 1};
-parse_tag(info, "--branch") -> {project, branch, 1};
-parse_tag(info, "--sha") -> {project, sha, 1};
+%% parse_tag(info, "--tag") -> {project, tag, 1};
+%% parse_tag(info, "--branch") -> {project, branch, 1};
+%% parse_tag(info, "--sha") -> {project, sha, 1};
-parse_tag(_, "--with-deps") -> {project, with_deps, 0};
-parse_tag(_, "--without-deps") -> {project, without_deps, 0};
+%% parse_tag(_, "--with-deps") -> {project, with_deps, 0};
+%% parse_tag(_, "--without-deps") -> {project, without_deps, 0};
parse_tag(config, "--get") -> {global, get, 0};
parse_tag(config, "--set") -> {global, set, 2};
@@ -314,7 +312,7 @@ update_epm(_State) ->
{ok, {{_, 200, _}, _, Body}} ->
case file:write_file(File, Body) of
ok ->
- io:format("+ updated epm (~s) to latest version~n", [File]);
+ epm:p("+ updated epm (~s) to latest version~n", [File]);
{error, Reason} ->
exit(lists:flatten(io_lib:format("failed to overwrite epm executable ~s: ~p~n", [File, Reason])))
end;
View
11 src/epm_deps.erl
@@ -25,9 +25,16 @@ resolve_dependencies(Pkgids) ->
resolve_dependencies_internal(Pkgids, Pkgids) -> Pkgids;
resolve_dependencies_internal(Pkgids, _Previous) ->
F = fun(Pkgid=#pkgid{}, A) ->
+ SourceFlag = epm:arg_bool(source, Pkgid),
PkgList = epm_index:list_global_matching(Pkgid),
- lists:foldl(fun(Dep, A1) -> ordsets:add_element(Dep, A1) end
- , A, lists:flatten([Pkg#pkg.deps || Pkg <- PkgList]))
+ lists:foldl(fun(Dep, A1) ->
+ % source flag spreads over all deps
+ Dep1 = epm:set_arg_bool(source, SourceFlag, Dep),
+ ordsets:add_element(Dep1, A1)
+ end, A, lists:flatten([Pkg#pkg.deps || Pkg <- PkgList]))
end,
+ %% For all the package ids get matching packages (TODO: Get 1 best candidate)
+ %% and merge it with all the dependency ids
+
PkgidsPlusDeps = lists:foldl(F, ordsets:from_list(Pkgids), Pkgids),
resolve_dependencies_internal(PkgidsPlusDeps, Pkgids).
View
68 src/epm_ops.erl
@@ -20,7 +20,7 @@
, update_package/2
, remove_package/2
, install_package/2
- , install/3
+ %, install/3
]).
-include("epm.hrl").
@@ -30,7 +30,12 @@
-spec filter_installed_packages([#pkg{}]) ->
{[#pkg{}], [#pkg{}]}.
filter_installed_packages(Pkgids) ->
- lists:partition(fun(Id=#pkgid{}) -> epm_index:is_installed(Id) end, Pkgids).
+ {Installed, Not} = lists:partition(
+ fun(Id=#pkgid{}) -> epm_index:is_installed(Id) end
+ , Pkgids),
+ Installed1 = lists:map(fun(X) -> epm:set_arg_bool(source, false, X) end
+ , Installed),
+ {Installed1, Not}.
%% filter_installed_packages(Packages) ->
%% filter_installed_packages(Packages, [], []).
%%
@@ -339,32 +344,33 @@ install_package(State=#epm_state{}, #pkgid{}=Pkgid) ->
%epm_index:insert_local({User, Name, Vsn}, Package1),
State.
-install(ProjectName, Config, undefined) ->
- install(ProjectName, Config, code:lib_dir());
-
-install(ProjectName, _Config, LibDir) ->
- Vsn =
- case file:consult("ebin/" ++ ProjectName ++ ".app") of
- {ok, [{application, _, Props}]} ->
- proplists:get_value(vsn, Props);
- _ ->
- undefined
- end,
- Dir =
- case Vsn of
- undefined -> LibDir ++ "/" ++ ProjectName;
- _ -> LibDir ++ "/" ++ ProjectName ++ "-" ++ Vsn
- end,
- InstallCmd = "mkdir -p " ++ Dir ++ "; cp -R ./* " ++ Dir,
- io:format("+ running ~s install command~n", [ProjectName]),
- epm_util:print_cmd_output("~s~n", [InstallCmd]),
- epm_util:do_cmd(InstallCmd, fail),
- Ebin = Dir ++ "/ebin",
- case code:add_pathz(Ebin) of
- true -> ok;
- Err ->
- M = io_lib:format("failed to add path for ~s (~s): ~p"
- , [ProjectName, Ebin, Err]),
- exit(lists:flatten(M))
- end,
- Dir.
+%%---------------------------------------------------------------------------
+%% install(ProjectName, Config, undefined) ->
+%% install(ProjectName, Config, code:lib_dir());
+%%
+%% install(ProjectName, _Config, LibDir) ->
+%% Vsn =
+%% case file:consult("ebin/" ++ ProjectName ++ ".app") of
+%% {ok, [{application, _, Props}]} ->
+%% proplists:get_value(vsn, Props);
+%% _ ->
+%% undefined
+%% end,
+%% Dir =
+%% case Vsn of
+%% undefined -> LibDir ++ "/" ++ ProjectName;
+%% _ -> LibDir ++ "/" ++ ProjectName ++ "-" ++ Vsn
+%% end,
+%% InstallCmd = "mkdir -p " ++ Dir ++ "; cp -R ./* " ++ Dir,
+%% io:format("+ running ~s install command~n", [ProjectName]),
+%% epm_util:print_cmd_output("~s~n", [InstallCmd]),
+%% epm_util:do_cmd(InstallCmd, fail),
+%% Ebin = Dir ++ "/ebin",
+%% case code:add_pathz(Ebin) of
+%% true -> ok;
+%% Err ->
+%% M = io_lib:format("failed to add path for ~s (~s): ~p"
+%% , [ProjectName, Ebin, Err]),
+%% exit(lists:flatten(M))
+%% end,
+%% Dir.
View
328 src/epm_util.erl
@@ -1,7 +1,13 @@
-module(epm_util).
--compile(export_all).
-include("epm.hrl").
+-export([ git/1
+ , home_dir/0, epm_home_dir/1, set_net_timeout/1, set_http_proxy/2
+ ]).
+
+git(Params) ->
+ os:cmd(string:join(["git"|Params], " ")) .
+
home_dir() ->
case init:get_argument(home) of
{ok, [[H]]} -> [H];
@@ -20,61 +26,61 @@ set_net_timeout(Timeout) when is_list(Timeout) ->
set_net_timeout(Timeout) when is_integer(Timeout) ->
epm_cfg:set(net_timeout, Timeout).
-request_as_str(Url, Host) ->
- case http_request(Url, Host) of
- {ok, "200", _, Body} ->
- Body;
- {ok, "403", _, _} ->
- not_found;
- {ok, "404", _, _} ->
- not_found;
- {ok, _} ->
- request_failed;
- {error, Reason} ->
- io:format("timeout? ~p~n", [Reason]),
- Reason
- end.
-
-http_request(Url, Host) ->
- http_request(Url, Host, []).
-
-http_request(Url, Host, ClientOpts) ->
- Hdrs = make_headers(Host),
- Opts = http_options(ClientOpts),
- {ok, Timeout} = epm_cfg:get(net_timeout),
- case ibrowse:send_req(Url, Hdrs, get, [], Opts, Timeout) of
- {ok, "302", Headers, _} = Response ->
- case proplists:get_value("Location", Headers) of
- undefined ->
- Response;
- Location ->
- http_request(Location, undefined, ClientOpts)
- end;
- Other -> Other
- end.
-
-http_options(ClientOpts) ->
- proxy_options() ++ ClientOpts.
-
-proxy_options() ->
- case epm_cfg:get(proxy_host) of
- {error, not_found} -> [];
- {ok, Host} ->
- Port = case epm_cfg:get(proxy_port) of
- {error, not_found} -> 8080;
- {ok, PortNum} -> PortNum
- end,
- [{proxy_host, Host}, {proxy_port, Port}]
- end.
-
-make_headers(undefined) ->
- [{"User-Agent", "Erlang EPM v" ++ ?epm_version}];
-make_headers(Host) ->
- [{"User-Agent", "Erlang EPM v" ++ ?epm_version}, {"Host", Host}].
-
-default_http_options() ->
- {ok, T} = epm_cfg:get(net_timeout),
- [{timeout, T}].
+%% request_as_str(Url, Host) ->
+%% case http_request(Url, Host) of
+%% {ok, "200", _, Body} ->
+%% Body;
+%% {ok, "403", _, _} ->
+%% not_found;
+%% {ok, "404", _, _} ->
+%% not_found;
+%% {ok, _} ->
+%% request_failed;
+%% {error, Reason} ->
+%% io:format("timeout? ~p~n", [Reason]),
+%% Reason
+%% end.
+%%
+%% http_request(Url, Host) ->
+%% http_request(Url, Host, []).
+%%
+%% http_request(Url, Host, ClientOpts) ->
+%% Hdrs = make_headers(Host),
+%% Opts = http_options(ClientOpts),
+%% {ok, Timeout} = epm_cfg:get(net_timeout),
+%% case ibrowse:send_req(Url, Hdrs, get, [], Opts, Timeout) of
+%% {ok, "302", Headers, _} = Response ->
+%% case proplists:get_value("Location", Headers) of
+%% undefined ->
+%% Response;
+%% Location ->
+%% http_request(Location, undefined, ClientOpts)
+%% end;
+%% Other -> Other
+%% end.
+%%
+%% http_options(ClientOpts) ->
+%% proxy_options() ++ ClientOpts.
+%%
+%% proxy_options() ->
+%% case epm_cfg:get(proxy_host) of
+%% {error, not_found} -> [];
+%% {ok, Host} ->
+%% Port = case epm_cfg:get(proxy_port) of
+%% {error, not_found} -> 8080;
+%% {ok, PortNum} -> PortNum
+%% end,
+%% [{proxy_host, Host}, {proxy_port, Port}]
+%% end.
+%%
+%% make_headers(undefined) ->
+%% [{"User-Agent", "Erlang EPM v" ++ ?epm_version}];
+%% make_headers(Host) ->
+%% [{"User-Agent", "Erlang EPM v" ++ ?epm_version}, {"Host", Host}].
+%%
+%% default_http_options() ->
+%% {ok, T} = epm_cfg:get(net_timeout),
+%% [{timeout, T}].
epm_home_dir(Home) ->
EPM = filename:join([Home, "epm"]),
@@ -88,108 +94,108 @@ 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
-add_to_path(InstallDir) ->
- case file:list_dir(InstallDir) of
- {ok, Files} ->
- [begin
- File = filename:join([InstallDir, File0]),
- case filelib:is_dir(File) of
- true ->
- Ebin = filename:join([File, "ebin"]),
- case filelib:wildcard(Ebin ++ "/*.app") of
- [App|_] ->
- case file:consult(App) of
- {ok, _} ->
- code:add_pathz(Ebin);
- _ ->
- ok
- end;
- _ ->
- ok
- end;
- false -> ok
- end
- end || File0 <- Files];
- _ ->
- ok
- end.
-
-%% TODO: Bleeding eyes
-del_dir(Dir) ->
- case file:list_dir(Dir) of
- {ok, Files} ->
- [begin
- case file:delete(Dir ++ "/" ++ Filename) of
- ok -> ok;
- {error, eperm} ->
- case file:del_dir(Dir ++ "/" ++ Filename) of
- ok -> ok;
- {error, eexist} ->
- del_dir(Dir ++ "/" ++ Filename)
- end
- end
- end || Filename <- Files],
- file:del_dir(Dir);
- _ ->
- ok
- end.
-
-rn_dir(OldName, NewName) ->
- case file:rename(OldName, NewName) of
- ok -> ok;
- {error, Reason} ->
- exit(lists:flatten(io_lib:format("failed to rename ~s to ~s: ~p", [OldName, NewName, Reason])))
- end.
-
-do_cmd(Cmd, fail) ->
- case do_cmd(Cmd) of
- {0, ""} ->
- ok;
- {0, Output} ->
- print_cmd_output("~s~n", [Output]);
- {_, Output} ->
- exit(Output)
- end.
-
-do_cmd(Cmd) ->
- Results = string:tokens(os:cmd(Cmd ++ "; echo $?"), "\n"),
- [ExitCode|Other] = lists:reverse(Results),
- {list_to_integer(ExitCode), string:join(lists:reverse(Other), "\n")}.
-
-print_cmd_output(Format, Args) ->
- case epm_cfg:get(verbose) of
- {error, not_found} -> print_cmd_output(Format, Args, false);
- {ok, Verbose} -> print_cmd_output(Format, Args, Verbose)
- end.
-
-print_cmd_output(_, _, false) -> ok; %% do not print verbose output
-print_cmd_output(Format, Args, true) ->
- Str = lists:flatten(io_lib:format(" " ++ Format, Args)),
- Output0 = re:replace(Str, "\n", "\n ", [global, {return, list}]),
- Output = re:replace(Output0, "\~", "", [global, {return, list}]),
- io:format(string:substr(Output, 1, length(Output)-4), []).
-
-set_cwd_build_home(_State=#epm_state{}) ->
- set_cwd(epm_cfg:get(build_dir, ".")).
-
-set_cwd(Dir) ->
- case file:set_cwd(Dir) of
- ok ->
- ok;
- {error, _} ->
- exit(lists:flatten(io_lib:format("failed to change working directory: ~s", [Dir])))
- 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
+%% add_to_path(InstallDir) ->
+%% case file:list_dir(InstallDir) of
+%% {ok, Files} ->
+%% [begin
+%% File = filename:join([InstallDir, File0]),
+%% case filelib:is_dir(File) of
+%% true ->
+%% Ebin = filename:join([File, "ebin"]),
+%% case filelib:wildcard(Ebin ++ "/*.app") of
+%% [App|_] ->
+%% case file:consult(App) of
+%% {ok, _} ->
+%% code:add_pathz(Ebin);
+%% _ ->
+%% ok
+%% end;
+%% _ ->
+%% ok
+%% end;
+%% false -> ok
+%% end
+%% end || File0 <- Files];
+%% _ ->
+%% ok
+%% end.
+%%
+%% %% TODO: Bleeding eyes
+%% del_dir(Dir) ->
+%% case file:list_dir(Dir) of
+%% {ok, Files} ->
+%% [begin
+%% case file:delete(Dir ++ "/" ++ Filename) of
+%% ok -> ok;
+%% {error, eperm} ->
+%% case file:del_dir(Dir ++ "/" ++ Filename) of
+%% ok -> ok;
+%% {error, eexist} ->
+%% del_dir(Dir ++ "/" ++ Filename)
+%% end
+%% end
+%% end || Filename <- Files],
+%% file:del_dir(Dir);
+%% _ ->
+%% ok
+%% end.
+%%
+%% rn_dir(OldName, NewName) ->
+%% case file:rename(OldName, NewName) of
+%% ok -> ok;
+%% {error, Reason} ->
+%% exit(lists:flatten(io_lib:format("failed to rename ~s to ~s: ~p", [OldName, NewName, Reason])))
+%% end.
+%%
+%% do_cmd(Cmd, fail) ->
+%% case do_cmd(Cmd) of
+%% {0, ""} ->
+%% ok;
+%% {0, Output} ->
+%% print_cmd_output("~s~n", [Output]);
+%% {_, Output} ->
+%% exit(Output)
+%% end.
+%%
+%% do_cmd(Cmd) ->
+%% Results = string:tokens(os:cmd(Cmd ++ "; echo $?"), "\n"),
+%% [ExitCode|Other] = lists:reverse(Results),
+%% {list_to_integer(ExitCode), string:join(lists:reverse(Other), "\n")}.
+%%
+%% print_cmd_output(Format, Args) ->
+%% case epm_cfg:get(verbose) of
+%% {error, not_found} -> print_cmd_output(Format, Args, false);
+%% {ok, Verbose} -> print_cmd_output(Format, Args, Verbose)
+%% end.
+%%
+%% print_cmd_output(_, _, false) -> ok; %% do not print verbose output
+%% print_cmd_output(Format, Args, true) ->
+%% Str = lists:flatten(io_lib:format(" " ++ Format, Args)),
+%% Output0 = re:replace(Str, "\n", "\n ", [global, {return, list}]),
+%% Output = re:replace(Output0, "\~", "", [global, {return, list}]),
+%% io:format(string:substr(Output, 1, length(Output)-4), []).
+%%
+%% set_cwd_build_home(_State=#epm_state{}) ->
+%% set_cwd(epm_cfg:get(build_dir, ".")).
+%%
+%% set_cwd(Dir) ->
+%% case file:set_cwd(Dir) of
+%% ok ->
+%% ok;
+%% {error, _} ->
+%% exit(lists:flatten(io_lib:format("failed to change working directory: ~s", [Dir])))
+%% end.
View
28 src/api_behavior.erl → src/gen_epm_api.erl
@@ -1,15 +1,19 @@
--module(api_behavior).
--export([behaviour_info/1]).
-
-behaviour_info(callbacks) -> [
- {package_deps, 3},
- {search, 1},
- {info, 2},
- {tags, 2},
- {branches, 2},
- {download_package, 2},
- {default_vsn, 0} ];
-behaviour_info(_) -> undefined.
+-module(gen_epm_api).
+%-export([behaviour_info/1]).
+
+-include("epm.hrl").
+
+-callback get_source(Pkg :: pkg(), DestDir :: string()) -> ok | {error, any()}.
+
+%behaviour_info(callbacks) -> [ {get_source, 2} ];
+%behaviour_info(_) -> undefined.
+%% {package_deps, 3},
+%% {search, 1},
+%% {info, 2},
+%% {tags, 2},
+%% {branches, 2},
+%% {download_package, 2},
+%% {default_vsn, 0} ];
%% package_deps(User, ProjectName, Vsn) -> Deps
%% User = string()

0 comments on commit a957756

Please sign in to comment.