Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new exe to export keys and images from a base #17

Open
wants to merge 2 commits into
base: gnt
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
_build
**/.merlin
*~
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)
)
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