Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 73 lines (59 sloc) 2.399 kB
19de618 e_component uploader added
michal.ptaszek authored
1 #!/usr/bin/env escript
2
3 main(Args) ->
4 inets:start(),
5 application:start(crypto),
6 action(Args).
7
8 action(["add", Path]) ->
9 [AppName] = filelib:wildcard(Path ++ "/ebin/*.app"),
10 {ok, [{application, Name0, Props}]} = file:consult(AppName),
130442b merged erlangweb-1.2.1 to 1.3
michal.ptaszek authored
11 Md5Ctx = crypto:md5_init(),
19de618 e_component uploader added
michal.ptaszek authored
12
13 Name = atom_to_list(Name0),
14 Content = read_package(create_package(Name, Path)),
15
16 Username = string:strip(io:get_line("Username: "), both, 10),
130442b merged erlangweb-1.2.1 to 1.3
michal.ptaszek authored
17 ContentCtx = crypto:md5_update(Md5Ctx, Content),
18 PasswdCtx = crypto:md5_update(ContentCtx, string:strip(io:get_line("Password: "), both, 10)),
19 FinalMd5 = hash(binary_to_list(crypto:md5_final(PasswdCtx))),
19de618 e_component uploader added
michal.ptaszek authored
20
21 Categories = string:strip(io:get_line("Enter the categories for the ecomponent (separated by \",\"): "), both, 10),
22 Vsn = proplists:get_value(vsn, Props),
23 Desc = proplists:get_value(description, Props),
24 Author = proplists:get_value(author, Props, Username),
25
26 Params = string:join(lists:map(fun({Key, Val}) ->
27 Key ++ "=" ++ edoc_lib:escape_uri(Val)
28 end, [{"username", Username},
130442b merged erlangweb-1.2.1 to 1.3
michal.ptaszek authored
29 {"md5", FinalMd5},
19de618 e_component uploader added
michal.ptaszek authored
30 {"name", Name},
31 {"version", Vsn},
32 {"categories", Categories},
33 {"description", Desc},
34 {"author", Author},
130442b merged erlangweb-1.2.1 to 1.3
michal.ptaszek authored
35 {"package", base64:encode_to_string(Content)}]), [$&]),
19de618 e_component uploader added
michal.ptaszek authored
36
37 {ok, {_, _, Response}} = http:request(post, {"http://ecomponents.erlang-web.org/cgi-bin/add.py",
38 [{"content-length", integer_to_list(length(Params))},
39 {"user-agent", escript:script_name()}],
40 "application/x-www-form-urlencoded", Params},
41 [], []),
130442b merged erlangweb-1.2.1 to 1.3
michal.ptaszek authored
42 io:format("~s~n", [Response]);
43 action(_) ->
44 print_usage().
19de618 e_component uploader added
michal.ptaszek authored
45
46 create_package(Name, Path) ->
47 TarName = "/tmp/" ++ Name ++ ".tar.gz",
48 erl_tar:create(TarName, [Path], [compressed]),
49 TarName.
50
51 read_package(Path) ->
52 {ok, Binary} = file:read_file(Path),
53 file:delete(Path),
54 binary_to_list(Binary).
55
56 hash(String) ->
57 lists:flatten(lists:reverse(lists:foldl(fun(X, Acc) ->
58 int_to_hex(X, Acc)
59 end, [], String))).
60
61 int_to_hex(X, Acc) when X < 256 ->
62 [[hex(X div 16), hex(X rem 16)] | Acc].
63
64 hex(X) when X < 10 ->
65 $0 + X;
66 hex(X) ->
67 $a + (X-10).
130442b merged erlangweb-1.2.1 to 1.3
michal.ptaszek authored
68
69 print_usage() ->
70 io:format("Usage: bin/e_component_uploader.erl add Path~n"
71 "where Path specifies the path to the valid Erlang application~n"
72 "adds the component to the e_component repository~n").
Something went wrong with that request. Please try again.