X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;ds=sidebyside;f=matitaB%2Fmatita%2FmatitaFilesystem.ml;h=49091b2f5428cbd404cfbde0572999c147ea8d6e;hb=d8bc6fd4ab18f2995624c75e2889318237e9c17f;hp=1809627ca0a2543c607daaa0479f68b7ae434aa1;hpb=c0fe4fa6c136cc80037a9fbf1997cbb1d6763a3c;p=helm.git diff --git a/matitaB/matita/matitaFilesystem.ml b/matitaB/matita/matitaFilesystem.ml index 1809627ca..49091b2f5 100644 --- a/matitaB/matita/matitaFilesystem.ml +++ b/matitaB/matita/matitaFilesystem.ml @@ -23,6 +23,8 @@ * 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 @@ -50,8 +52,64 @@ 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 ^ "/" ^ user ^ "/scripts") + 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 - if errno = 0 then "checkout successful!" - else "checkout error!\n\n" ^ outstr + 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 +;; + +let reset_lib () = + let to_be_removed = (Helm_registry.get "matita.rt_base_dir") ^ "/users/*" in + ignore (Sys.command ("rm -rf " ^ to_be_removed)) +;;