1 | open Logarion
|
---|
2 |
|
---|
3 | let index print title authors locations peers dir =
|
---|
4 | let fname = Filename.concat dir "index.pck" in
|
---|
5 | let pck = match Header_pack.of_string @@ File_store.to_string fname with
|
---|
6 | | Error s -> failwith s
|
---|
7 | | Ok pck -> let info = Header_pack.{ pck.info with
|
---|
8 | title = if title <> "" then title else pck.info.title;
|
---|
9 | people = if authors <> ""
|
---|
10 | then (String_set.list_of_csv authors) else pck.info.people;
|
---|
11 | locations = if locations <> ""
|
---|
12 | then (String_set.list_of_csv locations) else pck.info.locations;
|
---|
13 | } in
|
---|
14 | Header_pack.{ info; fields;
|
---|
15 | texts = of_text_list @@ File_store.fold ~dir
|
---|
16 | (fun a (t,_) -> of_text a t) [];
|
---|
17 | peers = if peers <> ""
|
---|
18 | then (str_list @@ String_set.list_of_csv peers) else pck.peers;
|
---|
19 | }
|
---|
20 | | exception (Sys_error _) -> Header_pack.{
|
---|
21 | info = {
|
---|
22 | version = version; id = Id.generate (); title;
|
---|
23 | people = String_set.list_of_csv authors;
|
---|
24 | locations = String_set.list_of_csv locations };
|
---|
25 | fields;
|
---|
26 | texts = of_text_list @@ File_store.fold ~dir
|
---|
27 | (fun a (t,_) -> of_text a t) [];
|
---|
28 | peers = str_list @@ String_set.list_of_csv peers;
|
---|
29 | } in
|
---|
30 | File_store.file fname (Header_pack.string pck);
|
---|
31 | let open Header_pack in
|
---|
32 | let s ss = String.concat "\n\t" ss in
|
---|
33 | if print then
|
---|
34 | Printf.printf "Title: %s\nAuthors: %s\nLocations:\n\t%s\nPeers:\n\t%s\n"
|
---|
35 | pck.info.title (String.concat "," pck.info.people)
|
---|
36 | (s pck.info.locations) (s (to_str_list pck.peers))
|
---|
37 |
|
---|
38 | open Cmdliner
|
---|
39 | let term =
|
---|
40 | let print = Arg.(value & flag & info ["print"] ~doc:"print info") in
|
---|
41 | let title= Arg.(value & opt string "" & info ["t"; "title"]
|
---|
42 | ~docv:"string" ~doc:"Title for index") in
|
---|
43 | let auth = Arg.(value & opt string "" & info ["a"; "authors"]
|
---|
44 | ~docv:"comma-separated names" ~doc:"Index authors") in
|
---|
45 | let locs = Arg.(value & opt string "" & info ["l"; "locations"]
|
---|
46 | ~docv:"comma-separated URLs" ~doc:"repository URLs") in
|
---|
47 | let peers= Arg.(value & opt string "" & info ["p"; "peers"]
|
---|
48 | ~docv:"comma-separated URLs" ~doc:"URLs to other known text repositories") in
|
---|
49 | let dir = Arg.(value & pos 0 string "." & info []
|
---|
50 | ~docv:"directory to index") in
|
---|
51 | let doc = "Generate an index.pck for texts in a directory" in
|
---|
52 | Term.(const index $ print $ title $ auth $ locs $ peers $ dir),
|
---|
53 | Term.info "index" ~doc
|
---|
54 | ~man:[ `S "DESCRIPTION"; `Pre "An index contains:\n
|
---|
55 | * an info section with: title for the index, the authors, locations (URLs) the texts can be access\n
|
---|
56 | * listing of texts with: ID, date, title, authors, topics\n
|
---|
57 | * list of other text repositories (peers)\n\n
|
---|
58 | MessagePack format. <msgpack.org>" ]
|
---|
59 |
|
---|