Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

install /no versions/no tags

  • Loading branch information...
commit 76c7ba73548982237265eef11e77d4c47b9b655c 1 parent ca16526
Dmytro Lytovchenko authored
View
3  .gitignore
@@ -7,4 +7,5 @@ epm
.idea
*.plt
*.log
-epm_local_index
+epm_local_index
+erl_crash.dump
View
4 Makefile
@@ -2,6 +2,10 @@
compile:
rebar get-deps compile escriptize
+.PHONY: run
+run: compile
+ erl -pa ebin -s epm
+
.PHONY: clean
clean:
rm ebin/* *.log
View
16 include/epm.hrl
@@ -17,7 +17,7 @@
| epm_vcs_git | epm_vcs_github.
-type pkg_arg() :: source | {tag|branch|hash, string()}.
--record(repoid, { name :: string()
+-record(repoid, { name=erlang:error(name_not_set) :: nonempty_string()
}).
-type repoid() :: #repoid{}.
@@ -33,27 +33,25 @@
-type pkgid() :: #pkgid{}.
%% Repository: Specifies only title and base URL for api_module to use.
--record(repo, { id :: repoid()
+-record(repo, { id=erlang:error(id_not_set) :: repoid()
, description :: string()
, url :: string()
- %, followers
- %, pushed
+ , short_name=erlang:error(short_name_not_set) :: nonempty_string()
, api_module=epm_vcs :: api_module()
}).
-type repo() :: #repo{}.
%% Package: Does not specify branches/tags as this info is queried from package
%% repository online.
--record(pkg, { id :: pkgid()
- , install_dir :: string()
+-record(pkg, { id=erlang:error(id_not_set) :: pkgid()
, deps=[] :: [pkgid()]
, args=[] :: list()
- , repo :: repoid()
+ , repo=erlang:error(repo_not_set) :: repoid()
}).
-type pkg() :: #pkg{}.
--record(installed_pkg, { id :: pkgid()
- , repository :: repoid()
+-record(installed_pkg, { id=erlang:error(id_not_set) :: pkgid()
+ , repository=erlang:error(repo_not_set) :: repoid()
, platform :: platform()
}).
-type installed_pkg() :: #installed_pkg{}.
View
16 src/epm.erl
@@ -1,5 +1,5 @@
-module(epm).
--export([main/1
+-export([ start/0, main/1
, author/1
, name/1
, vsn/1
@@ -13,6 +13,10 @@
-include("epm.hrl").
-include_lib("stdlib/include/ms_transform.hrl").
+start() ->
+ %% Debug
+ main(["install", "cowboy"]).
+
main(Args) ->
application:load(sasl),
application:set_env(sasl, sasl_error_logger, false),
@@ -20,19 +24,19 @@ main(Args) ->
, [sasl, crypto, public_key, ssl, ibrowse, epm]),
case (catch main_internal(Args)) of
- {'EXIT', {ok, Msg}} when is_list(Msg) -> epm:p(red, "- ~s~n", [Msg]);
- {'EXIT', {error, Msg}} when is_list(Msg) -> epm:p(green, "- ~s~n", [Msg]);
- {'EXIT', Other} -> epm:p(dark_cyan, "~p~n", [Other]);
+ {'EXIT', {ok, Msg}} when is_list(Msg) -> epm:p(green, "OK ~s~n", [Msg]);
+ {'EXIT', {error, Msg}} when is_list(Msg) -> epm:p(red, "ERROR ~s~n", [Msg]);
+ {'EXIT', Other} -> epm:p(dark_cyan, "EXIT ~p~n", [Other]);
_ -> ok
end,
epm_index:close(),
io:format("~n").
main_internal(Args) ->
- epm_cfg:init(),
Home = epm_util:home_dir(),
EpmHome = epm_util:epm_home_dir(Home),
- State = epm_index:open(Home, EpmHome),
+ epm_cfg:init(EpmHome),
+ State = epm_index:open(EpmHome),
setup_proxy(),
epm_core:execute(State, Args).
View
11 src/epm_cfg.erl
@@ -7,7 +7,7 @@
-module(epm_cfg).
%% API
--export([init/0
+-export([init/1
, set/2
, get/1
, get/2
@@ -17,19 +17,18 @@
-include("epm.hrl").
-define(cfg_table, epm_cfg).
-init() ->
+init(EpmHome) ->
ets:new(?cfg_table, [named_table]),
Home = epm_util:home_dir(),
set(vsn, ?epm_version),
%% consult global .epm config file in home directory
- GlobalConfig =
- case file:path_consult(["."] ++ Home ++ [code:root_dir()], ".epm") of
- {ok, [C], _FileLoc} ->
+ GlobalConfig = case file:consult(filename:join([EpmHome, "epm.conf"])) of
+ {ok, [C]} ->
io:format("epm v~s, ~p~n~n", [?epm_version, ?epm_year]),
C;
- {ok, [], _FileLoc} -> [];
+ {ok, []} -> [];
{error, enoent} ->
file:write_file(filename:join([Home, ".epm"]), <<>>),
[];
View
61 src/epm_index.erl
@@ -8,7 +8,7 @@
-module(epm_index).
%% API
--export([open/2
+-export([open/1
, delete_local/1
, insert_local/2
, close/0
@@ -38,42 +38,34 @@ is_installed(Id=#pkgid{}) ->
close() -> ok.
-
-open(_Home, EpmHome) ->
- PkgDb = open_dets_file(filename:join([EpmHome, ?global_pkgs_db])),
- ets:new(?global_pkgs, [named_table, {keypos, #pkg.id}]),
- lists:foreach(fun(X1) -> ets:insert(?global_pkgs, X1) end, PkgDb),
-
- RepoDb = open_dets_file(filename:join([EpmHome, ?global_repos_db])),
- ets:new(?global_repos, [named_table, {keypos, #repo.id}]),
- lists:foreach(fun(X3) -> ets:insert(?global_repos, X3) end, RepoDb),
+open(EpmHome) ->
+ create_and_load(EpmHome),
%% Pkgid Fixtures
CowboyId = #pkgid{author="extend", pkg_name="cowboy", vsn="2.7", platform=x64},
Cowboy2Id = #pkgid{author="derp", pkg_name="cowboy", vsn="2.6"},
- RanchId = #pkgid{pkg_name="ranch", vsn="1.1"},
- GunId = #pkgid{pkg_name="gun", vsn="0.1-dev", platform=x86},
- FwId = #pkgid{pkg_name="farwest", vsn="1a"},
+ RanchId = #pkgid{author="extend", pkg_name="ranch", vsn="1.1"},
+ GunId = #pkgid{author="extend", pkg_name="gun", vsn="0.1-dev", platform=x86},
+ FwId = #pkgid{author="extend", pkg_name="farwest", vsn="1a"},
OtherId = #pkgid{pkg_name="other", erlang_vsn="r13b"},
%% Repo Fixtures
- Repo1Id = #repoid{name="github"},
- ets:insert(?global_repos, #repo{id=Repo1Id, api_module=epm_vcs_git}),
- Repo2Id = #repoid{name="git"},
- ets:insert(?global_repos, #repo{id=Repo2Id, api_module=epm_vcs_git}),
+ Github = #repoid{name="github"},
+ ets:insert(?global_repos, #repo{ id=Github, api_module=epm_vcs_git
+ , short_name="github" }),
+ Git = #repoid{name="git"},
+ ets:insert(?global_repos, #repo{ id=Git, api_module=epm_vcs_git
+ , short_name="git" }),
%% Pkg Fixtures
- ets:insert(?global_pkgs, #pkg{id=CowboyId, deps=[RanchId], repo=Repo1Id}),
- ets:insert(?global_pkgs, #pkg{id=Cowboy2Id, deps=[RanchId]}),
- ets:insert(?global_pkgs, #pkg{id=RanchId, deps=[GunId]}),
- ets:insert(?global_pkgs, #pkg{id=GunId}),
- ets:insert(?global_pkgs, #pkg{id=FwId}),
- ets:insert(?global_pkgs, #pkg{id=OtherId}),
+ ets:insert(?global_pkgs, #pkg{id=CowboyId, deps=[RanchId], repo=Github}),
+ ets:insert(?global_pkgs, #pkg{id=Cowboy2Id, deps=[RanchId], repo=Github}),
+ ets:insert(?global_pkgs, #pkg{id=RanchId, deps=[GunId], repo=Github}),
+ ets:insert(?global_pkgs, #pkg{id=GunId, repo=Github}),
+ ets:insert(?global_pkgs, #pkg{id=FwId, repo=Github}),
+ ets:insert(?global_pkgs, #pkg{id=OtherId, repo=Git}),
- LocalPkgDb = open_dets_file(?local_pkgs_db),
- ets:new(?local_pkgs, [named_table, {keypos, #pkg.id}]),
- lists:foreach(fun(X2) -> ets:insert(?local_pkgs, X2) end, LocalPkgDb),
- ets:insert(?local_pkgs, #pkg{id=GunId}),
+ %ets:insert(?local_pkgs, #pkg{id=GunId}),
State = #epm_state{},
State.
@@ -125,4 +117,17 @@ open_dets_file(File) ->
%% Load everything and return, to be inserted to ETS or used later
Objects = dets:match(epm_temporary, '$1'),
dets:close(epm_temporary),
- Objects.
+ Objects.
+
+create_and_load(EpmHome) ->
+ PkgDb = open_dets_file(filename:join([EpmHome, ?global_pkgs_db])),
+ ets:new(?global_pkgs, [named_table, {keypos, #pkg.id}]),
+ lists:foreach(fun(X1) -> ets:insert(?global_pkgs, X1) end, PkgDb),
+
+ RepoDb = open_dets_file(filename:join([EpmHome, ?global_repos_db])),
+ ets:new(?global_repos, [named_table, {keypos, #repo.id}]),
+ lists:foreach(fun(X3) -> ets:insert(?global_repos, X3) end, RepoDb),
+
+ LocalPkgDb = open_dets_file(?local_pkgs_db),
+ ets:new(?local_pkgs, [named_table, {keypos, #pkg.id}]),
+ lists:foreach(fun(X2) -> ets:insert(?local_pkgs, X2) end, LocalPkgDb).
View
2  src/epm_util.erl
@@ -83,7 +83,7 @@ set_net_timeout(Timeout) when is_integer(Timeout) ->
%% [{timeout, T}].
epm_home_dir(Home) ->
- EPM = filename:join([Home, "epm"]),
+ EPM = filename:join([Home, ".epm"]),
case filelib:is_dir(EPM) of
true -> EPM;
false ->
View
13 src/epm_vcs.erl
@@ -8,7 +8,7 @@
-behaviour(gen_vcs).
%% API
--export([get_source/2]).
+-export([get_source/2, install_dir_name/1]).
-include("epm.hrl").
@@ -16,10 +16,17 @@
get_source(Pkg=#pkg{repo=RepoId}, DestDir) ->
%% TODO: auto detection for git/svn protocol
case epm_index:get_repo(RepoId) of
- undefined ->
- ?EPM_FAIL("repository not set for package ~s", [epm:s(Pkg)]);
+ not_found ->
+ ?EPM_FAIL("[index error] repository was set, but not found for package ~s"
+ , [epm:as_string(Pkg)]);
Repo ->
epm:p("repo ~p", [Repo]),
ApiMod = Repo#repo.api_module,
ApiMod:get_source(Pkg, DestDir)
end.
+
+%% @doc Naming scheme for local install
+%% TODO: Configure naming format per project/per user
+install_dir_name(#pkg{id=#pkgid{author=A, pkg_name=N}, repo=RepoId}) ->
+ #repo{short_name=RepoSN} = epm_index:get_repo(RepoId),
+ epm:s("~s.~s.~s", [N, A, RepoSN]).
View
5 src/epm_vcs_git.erl
@@ -13,9 +13,10 @@
-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) ->
+get_source(Pkg, DestDir) ->
Url = get_vcs_url(Pkg),
- Path = filename:join([DestDir, epm:s("~s_~s", [A, N])]),
+ Path = filename:join([DestDir, epm_vcs:install_dir_name(Pkg)]),
+ %% TODO: versions, tags
epm_util:git(["clone", Url, Path]),
ok.
Please sign in to comment.
Something went wrong with that request. Please try again.