]> matita.cs.unibo.it Git - helm.git/blob - matitaB/matita/matitaFilesystem.ml
Added generation of HTML representation of the library.
[helm.git] / matitaB / matita / matitaFilesystem.ml
1 (* Copyright (C) 2004-2011, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 exception SvnError of string;;
27
28 let exec_process cmd =
29   let (stdout, stdin, stderr) as chs = Unix.open_process_full cmd [||] in
30   let outlines = ref [] in
31   let errlines = ref [] in
32   (try
33      while true do
34        outlines := input_line stdout :: !outlines;
35      done;
36      assert false
37    with End_of_file -> 
38    (try
39      while true do
40        errlines := input_line stderr :: !errlines;
41      done;
42      assert false
43     with End_of_file -> 
44      match (Unix.close_process_full chs) with
45      | Unix.WEXITED errno -> 
46         let output = "std out =\n" ^ String.concat "\n" (List.rev !outlines) in
47         let errors = "std err =\n" ^ String.concat "\n" (List.rev !errlines) in
48         errno, output ^ "\n\n" ^ errors
49      | _ -> assert false))
50
51 let checkout user =
52   let rt_dir = Helm_registry.get "matita.rt_base_dir" in
53   let repo = Helm_registry.get "matita.weblib" in
54
55   let errno, outstr = exec_process 
56     ("svn co " ^ repo ^ " " ^ rt_dir ^ "/users/" ^ user ^ "/scripts")
57   in
58   if errno = 0 then ()
59   else raise (SvnError outstr)
60
61 let html_of_library uid =
62   let i = ref 0 in
63   let newid () = incr i; ("node" ^ string_of_int !i) in
64
65   let branch text acc =
66     let id = newid () in
67     "<span class=\"trigger\" onClick=\"showBranch(" ^ id ^ ")\">\n" ^
68     "<img src=\"treeview/closed.gif\" id=\"I" ^ id ^ "\"/>\n" ^
69     text ^ "<br/></span>\n" ^
70     "<span class=\"branch\" id=\"" ^ id ^ "\">\n" ^
71     acc ^ "\n</span>"
72   in
73   let leaf text link =
74     "<img src=\"treeview/doc.gif\"/>\n" ^
75     "<a href=\"" ^ link ^ "\">" ^ text ^ "</a><br/>"
76   in
77
78   let rec aux path =
79     let dirlist = Array.to_list (Sys.readdir path) in
80     let subdirs = List.filter Sys.is_directory dirlist in
81     let scripts = 
82       List.filter (fun x -> 
83         try
84           let i = String.rindex x '.' in
85           not (Sys.is_directory x) && (String.sub x i 3 = ".ma")
86         with Not_found | Invalid_argument _ -> false) dirlist in
87     let subdirtags = 
88       String.concat "\n" (List.map (fun x -> aux (path ^ "/" ^ x)) subdirs) in
89     let scripttags =
90       String.concat "\n" 
91        (List.map (fun x -> leaf x (path ^ "/" ^ x)) scripts)
92     in
93     branch (Filename.basename path) (subdirtags ^ "\n" ^ scripttags)
94   in
95
96   let basedir = (Helm_registry.get "matita.rt_base_dir") ^ "/lib/" ^ uid ^ "/" in
97   let res = aux basedir in
98   prerr_endline "BEGIN TREE";prerr_endline res;prerr_endline "END TREE";
99   res
100 ;;