(* Copyright (C) 2004-2011, HELM Team. * * This file is part of HELM, an Hypertextual, Electronic * Library of Mathematics, developed at the Computer Science * Department, University of Bologna, Italy. * * HELM is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * HELM is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HELM; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * * For details, see the HELM World-Wide-Web page, * http://helm.cs.unibo.it/ *) exception SvnError of string;; let exec_process cmd = let (stdout, stdin, stderr) as chs = Unix.open_process_full cmd [||] in let outlines = ref [] in let errlines = ref [] in (try while true do outlines := input_line stdout :: !outlines; done; assert false with End_of_file -> (try while true do errlines := input_line stderr :: !errlines; done; assert false with End_of_file -> match (Unix.close_process_full chs) with | Unix.WEXITED errno -> let output = "std out =\n" ^ String.concat "\n" (List.rev !outlines) in let errors = "std err =\n" ^ String.concat "\n" (List.rev !errlines) in errno, output ^ "\n\n" ^ errors | _ -> assert false)) let checkout user = let rt_dir = Helm_registry.get "matita.rt_base_dir" in let repo = Helm_registry.get "matita.weblib" in let errno, outstr = exec_process ("svn co " ^ repo ^ " " ^ rt_dir ^ "/users/" ^ user ^ "/") in if errno = 0 then () else raise (SvnError outstr) let html_of_library uid = let i = ref 0 in let newid () = incr i; ("node" ^ string_of_int !i) in let basedir = (Helm_registry.get "matita.rt_base_dir") ^ "/users/" ^ uid in let branch text acc = let id = newid () in let name = Filename.basename text in let name = if name <> "." then name else "cic:/matita" in "\n" ^ "\n" ^ name ^ "
\n" ^ "\n" ^ acc ^ "\n" in let leaf text = "\n" ^ "" ^ (Filename.basename text) ^ "
" in let rec aux path = let lpath filename = path ^ "/" ^ filename in let gpath filename = basedir ^ "/" ^ path ^ "/" ^ filename in let dirlist = List.filter (fun x -> String.sub x 0 1 <> ".") (Array.to_list (Sys.readdir (basedir ^ "/" ^ path))) in let subdirs = List.filter (fun x -> Sys.is_directory (gpath x)) dirlist in let scripts = List.filter (fun x -> try let i = String.rindex x '.' in let len = String.length x - i in not (Sys.is_directory (gpath x)) && (String.sub x 0 1 <> ".") && (String.sub x i len = ".ma") with Not_found | Invalid_argument _ -> false) dirlist in let subdirtags = String.concat "\n" (List.map (fun x -> aux (lpath x)) subdirs) in let scripttags = String.concat "\n" (List.map (fun x -> leaf (lpath x)) scripts) in branch path (subdirtags ^ "\n" ^ scripttags) in let res = aux "." in prerr_endline "BEGIN TREE";prerr_endline res;prerr_endline "END TREE"; res ;;