Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 107 lines (91 sloc) 3.718 kb
44a5bb4 @jlouis Hint Emacs that the Tab Stop of the files are 4 spaces.
jlouis authored
1 %% -*- Mode: Erlang; tab-width: 4 -*-
0cdd671 @yrashk Initial simplistic fetching functionality
yrashk authored
2 -module(agner_download).
3 -export([fetch/2]).
5080e44 @yrashk Get rid of GitHub API for specs retrieval, we'll actually checkout ac…
yrashk authored
4 %% internal exports
5 -export([git/1, git/2, process_port/2]).
0cdd671 @yrashk Initial simplistic fetching functionality
yrashk authored
6
149e6dd @yrashk Store specification in fetched repositories
yrashk authored
7 fetch(Spec, Directory) ->
8 Fetch = fetch_1(proplists:get_value(url, Spec), Directory),
6440b88 @yrashk Initial support for fetching dependencies from .app files
yrashk authored
9 case file:open(filename:join(Directory,".agner.config"),[write]) of
10 {ok, F} ->
11 lists:foreach(fun (Term) ->
12 io:fwrite(F,"~p.~n",[Term])
13 end, Spec),
14 file:close(F);
15 _ ->
16 ignore
17 end,
149e6dd @yrashk Store specification in fetched repositories
yrashk authored
18 Fetch.
6440b88 @yrashk Initial support for fetching dependencies from .app files
yrashk authored
19
20 fetch_1(undefined, _) -> %% if no url is defined, don't download anything
21 ok;
149e6dd @yrashk Store specification in fetched repositories
yrashk authored
22
23 fetch_1({all, []}, _) ->
c89b6cf @yrashk Added support for multiple URLs ('all' url)
yrashk authored
24 ok;
25
149e6dd @yrashk Store specification in fetched repositories
yrashk authored
26 fetch_1({all, [{Name, URL}|Rest]}, Directory) ->
27 fetch_1(URL, filename:join(Directory, Name)),
28 fetch_1({all, Rest}, Directory);
c89b6cf @yrashk Added support for multiple URLs ('all' url)
yrashk authored
29
149e6dd @yrashk Store specification in fetched repositories
yrashk authored
30 fetch_1({git, URL, Ref}, Directory) ->
114e3b3 @yrashk When git clone exists, just refresh it.
yrashk authored
31 case filelib:is_dir(Directory) of
32 false -> %% clone
33 PortClone = git(["clone", URL, Directory]),
34 process_port(PortClone, fun () -> git_checkout(Ref, Directory) end);
35 true -> %% existing repo (or something else)
18d6d21 @yrashk Updating git repo was broken, fixing.
yrashk authored
36 PortFetch = git(["fetch","origin"], [{cd, Directory}]),
114e3b3 @yrashk When git clone exists, just refresh it.
yrashk authored
37 process_port(PortFetch, fun() -> git_checkout(Ref, Directory) end)
7af82ca @yrashk Added hg support
yrashk authored
38 end;
39
149e6dd @yrashk Store specification in fetched repositories
yrashk authored
40 fetch_1({hg, URL, Rev}, Directory) ->
7af82ca @yrashk Added hg support
yrashk authored
41 case filelib:is_dir(Directory) of
42 false -> %% new
43 PortClone = hg(["clone", "-U", URL, Directory]),
44 process_port(PortClone, fun () ->
b645760 @ferd Fixing the download procedure for mercurial.
ferd authored
45 PortUpdate = hg(["update", Rev], [{cd, Directory}]),
7af82ca @yrashk Added hg support
yrashk authored
46 process_port(PortUpdate, fun () -> ok end)
47 end);
48 true -> %% existing
49 PortClone = hg(["pull", "-u", "-r", Rev],[{cd, Directory}]),
50 process_port(PortClone, fun () -> ok end)
8569013 @yrashk Added initial svn url support
yrashk authored
51 end;
52
53 fetch_1({svn, Url, Rev}, Directory) ->
54 io:format("[Fetching svn repository...]~n"),
55 case filelib:is_dir(Directory) of
56 false -> %% new
57 PortCheckout = svn(["checkout", "-r", Rev, Url, filename:basename(Directory)],
58 [{cd, filename:dirname(Directory)}]),
59 process_port(PortCheckout, fun () -> ok end);
60 true -> %% existing
61 PortUp = svn(["up", "-r", Rev],[{cd, Directory}]),
62 process_port(PortUp, fun () -> ok end)
114e3b3 @yrashk When git clone exists, just refresh it.
yrashk authored
63 end.
0cdd671 @yrashk Initial simplistic fetching functionality
yrashk authored
64
65 %%
66
f00cf10 @yrashk Added support for git tags and branches
yrashk authored
67 git_checkout({branch, Ref}, Directory) when is_list(Ref)->
114e3b3 @yrashk When git clone exists, just refresh it.
yrashk authored
68 PortCheckout = git(["checkout","-q","origin/" ++ Ref],[{cd, Directory}]),
f00cf10 @yrashk Added support for git tags and branches
yrashk authored
69 process_port(PortCheckout, fun () -> ok end);
70 git_checkout({tag, Ref}, Directory) when is_list(Ref) ->
71 PortCheckout = git(["checkout","-q",Ref],[{cd, Directory}]),
72 process_port(PortCheckout, fun () -> ok end);
73 git_checkout(Ref, Directory) when is_list(Ref) ->
74 PortCheckout = git(["checkout","-q",Ref],[{cd, Directory}]),
114e3b3 @yrashk When git clone exists, just refresh it.
yrashk authored
75 process_port(PortCheckout, fun () -> ok end).
76
0cdd671 @yrashk Initial simplistic fetching functionality
yrashk authored
77 git(Args) ->
78 git(Args,[]).
79
80 git(Args, Opts) ->
81 Git = os:find_executable("git"),
1d8fcb7 @yrashk Don't suppress git output
yrashk authored
82 open_port({spawn_executable, Git},[{args, Args},
0cdd671 @yrashk Initial simplistic fetching functionality
yrashk authored
83 exit_status|Opts]).
84
7af82ca @yrashk Added hg support
yrashk authored
85 hg(Args) ->
86 hg(Args,[]).
87
88 hg(Args, Opts) ->
89 Hg = os:find_executable("hg"),
90 open_port({spawn_executable, Hg},[{args, Args},
91 exit_status|Opts]).
92
8569013 @yrashk Added initial svn url support
yrashk authored
93 svn(Args, Opts) ->
94 Svn = os:find_executable("svn"),
95 open_port({spawn_executable, Svn},[{args, Args},
96 exit_status|Opts]).
97
0cdd671 @yrashk Initial simplistic fetching functionality
yrashk authored
98 process_port(Port, Fun) ->
99 receive
100 {Port, {exit_status, 0}} ->
101 apply(Fun, []);
102 {Port, {exit_status, Status}} ->
103 {error, Status};
104 {'EXIT', Port, PosixCode} ->
105 {error, PosixCode}
106 end.
Something went wrong with that request. Please try again.