Permalink
Browse files

rebarize, makefile

  • Loading branch information...
1 parent 9b66689 commit 1aad87624bef12a3e2e2cb0ddf74dba35388df73 Dmytro Lytovchenko committed Feb 8, 2014
Showing with 216 additions and 165 deletions.
  1. +4 −0 Makefile
  2. +0 −3 bootstrap
  3. +0 −20 ebin/epm.app
  4. +0 −15 ebin/epm_cfg.erl
  5. +2 −1 include/epm.hrl
  6. BIN rebar
  7. +2 −2 rebar.config
  8. +11 −0 src/epm.app.src
  9. +10 −10 src/epm.erl
  10. +31 −0 src/epm_cfg.erl
  11. +18 −19 src/epm_core.erl
  12. +3 −3 src/epm_deps.erl
  13. +76 −0 src/epm_index.erl
  14. +40 −37 src/{epm_cache.erl → epm_ops.erl}
  15. +19 −55 src/epm_util.erl
View
4 Makefile
@@ -0,0 +1,4 @@
+.PHONY: epm
+epm:
+ rebar get-deps compile escriptize
+
View
3 bootstrap
@@ -1,3 +0,0 @@
-#!/usr/bin/env sh
-
-./rebar get-deps compile-deps escriptize
View
20 ebin/epm.app
@@ -1,20 +0,0 @@
-{application, epm,
- [{description, "An Erlang package manager"},
- {vsn, "0.1.1"},
- {modules, [ epm,
- epm_core,
- epm_package,
- epm_util, epm_cache, epm_deps,
- api_behavior,
- %github_api,
- %bitbucket_api,
- yaws_html
- ]},
- {registered, []},
- {applications, [kernel, stdlib]},
- {env, [
- {sasl, [
- {sasl_error_logger, false}
- ]}
- ]}
-]}.
View
15 ebin/epm_cfg.erl
@@ -1,15 +0,0 @@
-%%%-------------------------------------------------------------------
-%%% @author Dmytro Lytovchenko <dmytro.lytovchenko@gmail.com>
-%%% @doc Configuration global storage
-%%% @end
-%%% Created : 08. Feb 2014 1:56 PM
-%%%-------------------------------------------------------------------
--module(epm_cfg).
-
-%% API
--export([]).
-
-init(Config) ->
- ets:new().
-
-set(Key, Value) ->
View
3 include/epm.hrl
@@ -1,6 +1,7 @@
--define(epm_version, "0.1.1").
+-define(epm_version, "1.0.0-dev").
-define(epm_year, 2014).
-define(DEFAULT_API_MODULES, [github_api]).
+-define(epm_index_filename, "epm_index").
-define(EXIT(Format, Args), exit(lists:flatten(io_lib:format(Format, Args)))).
View
BIN rebar
Binary file not shown.
View
4 rebar.config
@@ -1,7 +1,7 @@
{deps,[
- {ibrowse, "2.*",
- {git, "https://github.com/cmullaparthi/ibrowse.git", {tag, "v2.2.0"}}}
+ {ibrowse, "2.*", {git, "https://github.com/cmullaparthi/ibrowse.git", {tag, "v2.2.0"}}}
+ %, {'erlang-github-api', ".*", {git, "https://github.com/onlyshk/erlang-github-api.git", master}}
]}.
{escript_incl_apps, [ibrowse]}.
View
11 src/epm.app.src
@@ -0,0 +1,11 @@
+{application, epm,
+ [{description, "An Erlang package manager"},
+ {vsn, "0.1.1"},
+ {registered, []},
+ {applications, [kernel, stdlib]},
+ {env, [
+ {sasl, [
+ {sasl_error_logger, false}
+ ]}
+ ]}
+]}.
View
20 src/epm.erl
@@ -3,10 +3,6 @@
-include("epm.hrl").
main(Args) ->
- %% TODO: Remove put/get
- put(vsn, ?epm_version),
- io:format("epm v~s, ~p~n~n", [?epm_version, ?epm_year]),
-
application:load(sasl),
application:set_env(sasl, sasl_error_logger, false),
lists:map(fun application:start/1, [sasl, crypto, public_key, ssl, ibrowse, epm]),
@@ -20,20 +16,22 @@ main(Args) ->
ok
end,
- dets:close(epm_index),
+ epm_index:close(),
io:format("~n").
main_internal(Args) ->
Home = epm_util:home_dir(),
EpmHome = epm_util:epm_home_dir(Home),
- epm_util:open_dets_table(Home, EpmHome),
+ epm_util:open(Home, EpmHome),
%% consult global .epm config file in home directory
case file:path_consult(["."] ++ Home ++ [code:root_dir()], ".epm") of
{ok, [GlobalConfig], FileLoc} ->
- %% TODO: Remove put/get
- put(global_config, FileLoc),
+ epm_cfg:init(GlobalConfig),
+ epm_cfg:set(global_config, FileLoc),
+ epm_cfg:set(vsn, ?epm_version),
+ io:format("epm v~s, ~p~n~n", [?epm_version, ?epm_year]),
case proplists:get_value(install_dir, GlobalConfig) of
undefined ->
@@ -51,11 +49,13 @@ main_internal(Args) ->
epm_core:execute(GlobalConfig, Args);
{ok, [], FileLoc} ->
- put(global_config, FileLoc),
+ epm_cfg:init([]),
+ epm_cfg:set(global_config, FileLoc),
epm_core:execute([], Args);
{error, enoent} ->
file:write_file(filename:join([Home, ".epm"]), <<>>),
- put(global_config, filename:join([Home, ".epm"])),
+ epm_cfg:init([]),
+ epm_cfg:set(global_config, filename:join([Home, ".epm"])),
epm_core:execute([], Args);
{error, Reason} ->
?EXIT("failed to read epm global config: ~p", [Reason])
View
31 src/epm_cfg.erl
@@ -0,0 +1,31 @@
+%%%-------------------------------------------------------------------
+%%% @author Dmytro Lytovchenko <dmytro.lytovchenko@gmail.com>
+%%% @doc Configuration global storage
+%%% @end
+%%% Created : 08. Feb 2014 1:56 PM
+%%%-------------------------------------------------------------------
+-module(epm_cfg).
+
+%% API
+-export([init/1, set/2, get/1, get/2]).
+
+-define(cfg_table, epm_cfg).
+
+init(Config) ->
+ ets:new(?cfg_table, [named_table]),
+ lists:foreach(fun({K, V}) -> set(K, V) end, Config).
+
+set(Key, Value) ->
+ ets:insert(?cfg_table, {Key, Value}).
+
+get(Key) ->
+ case ets:lookup(?cfg_table, Key) of
+ [] -> {error, not_found};
+ [{Key, Value}] -> {ok, Value}
+ end.
+
+get(Key, Default) ->
+ case ets:lookup(?cfg_table, Key) of
+ [] -> Default;
+ [{Key, Value}] -> Value
+ end.
View
37 src/epm_core.erl
@@ -5,10 +5,9 @@
execute(GlobalConfig0, ["install" | Args]) ->
{GlobalConfig, Packages, Flags} = collect_args(install, Args, GlobalConfig0),
- %% TODO: Remove put/get
- put(verbose, lists:member(verbose, Flags)),
+ epm_cfg:set(verbose, lists:member(verbose, Flags)),
Deps = epm_deps:package_dependencies(GlobalConfig, Packages),
- {Installed, NotInstalled} = epm_cache:filter_installed_packages(Deps),
+ {Installed, NotInstalled} = epm_ops:filter_installed_packages(Deps),
case NotInstalled of
[] ->
io:format("+ nothing to do: packages and dependencies already installed~n");
@@ -31,16 +30,16 @@ execute(GlobalConfig0, ["install" | Args]) ->
case io:get_chars("", 1) of
C when C == "y"; C == "\n" ->
io:format("~n"),
- [epm_cache:install_package(GlobalConfig, Package)
+ [epm_ops:install_package(GlobalConfig, Package)
|| Package <- NotInstalled];
_ -> ok
end
end;
execute(GlobalConfig0, ["remove" | Args]) ->
{GlobalConfig, Packages, Flags} = collect_args(remove, Args, GlobalConfig0),
- put(verbose, lists:member(verbose, Flags)),
- Installed = epm_cache:installed_packages(Packages),
+ epm_cfg:set(verbose, lists:member(verbose, Flags)),
+ Installed = epm_ops:get_installed_packages(Packages),
case Installed of
[] ->
io:format("+ nothing to remove: no matching packages installed~n");
@@ -54,16 +53,16 @@ execute(GlobalConfig0, ["remove" | Args]) ->
case io:get_chars("", 1) of
C when C == "y"; C == "\n" ->
io:format("~n"),
- [epm_cache:remove_package(GlobalConfig, Package)
+ [epm_ops:remove_package(GlobalConfig, Package)
|| Package <- Installed];
_ -> ok
end
end;
execute(GlobalConfig0, ["update" | Args]) ->
{GlobalConfig, Packages, Flags} = collect_args(update, Args, GlobalConfig0),
- put(verbose, lists:member(verbose, Flags)),
- Installed = epm_cache:installed_packages(Packages),
+ epm_cfg:set(verbose, lists:member(verbose, Flags)),
+ Installed = epm_ops:get_installed_packages(Packages),
case Installed of
[] ->
io:format("- nothing to update~n");
@@ -77,15 +76,15 @@ execute(GlobalConfig0, ["update" | Args]) ->
case io:get_chars("", 1) of
C when C == "y"; C == "\n" ->
io:format("~n"),
- [epm_cache:update_package(GlobalConfig, Package)
+ [epm_ops:update_package(GlobalConfig, Package)
|| Package <- Installed];
_ -> ok
end
end;
execute(GlobalConfig0, ["info" | Args]) ->
{GlobalConfig, Packages, _Flags} = collect_args(info, Args, GlobalConfig0),
- {Installed, NotInstalled} = epm_cache:filter_installed_packages(Packages),
+ {Installed, NotInstalled} = epm_ops:filter_installed_packages(Packages),
case Installed of
[] -> ok;
_ ->
@@ -99,7 +98,7 @@ execute(GlobalConfig0, ["info" | Args]) ->
0 -> ok;
_ -> io:format("~n")
end,
- epm_cache:print_installed_package_info(Package),
+ epm_ops:print_installed_package_info(Package),
Count + 1
end , 0, lists:reverse(Installed))
end,
@@ -111,17 +110,17 @@ execute(GlobalConfig0, ["info" | Args]) ->
[] -> ok;
_ -> io:format("~n")
end,
- epm_cache:print_not_installed_package_info(GlobalConfig
+ epm_ops:print_not_installed_package_info(GlobalConfig
, NotInstalled, true)
end;
execute(GlobalConfig0, ["search" | Args]) ->
{GlobalConfig, Packages, _Flags} = collect_args(search, Args, GlobalConfig0),
- epm_cache:print_not_installed_package_info(GlobalConfig
+ epm_ops:print_not_installed_package_info(GlobalConfig
, lists:reverse(Packages));
execute(_GlobalConfig, ["list" | _Args]) ->
- Installed = epm_cache:installed_packages(),
+ Installed = epm_ops:installed_packages(),
case Installed of
[] ->
io:format("- no packages installed~n");
@@ -136,7 +135,7 @@ execute(_GlobalConfig, ["list" | _Args]) ->
0 -> ok;
_ -> io:format("~n")
end,
- epm_cache:print_installed_package_info(Package),
+ epm_ops:print_installed_package_info(Package),
Count + 1
end , 0, lists:reverse(Installed))
end;
@@ -234,7 +233,7 @@ collect_args(Target, [Arg | Rest], GlobalConfig, Packages, 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_cache:split_package(Arg),
+ {ProjectName, User} = epm_ops:split_package(Arg),
collect_args(Target, Rest, GlobalConfig
, [#package{user = User, name = ProjectName}|Packages]
, Flags);
@@ -351,7 +350,7 @@ print_config_values(GlobalConfig) ->
[io:format("~p\t\t~p~n", [K,V]) || {K,V} <- GlobalConfig].
write_config_file(GlobalConfig) ->
- FileLoc = get(global_config),
+ {ok, FileLoc} = epm_cfg:get(global_config),
case file:open(FileLoc, [write]) of
{ok, IoDevice} ->
io:format(IoDevice, "[~n", []),
@@ -369,7 +368,7 @@ write_config_file(GlobalConfig) ->
io:format(IoDevice, " {~p, ~p}", [Key, Val])
end,
Count + 1
- end , 0, GlobalConfig),
+ end, 0, GlobalConfig),
io:format(IoDevice, "~n].~n", []),
io:format("+ updated .epm config~n");
{error, Reason} ->
View
6 src/epm_deps.erl
@@ -27,7 +27,7 @@ package_dependencies(GlobalConfig, Packages) ->
%% @private
package_dependencies1([], _, _, _, Dict) -> Dict;
package_dependencies1([Package|Tail], RepoPlugins, G, Parent, Dict) ->
- Repo = epm_cache:retrieve_remote_repo(
+ Repo = epm_ops:retrieve_remote_repo(
RepoPlugins, Package#package.user, Package#package.name),
WithoutDeps = lists:member(without_deps, Package#package.args),
Key = {Repo#repository.owner, Repo#repository.name, Package#package.vsn},
@@ -59,8 +59,8 @@ package_dependencies1([Package|Tail], RepoPlugins, G, Parent, Dict) ->
Deps0 = apply(Repo#repository.api_module, package_deps
, [Repo#repository.owner, Repo#repository.name, PkgVsn]),
F = fun({Dep, Args}, TempDict) ->
- {DepName, DepUser} = epm_cache:split_package(Dep),
- DepVsn = epm_cache:read_vsn_from_args(
+ {DepName, DepUser} = epm_ops:split_package(Dep),
+ DepVsn = epm_ops:read_vsn_from_args(
Args, apply(Repo#repository.api_module, default_vsn, [])),
Package0 = #package{user = DepUser
, name = DepName
View
76 src/epm_index.erl
@@ -0,0 +1,76 @@
+%%%-------------------------------------------------------------------
+%%% @author Dmytro Lytovchenko <dmytro.lytovchenko@gmail.com>
+%%% @doc Represents local installed package index and remote package index plus
+%%% manipulations (search, dependencies etc).
+%%% @end
+%%% Created : 08. Feb 2014 2:47 PM
+%%%-------------------------------------------------------------------
+-module(epm_index).
+
+%% API
+-export([ open/2
+ , list_local_packages/0
+ , list_local_by/3
+ , delete_local/1
+ , insert_local/2
+ , close/0]).
+
+-include("epm.hrl").
+
+-define(local_index, epm_index).
+
+%%------------------------------------------------------------------------------
+close() ->
+ dets:close(?local_index).
+
+open(Home, EpmHome) ->
+ File = filename:join([EpmHome, ?epm_index_filename]),
+
+ %% 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),
+
+ [{{User, Name, Vsn}
+ , #package{user = User
+ , name = Name
+ , vsn = Vsn
+ , install_dir = InstallDir
+ , deps = Deps
+ %, repo = github_api:info(User, Name)
+ }}
+ || [{{User, Name, Vsn}, InstallDir, Deps}] <- Rows];
+ _ -> []
+ end;
+ false -> []
+ end,
+
+ 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.
+
+list_local_packages() ->
+ dets:match(?local_index, '$1').
+
+%% @doc Provide '_' if field is not relevant
+list_local_by(User, ProjectName, Version) ->
+ dets:match(?local_index, {{User, ProjectName, Version}, '$1'}).
+
+delete_local(Key={_User, _Name, _Vsn}) ->
+ dets:delete(?local_index, Key).
+
+insert_local(Key={_User, _Name, _Vsn}, Package=#package{}) ->
+ dets:insert(?local_index, {Key, Package}).
View
77 src/epm_cache.erl → src/epm_ops.erl
@@ -1,17 +1,17 @@
%%%-------------------------------------------------------------------
%%% @author Dmytro Lytovchenko <dmytro.lytovchenko@gmail.com>
-%%% @doc Represents local index of packages and binary package storage
+%%% @doc Represents operations on package storage and remote storage
%%% @end
%%% Created : 07. Feb 2014 7:16 PM
%%%-------------------------------------------------------------------
--module(epm_cache).
+-module(epm_ops).
%% API
-export([filter_installed_packages/1
, retrieve_remote_repo/3
, retrieve_remote_repos/4
, installed_packages/0
- , installed_packages/1
+ , get_installed_packages/1
, split_package/1
, read_vsn_from_args/2
, print_not_installed_package_info/2
@@ -45,9 +45,9 @@ split_package([A | Tail], User) -> split_package(Tail, User ++ [A]).
installed_packages() ->
- [Package || [{_,Package}] <- dets:match(epm_index, '$1')].
+ [Package || [{_,Package}] <- epm_index:list_local_packages()].
-installed_packages(Packages) ->
+get_installed_packages(Packages) ->
Installed = dict:to_list(installed_packages_internal(Packages, dict:new())),
[V || {_K,V} <- Installed].
@@ -74,7 +74,7 @@ installed_packages_internal([Package|Tail], Dict) ->
dependant_installed_packages(Package) ->
- dependant_installed_packages(Package, [], dets:match(epm_index, '$1')).
+ dependant_installed_packages(Package, [], epm_index:list_local_packages()).
dependant_installed_packages(_Package, Acc, []) -> Acc;
dependant_installed_packages(#package{user = User
@@ -162,28 +162,28 @@ retrieve_remote_repos([Module|Tail], User, ProjectName, IsExact, Acc) ->
local_package_info(#package{ user = none
, name = ProjectName
, vsn = undefined}) ->
- case dets:match(epm_index, {{'_', ProjectName, '_'}, '$1'}) of
+ case epm_index:list_local_by('_', ProjectName, '_') of
[] -> [];
List -> [Package || [Package] <- List]
end;
local_package_info(#package{ user = none
, name = ProjectName
, vsn = Vsn}) ->
- case dets:match(epm_index, {{'_', ProjectName, Vsn}, '$1'}) of
+ case epm_index:list_local_by('_', ProjectName, Vsn) of
[] -> [];
List -> [Package || [Package] <- List]
end;
local_package_info(#package{ user = User
, name = ProjectName
, vsn = undefined}) ->
- case dets:match(epm_index, {{User, ProjectName, '_'}, '$1'}) of
+ case epm_index:list_local_by(User, ProjectName, '_') of
[] -> [];
List -> [Package || [Package] <- List]
end;
local_package_info(#package{ user = User
, name = ProjectName
, vsn = Vsn}) ->
- case dets:match(epm_index, {{User, ProjectName, Vsn}, '$1'}) of
+ case epm_index:list_local_by(User, ProjectName, Vsn) of
[] -> [];
List -> [Package || [Package] <- List]
end.
@@ -274,76 +274,79 @@ write_not_installed_package_info1(Packages, RepoPlugins, IsExact) ->
fetch_not_installed_package_info([], _, Acc, _) -> Acc;
fetch_not_installed_package_info([#package{user=User,name=ProjectName}|Tail]
, RepoPlugins, Acc, IsExact) ->
- Repos = epm_cache:retrieve_remote_repos(
+ Repos = epm_ops:retrieve_remote_repos(
RepoPlugins, User, ProjectName, IsExact),
fetch_not_installed_package_info(
Tail, RepoPlugins, lists:append(Acc, Repos), IsExact).
+%% -----------------------------------------------------------------------------
+%% REMOVE
+%% -----------------------------------------------------------------------------
+remove_package(_GlobalConfig, #package{ user = User
+ , name = Name
+ , vsn = Vsn
+ , install_dir = InstallDir}) ->
+ io:format("+ removing package ~s-~s-~s from ~s~n"
+ , [User, Name, Vsn, InstallDir]),
+ RemoveCmd = "rm -rf " ++ InstallDir,
+ epm_util:print_cmd_output("~s~n", [RemoveCmd]),
+ epm_util:do_cmd(RemoveCmd, fail),
+ epm_index:delete_local({User, Name, Vsn}).
%% -----------------------------------------------------------------------------
-%% INSTALL
+%% UPDATE
%% -----------------------------------------------------------------------------
-install_package(GlobalConfig, Package) ->
+update_package(GlobalConfig, Package) ->
Repo = Package#package.repo,
- User = Repo#repository.owner,
- Name = Repo#repository.name,
Vsn = Package#package.vsn,
%% switch to build home dir
epm_util:set_cwd_build_home(GlobalConfig),
%% download correct version of package
- LocalProjectDir = apply(Repo#repository.api_module, download_package, [Repo, Vsn]),
+ LocalProjectDir = apply(Repo#repository.api_module, download_package
+ , [Repo, Vsn]),
%% switch to project dir
epm_util:set_cwd_build_home(GlobalConfig),
epm_util:set_cwd(LocalProjectDir),
%% build/install project
- InstallDir = "not-building-anything", %build_project(GlobalConfig, Package),
+ %_InstallDir = build_project(GlobalConfig, Package),
%% switch to build home dir and delete cloned project
epm_util:set_cwd_build_home(GlobalConfig),
- epm_util:del_dir(LocalProjectDir),
-
- dets:insert(epm_index, {{User, Name, Vsn}, Package#package{install_dir = InstallDir}}),
-
- ok.
+ epm_util:del_dir(LocalProjectDir).
-%% -----------------------------------------------------------------------------
-%% REMOVE
-%% -----------------------------------------------------------------------------
-remove_package(_GlobalConfig, #package{user = User, name = Name, vsn = Vsn, install_dir = InstallDir}) ->
- io:format("+ removing package ~s-~s-~s from ~s~n", [User, Name, Vsn, InstallDir]),
- RemoveCmd = "rm -rf " ++ InstallDir,
- epm_util:print_cmd_output("~s~n", [RemoveCmd]),
- epm_util:do_cmd(RemoveCmd, fail),
- dets:delete(epm_index, {User, Name, Vsn}).
%% -----------------------------------------------------------------------------
-%% UPDATE
+%% INSTALL
%% -----------------------------------------------------------------------------
-update_package(GlobalConfig, Package) ->
+install_package(GlobalConfig, Package) ->
Repo = Package#package.repo,
+ User = Repo#repository.owner,
+ Name = Repo#repository.name,
Vsn = Package#package.vsn,
%% switch to build home dir
epm_util:set_cwd_build_home(GlobalConfig),
%% download correct version of package
- LocalProjectDir = apply(Repo#repository.api_module, download_package
- , [Repo, Vsn]),
+ LocalProjectDir = apply(Repo#repository.api_module, download_package, [Repo, Vsn]),
%% switch to project dir
epm_util:set_cwd_build_home(GlobalConfig),
epm_util:set_cwd(LocalProjectDir),
%% build/install project
- %_InstallDir = build_project(GlobalConfig, Package),
+ InstallDir = "not-building-anything", %build_project(GlobalConfig, Package),
%% switch to build home dir and delete cloned project
epm_util:set_cwd_build_home(GlobalConfig),
- epm_util:del_dir(LocalProjectDir).
+ epm_util:del_dir(LocalProjectDir),
+ Package1 = Package#package{install_dir = InstallDir},
+ epm_index:insert_local({User, Name, Vsn}, Package1),
+ ok.
install(ProjectName, Config, undefined) ->
install(ProjectName, Config, code:lib_dir());
View
74 src/epm_util.erl
@@ -9,16 +9,16 @@ home_dir() ->
end.
set_http_proxy(Host, Port) when Host =:= none orelse Port =:= none ->
- ignored;
+ ignored;
set_http_proxy(Host, Port) when is_list(Port) ->
- set_http_proxy(Host, list_to_integer(Port));
+ set_http_proxy(Host, list_to_integer(Port));
set_http_proxy(Host, Port) when is_integer(Port) ->
- put(proxy_host, Host), put(proxy_port, Port).
+ epm_cfg:set(proxy_host, Host), put(proxy_port, Port).
set_net_timeout(Timeout) when is_list(Timeout) ->
- set_net_timeout(list_to_integer(Timeout));
+ set_net_timeout(list_to_integer(Timeout));
set_net_timeout(Timeout) when is_integer(Timeout) ->
- put(net_timeout, Timeout).
+ epm_cfg:set(net_timeout, Timeout).
request_as_str(Url, Host) ->
case http_request(Url, Host) of
@@ -41,7 +41,7 @@ http_request(Url, Host) ->
http_request(Url, Host, ClientOpts) ->
Hdrs = make_headers(Host),
Opts = http_options(ClientOpts),
- Timeout = get(net_timeout),
+ {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
@@ -57,23 +57,24 @@ http_options(ClientOpts) ->
proxy_options() ++ ClientOpts.
proxy_options() ->
- case get(proxy_host) of
- undefined -> [];
- Host ->
- Port = case get(proxy_port) of
- none -> 8080;
- PortNum -> PortNum
+ 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", "EPM"}];
+ [{"User-Agent", "Erlang EPM v" ++ ?epm_version}];
make_headers(Host) ->
- [{"User-Agent", "EPM"}, {"Host", Host}].
+ [{"User-Agent", "Erlang EPM v" ++ ?epm_version}, {"Host", Host}].
default_http_options() ->
- [{timeout, get(net_timeout)}].
+ {ok, T} = epm_cfg:get(net_timeout),
+ [{timeout, T}].
epm_home_dir(Home) ->
EPM = filename:join([Home, "epm"]),
@@ -87,43 +88,6 @@ epm_home_dir(Home) ->
end
end.
-open_dets_table(Home, EpmHome) ->
- File = filename:join([EpmHome, "epm_index"]),
-
- %% TODO: delete this later
- Insert =
- case filelib:is_regular(filename:join([Home, "epm_index"])) of
- true ->
- case dets:open_file(epm_index, [{type, set}, {file, filename:join([Home, "epm_index"])}]) of
- {ok, _} ->
- Rows = dets:match(epm_index, '$1'),
- dets:close(epm_index),
-
- [{{User, Name, Vsn}, #package{
- user = User ,
- name = Name ,
- vsn = Vsn ,
- install_dir = InstallDir,
- deps = Deps ,
- repo = github_api:info(User, Name)
- }} || [{{User, Name, Vsn}, InstallDir, Deps}] <- Rows];
- _ -> []
- end;
- false -> []
- end,
-
- case dets:open_file(epm_index, [{type, set}, {file, File}]) of
- {ok, _} ->
- %% TODO: delete this later
- [dets:insert(epm_index, I) || I <- Insert],
- file:delete(filename:join([Home, "epm_index"])),
- 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.
-
%% TODO: Bleeding eyes
eval(Str) ->
case erl_scan:string(Str) of
@@ -209,9 +173,9 @@ do_cmd(Cmd) ->
{list_to_integer(ExitCode), string:join(lists:reverse(Other), "\n")}.
print_cmd_output(Format, Args) ->
- case get(verbose) of
- undefined -> print_cmd_output(Format, Args, false);
- Verbose -> print_cmd_output(Format, Args, Verbose)
+ 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

0 comments on commit 1aad876

Please sign in to comment.