@ -2,13 +2,13 @@ let result_to_html fmt results =
let score , max_score =
List . fold_left
( fun ( acc_score , acc_max_score ) r ->
match r with
| Ok ( msg , max_score ) ->
Utils . log fmt " -- %s (%d/%d)<br /> " msg max_score max_score ;
( acc_score + max_score , acc_max_score + max_score )
| Error ( msg , score , max_score ) ->
Format . fprintf fmt " -- %s (%d/%d)<br /> " msg score max_score ;
( acc_score + score , acc_max_score + max_score ) )
match r with
| Ok ( msg , max_score ) ->
Utils . log fmt " -- %s (%d/%d)<br /> " msg max_score max_score ;
( acc_score + max_score , acc_max_score + max_score )
| Error ( msg , score , max_score ) ->
Format . fprintf fmt " -- %s (%d/%d)<br /> " msg score max_score ;
( acc_score + score , acc_max_score + max_score ) )
( 0 , 0 ) results
in
Format . fprintf fmt " Final score: %d / %d<br /> " score max_score
@ -30,8 +30,128 @@ let output fmt result =
< / head >
< body >
< h1 > Orel results < / h1 >
< h3 > verbose is % s < / h3 >
< div id = " results " > % a < / div >
< br />
< a href = " index.html " > Go back to view home < / a >
< / body >
< / html >
| }
result_to_html result
( if ! Utils . verbose then " on " else " off " ) result_to_html result
(* * [view_summary fmt view_files] prints HTML into formatter [fmt]. [view_files] is a list of type [ ( file:string * score:string ) ] where file is a [.html] file found in directory _orel_view and [score] the final score given by orel. *)
let view_summary fmt view_files =
Format . fprintf fmt
{ | < ! DOCTYPE html >
< html lang = " en " >
< head >
< meta name = " description " content = " orel results " />
< meta name = " keywords " content = " lint, ocaml, orel, repository, score " />
< meta charset = " utf-8 " />
< style >
body { color : # 444 ; background - color : # EEEEEE ; line - height : 1 . 6 ; font - size : 18px ; }
< / style >
< title >
Orel results summary
< / title >
< / head >
< body >
< h1 > Orel_view Summary < / h1 >
< h3 > verbose is % s < / h3 >
< div id = " view_files " >
< ol >
% a
< / ol >
< / div >
< br />
< / body >
< / html >
| } ( if ! Utils . verbose then " on " else " off " )
( Format . pp_print_list ~ pp_sep : ( fun fmt () ->
Format . fprintf fmt " " )
( fun fmt ( target_file , final_score ) ->
Format . fprintf fmt { | < li > Package : < strong > % s < / strong > has score < strong > % s < / strong > .. . < a href = " %s " > ( View detail ) < / a > < / li > | }
( Filename . chop_extension target_file ) final_score target_file ) )
view_files
(* * [view source_dirs] takes a list of source directories and creates a directory name [_orel_view] in which *)
let view source_dirs =
let orel_view_dir = " _orel_view " in
(* check existence of [_orel_view] directory *)
match Bos . OS . Dir . exists ( Fpath . v orel_view_dir ) with
| Error e -> ( match e with
| ` Msg m -> Format . eprintf " %s@. " m ) ;
Utils . error " `Bos.OS.Dir.exists _orel_view` returned Error. (orel_opam_repo.ml). "
| Ok b ->
(* stop view construction if [_orel_view] directory already exists *)
if b then
begin
Format . eprintf " Directory _orel_view already exists...@. " ;
Utils . error " can't delete _orel_view dir. "
end
else
(* else create [_orel_view] directory and proceed *)
match Bos . OS . Dir . create ( Fpath . v orel_view_dir ) with
| Error e -> ( match e with
| ` Msg m -> Format . eprintf " %s@. " m ) ;
Utils . error " can't create _orel_view dir. "
| Ok _ b ->
(*
* view_files is a list of type ( file : string * score : string ) where :
* [ file ] is the name of a given HTML file for a given package
* [ score ] its score based on orel's checks
* * )
let view_files =
List . map
( fun path ->
(* name the file *)
let file = Filename . basename path ^ " .html " in
(* prepend the path to it *)
let target_file = orel_view_dir ^ " / " ^ file in
(* create file *)
( match Bos . OS . Cmd . run_status ~ quiet : true Bos . Cmd . ( v " touch " % target_file ) with
| Ok ( ` Exited 0 ) -> ()
| Error _ | Ok _ ->
Utils . error ( " can't create " ^ path ) ) ;
(* collect orel's results *)
let results = Check . check_local ( Fpath . v path ) in
(* open file, write to corresponding formatter and close *)
let out = open_out target_file in
let fmt = Format . formatter_of_out_channel out in
output fmt results ;
close_out out ;
(* collect score *)
let score , max_score =
List . fold_left
( fun ( acc_score , acc_max_score ) r ->
match r with
| Ok ( _ msg , max_score ) -> ( acc_score + max_score , acc_max_score + max_score )
| Error ( _ msg , score , max_score ) -> ( acc_score + score , acc_max_score + max_score )
) ( 0 , 0 ) results
in
file , Format . sprintf " %d / %d " score max_score )
source_dirs
in
(* writes summary of all view files in a index.html file under [_orel_view/] *)
let index_file = orel_view_dir ^ " / " ^ " index.html " in
(* create file *)
( match Bos . OS . Cmd . run_status ~ quiet : true Bos . Cmd . ( v " touch " % index_file ) with
| Ok ( ` Exited 0 ) -> ()
| Error _ | Ok _ ->
Utils . error ( " can't create " ^ index_file ) ) ;
(* open index.html, write to corresponding formatter and close *)
let out = open_out index_file in
let fmt = Format . formatter_of_out_channel out in
view_summary fmt view_files ;
close_out out ;