Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 91 lines (66 sloc) 2.227 kB
4141c6e created new branches for eptic and erlangweb (1.3)
michal.ptaszek authored
1 #!/usr/bin/env escript
2
3 -include_lib("kernel/include/file.hrl").
4
5 main([]) ->
6 Name = string:strip(io:get_line("Name of the tarball: "), both, 10),
7 Url = string:strip(io:get_line("SVN address: "), both, 10),
8 main([Name, Url]);
9 main([Name, URL]) ->
10 Path = export_svn(URL, Name),
11 generate_pdf(Name, Path),
12
13 Tarball = create_tarball(Name, Path),
14 calculate_checksum(Tarball),
15
16 clean_up(Path).
17
18 export_svn(URL, Name) ->
19 Path = filename:join(["/tmp",
20 pid_to_list(self()),
21 Name]),
22 file:make_dir(filename:join("/tmp",
23 pid_to_list(self()))),
24
25 os:cmd(io_lib:format("svn export ~p ~p", [URL, Path])),
26
27 message("SVN version exported."),
28
29 Path.
30
31 generate_pdf(Name, Path) ->
32 DocPath = filename:join(Path, "doc"),
33 PDFName = filename:join(DocPath, Name ++ ".pdf"),
34
35 os:cmd(io_lib:format("make -C ~p", [DocPath])),
36
37 file:rename(filename:join(DocPath, "skeleton.pdf"),
38 PDFName),
39 message("PDF generated"),
40
41 clean_tex(DocPath, PDFName).
42
43 clean_tex(Path, PDF) ->
44 {ok, Dir} = file:list_dir(Path),
45 lists:foreach(fun(F) ->
46 delete_file(filename:join(Path, F), PDF)
47 end, Dir),
48
49 message("PDF cleaning up completed").
50
51 delete_file(PDF, PDF) ->
52 ok;
53 delete_file(File, PDF) ->
54 {ok, FileInfo} = file:read_file_info(File),
55 case FileInfo#file_info.type of
56 directory ->
57 {ok, Dir} = file:list_dir(File),
58 lists:foreach(fun(F) ->
59 delete_file(filename:join(File, F), PDF)
60 end, Dir),
61
62 file:del_dir(File);
63 _ ->
64 file:delete(File)
65 end.
66
67 create_tarball(Name, Path) ->
68 Result = Name ++ ".tar.gz",
69
70 os:cmd(io_lib:format("tar -czf ~p ~p", [Result, Path])),
71
72 message("Creating tar.gz completed"),
73 Result.
74
75 calculate_checksum(Tarball) ->
76 Md5 = hd(string:tokens(os:cmd("md5sum " ++ Tarball), " ")),
77 Sha1 = hd(string:tokens(os:cmd("sha1sum " ++ Tarball), " ")),
78
79 io:format("MD5: ~s~nSHA1: ~s~n", [Md5, Sha1]).
80
81 clean_up(Path) ->
82 {ok, Dir} = file:list_dir(Path),
83 lists:foreach(fun(F) ->
84 delete_file(filename:join(Path, F), "not used")
85 end, Dir),
86
87 message("Cleaning up completed").
88
89 message(Msg) ->
90 io:format("~s~n", [Msg]).
Something went wrong with that request. Please try again.