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

Refacto gwpublic scripts #6

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
Useful scripts for geneweb not included in official release to
be used with `gwrepl`.

Usually, using a script will be invocated using this pattern

```
cat script.ml | GWREPL_PPF=/dev/null GWREPL_NOPROMPT=1 gwrepl [arg1, ..., argN]
```

See README of each subdirectory for more details about each tool.
23 changes: 0 additions & 23 deletions gwpublic/gwiftitles.ml

This file was deleted.

29 changes: 0 additions & 29 deletions gwpublic/gwprivate.ml

This file was deleted.

27 changes: 0 additions & 27 deletions gwpublic/gwpublic.ml

This file was deleted.

109 changes: 0 additions & 109 deletions gwpublic/gwpublic2.ml

This file was deleted.

File renamed without changes.
64 changes: 5 additions & 59 deletions gwpublic/gwaccess.ml → privacy/gwaccess.ml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
open Geneweb
open Gwdb
let open Def in
let open Gwdb in

(** [oldest_year_of p]
Find a year in [[ birth ; baptism ; death ]].
*)
let oldest_year_of p =
let open Def in
match Adef.od_of_cdate (get_birth p) with
| Some (Dgreg (d, _)) -> Some d.year
| _ -> match Adef.od_of_cdate (get_baptism p) with
| Some (Dgreg (d, _)) -> Some d.year
| _ -> match Date.date_of_death (get_death p) with
| Some (Dgreg (d, _)) -> Some d.year
| _ -> None
in

(** [most_recent_year_of p]
Find a year in [[ death ; baptism ; birth ]].
*)
let most_recent_year_of p =
let open Def in
match Date.date_of_death (get_death p) with
| Some (Dgreg (d, _)) -> Some d.year
| _ -> match Adef.od_of_cdate (get_baptism p) with
| Some (Dgreg (d, _)) -> Some d.year
| _ -> match Adef.od_of_cdate (get_birth p) with
| Some (Dgreg (d, _)) -> Some d.year
| _ -> None
in

let find_dated_ancestor base p =
let mark = Gwdb.iper_marker (Gwdb.ipers base) false in
Expand Down Expand Up @@ -65,58 +65,4 @@ let find_dated_ancestor base p =
loop_ind anc_list
in
loop 1 [get_iper p]

let input_person file =
let pl = ref [] in
begin match (try Some (open_in file) with Sys_error _ -> None) with
Some ic ->
begin try
while true do let line = input_line ic in pl := line :: !pl done
with End_of_file -> ()
end;
close_in ic
| None -> Printf.eprintf "Error while opening file %s\n" file; flush stderr
end;
List.rev !pl

let access_everybody access bname =
let base = Gwdb.open_base bname in
Gwdb.Collection.iter begin fun p ->
if get_access p <> access then
let p = {(gen_person_of_person p) with Def.access = access} in
patch_person base p.Def.key_index p
end (Gwdb.persons base) ;
commit_patches base

let access_some access bname key =
let base = Gwdb.open_base bname in
match Gutil.person_ht_find_all base key with
[ip] ->
let p = poi base ip in
if get_access p <> access then
begin let p = {(gen_person_of_person p) with Def.access = access} in
patch_person base p.Def.key_index p
end;
commit_patches base
| _ ->
match Gutil.person_of_string_dot_key base key with
Some ip ->
let p = poi base ip in
if get_access p <> access then
begin let p =
{(gen_person_of_person p) with Def.access = access}
in
patch_person base p.Def.key_index p
end;
commit_patches base
| None -> Printf.eprintf "Bad key %s\n" key; flush stderr

let access_some_list access bname file =
if Sys.file_exists file then
let pl = input_person file in List.iter (access_some access bname) pl
else
begin
Printf.eprintf "File does not exist : %s\n" file;
flush stderr;
exit 2
end
in
Loading