mirror of
https://gitlab.com/scemama/qmcchem.git
synced 2024-12-22 12:23:30 +01:00
Added md5 update
This commit is contained in:
parent
010c3374a4
commit
9b34e07283
@ -110,10 +110,15 @@ let hash () =
|
|||||||
else
|
else
|
||||||
""
|
""
|
||||||
in
|
in
|
||||||
let new_md5 = files_to_track
|
let md5_string =
|
||||||
|
files_to_track
|
||||||
|> List.map ~f:(fun x -> Printf.sprintf "%s/%s" ezfio_filename x)
|
|> List.map ~f:(fun x -> Printf.sprintf "%s/%s" ezfio_filename x)
|
||||||
|> List.map ~f:hash_file
|
|> List.map ~f:hash_file
|
||||||
|> String.concat
|
|> String.concat
|
||||||
|
in
|
||||||
|
|
||||||
|
let new_md5 =
|
||||||
|
md5_string
|
||||||
|> Cryptokit.hash_string (Cryptokit.Hash.md5 ())
|
|> Cryptokit.hash_string (Cryptokit.Hash.md5 ())
|
||||||
|> Cryptokit.transform_string (Cryptokit.Hexa.encode ())
|
|> Cryptokit.transform_string (Cryptokit.Hexa.encode ())
|
||||||
in
|
in
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
open Core.Std
|
open Core.Std
|
||||||
|
|
||||||
let run ?c ?d ~l ezfio_filename =
|
let run ?c ?d ~l ~update ezfio_filename =
|
||||||
|
|
||||||
Qputils.set_ezfio_filename ezfio_filename;
|
Qputils.set_ezfio_filename ezfio_filename;
|
||||||
|
|
||||||
@ -25,6 +25,43 @@ let run ?c ?d ~l ezfio_filename =
|
|||||||
Sys.file_exists_exn filename
|
Sys.file_exists_exn filename
|
||||||
in
|
in
|
||||||
|
|
||||||
|
if (update) then
|
||||||
|
begin
|
||||||
|
Printf.printf "Updating\n%!" ;
|
||||||
|
let update_one old_key =
|
||||||
|
Qmcchem_edit.run ~c:false ~input:(filename_of_key old_key) ezfio_filename;
|
||||||
|
Md5.reset_hash ();
|
||||||
|
let new_key =
|
||||||
|
Md5.hash ()
|
||||||
|
in
|
||||||
|
|
||||||
|
if (old_key <> new_key) then
|
||||||
|
begin
|
||||||
|
let new_name =
|
||||||
|
String.concat ~sep:"/" [ ezfio_filename; "blocks"; new_key ]
|
||||||
|
and old_name =
|
||||||
|
String.concat ~sep:"/" [ ezfio_filename; "blocks"; old_key ]
|
||||||
|
in
|
||||||
|
Printf.printf "Renaming %s -> %s\n" old_name new_name;
|
||||||
|
try Sys.rename old_name new_name with
|
||||||
|
| Sys_error _ -> ();
|
||||||
|
|
||||||
|
let old_name =
|
||||||
|
String.concat ~sep:"/" [ ezfio_filename; "input"; old_key ]
|
||||||
|
in
|
||||||
|
Printf.printf "Removing %s\n%!" old_name;
|
||||||
|
try Sys.remove old_name with
|
||||||
|
| Sys_error _ -> ();
|
||||||
|
end
|
||||||
|
in
|
||||||
|
let l =
|
||||||
|
Sys.ls_dir input_directory
|
||||||
|
in
|
||||||
|
List.iter l ~f:(fun x -> update_one x) ;
|
||||||
|
Printf.printf "Done\n%!" ;
|
||||||
|
end
|
||||||
|
;
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
match c with
|
match c with
|
||||||
| None -> ()
|
| None -> ()
|
||||||
@ -79,8 +116,8 @@ let run ?c ?d ~l ezfio_filename =
|
|||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
match (c,d,l) with
|
match (c,d,l,update) with
|
||||||
| (None,None,false) ->
|
| (None,None,false,false) ->
|
||||||
Printf.printf "Current key :\n%s\n" (Md5.hash ())
|
Printf.printf "Current key :\n%s\n" (Md5.hash ())
|
||||||
| _ -> handle_options ()
|
| _ -> handle_options ()
|
||||||
|
|
||||||
@ -94,6 +131,8 @@ let spec =
|
|||||||
~doc:("<key> Show input differences with <key>")
|
~doc:("<key> Show input differences with <key>")
|
||||||
+> flag "l" no_arg
|
+> flag "l" no_arg
|
||||||
~doc:(" List all the saved MD5 keys.")
|
~doc:(" List all the saved MD5 keys.")
|
||||||
|
+> flag "update" no_arg
|
||||||
|
~doc:(" Update to the latest MD5 format.")
|
||||||
+> anon ("ezfio_file" %: string)
|
+> anon ("ezfio_file" %: string)
|
||||||
|
|
||||||
|
|
||||||
@ -106,7 +145,7 @@ let command =
|
|||||||
Manipulate input MD5 keys
|
Manipulate input MD5 keys
|
||||||
")
|
")
|
||||||
spec
|
spec
|
||||||
(fun c d l ezfio_file () -> run ?c ?d ~l ezfio_file )
|
(fun c d l update ezfio_file () -> run ?c ?d ~l ~update ezfio_file )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user