Skip to content

Commit

Permalink
new exe to export keys and images from a base
Browse files Browse the repository at this point in the history
  • Loading branch information
Elie Canonici Merle committed Sep 23, 2024
1 parent c996e73 commit 6872732
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gwimages/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(executables
(names gwimages)
(libraries geneweb.gwdb-versioned geneweb.sosa_zarith geneweb)
)
4 changes: 4 additions & 0 deletions gwimages/dune~
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(executables
(names gwimages)
(libraries geneweb)
)
45 changes: 45 additions & 0 deletions gwimages/gwimages.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
let key_of_person base p =
let surname = Name.lower (Gwdb.p_surname base p) in
let first_name = Name.lower (Gwdb.p_first_name base p) in
let occ = string_of_int (Gwdb.get_occ p) in
String.concat "." [surname; first_name; occ]

let line_of_person base p =
let key = key_of_person base p in
let image = Gwdb.sou base (Gwdb.get_image p) in
Printf.sprintf "%s %s\n" key image

let has_image p =
not (Gwdb.is_empty_string (Gwdb.get_image p))

let output_images_of_base oc base =
Gwdb.Collection.iter begin fun p ->
if has_image p then
let line = line_of_person base p in
output_string oc line
else ()
end (Gwdb.persons base)

let () =
let bname = ref "" in
let output_file = ref "" in
let anonfun i = bname := i in
let speclist = [
"-o", Arg.String (fun s -> output_file := s), "set the output file"
]
in
let usage = "Usage: " ^ Sys.argv.(0) ^ " -o file base" in
Arg.parse speclist anonfun usage;
if !bname <> "" && !output_file <> "" then begin
Secure.set_base_dir (Filename.dirname !bname);
Lock.control_retry (Files.lock_file !bname) ~onerror:Lock.print_error_and_exit @@ fun () ->
let base = Gwdb.open_base !bname in
let oc = open_out !output_file in
output_images_of_base oc base;
close_out oc;
Gwdb.close_base base
end
else begin
Arg.usage speclist usage ;
exit 2
end
11 changes: 11 additions & 0 deletions gwimages/gwimages.ml~
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let () =
let bname = ref "" in
let output_file = ref "" in
let anonfun i = bname := i in
let speclist = [
"-o", Arg.String (fun s -> output_file := s), "set the output file"
]
let usage = "Usage: " ^ Sys.argv.(0) ^ " -o file base" in
Arg.parse speclist anonfun usage;
in
()

0 comments on commit 6872732

Please sign in to comment.