Changeset 42 in code
- Timestamp:
- Dec 15, 2022, 9:25:18 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cli/convert.ml
r41 r42 27 27 t 28 28 29 let acc_ref id t a = 30 Conversion.Id_map.update t (function 31 | Some s -> Some (Conversion.Ref_set.add id s) 32 | None -> Some (Conversion.Ref_set.singleton id) 33 ) a 29 let acc_rel source target a = 30 prerr_endline source; 31 Conversion.Id_map.update target 32 (function Some set -> Some (Conversion.Ref_set.add source set) 33 | None -> Some (Conversion.Ref_set.singleton source)) 34 a 34 35 35 let fold_refs text refs = String_set.fold (acc_ref text.Text.id) (Text.set "references" text) refs 36 let fold_reps text reps = String_set.fold (acc_ref text.Text.id) (Text.set "in-reply-to" text) reps 36 let empty_rels () = Conversion.Id_map.empty, Conversion.Id_map.empty 37 38 let acc_txt_refs text refs = String_set.fold (acc_rel text.Text.id) (Text.set "references" text) refs 39 let acc_txt_reps text reps = String_set.fold (acc_rel text.Text.id) (Text.set "in-reply-to" text) reps 40 let acc_txt_rels (refs, reps) (elt, _paths) = 41 acc_txt_refs elt refs, acc_txt_reps elt reps 42 43 let acc_pck_refs id refs_ls refs = String_set.fold (acc_rel id) (String_set.of_list refs_ls) refs 44 let acc_pck_reps id reps_ls reps = String_set.fold (acc_rel id) (String_set.of_list reps_ls) reps 45 let acc_pck_rels refs_reps peer = 46 let path = try List.hd peer.Peers.pack.Header_pack.info.locations with Failure _ -> "" in 47 try Header_pack.fold 48 (fun (refs, reps) id _t _title _authors _topics refs_ls reps_ls -> 49 let id = Filename.concat path id in 50 acc_pck_refs id refs_ls refs, acc_pck_reps id reps_ls reps) 51 refs_reps peer.Peers.pack 52 with e -> prerr_endline "acc_pck_rels"; raise e 37 53 38 54 let directory converters noindex repo = 39 let fn (ts,refs,reps,ls,acc) ((elt,_) as r) = 40 Topic_set.to_map ts (Text.set "topics" elt), 41 fold_refs elt refs, fold_reps elt reps, 42 elt::ls, 43 if convert converters {repo with references = refs; replies = reps} r then acc+1 else acc in 44 let topics, references, replies, texts, count = 45 File_store.(fold ~dir:repo.Conversion.dir ~order:oldest fn 46 (Topic_set.Map.empty, Conversion.Id_map.empty, Conversion.Id_map.empty, [], 0)) in 55 let order = File_store.oldest in 56 let repo = 57 let references, replies = 58 File_store.fold ~dir:repo.Conversion.dir ~order acc_txt_rels (empty_rels ()) in 59 let references, replies = Peers.fold acc_pck_rels (references, replies) in 60 Printf.eprintf "%s %d\n" repo.Conversion.dir (Conversion.Id_map.cardinal replies); 61 { repo with references; replies } in 62 let acc (ts,ls,acc) ((elt,_) as r) = Topic_set.to_map ts (Text.set "topics" elt), elt::ls, 63 if convert converters repo r then acc+1 else acc in 64 let topics, texts, count = 65 File_store.fold ~dir:repo.Conversion.dir ~order acc (Topic_set.Map.empty, [], 0) in 47 66 let topic_roots = try List.rev @@ String_set.list_of_csv (Store.KV.find "Topics" repo.kv) 48 67 with Not_found -> Topic_set.roots topics in 49 Printf.eprintf "%d\n" (Conversion.Id_map.cardinal replies); 50 let repo = Conversion.{ repo with 51 topic_roots; topics; references; replies; texts = List.rev texts } in 68 let repo = Conversion.{ repo with topic_roots; topics; texts = List.rev texts } in 52 69 if not noindex then 53 70 List.iter (fun c -> match c.Conversion.indices with None -> () | Some f -> f repo) converters; … … 79 96 | Ok text -> 80 97 let dir = "." in 81 let references, replies = File_store.(fold ~dir ~order:newest 82 (fun (refs, reps) (elt, _) -> fold_refs elt refs, fold_reps elt reps) 83 (Conversion.Id_map.empty, Conversion.Id_map.empty)) in 98 let references, replies = File_store.(fold ~dir ~order:newest acc_txt_rels (empty_rels ())) in 84 99 let repo = { (Conversion.empty ()) with dir; kv = load_kv ""; references; replies } in 85 100 ignore @@ convert (converters types repo.kv) repo (text, [path]) -
trunk/cli/html.ml
r41 r42 89 89 ^ opt_kv "Replies:" (try 90 90 ref_links (Conversion.Id_map.find text.id conversion.Conversion.replies) 91 with Not_found -> " empty replies")91 with Not_found -> "") 92 92 ^ {|</dl></header><pre style="white-space:pre-wrap">|} in 93 93 wrap conversion htm text.title ((T.of_string text.body header) ^ "</pre></article>") -
trunk/cli/peers.ml
r31 r42 10 10 let open Logarion.Peers in 11 11 Printf.printf "%s" peer.path; 12 List.iter (Printf.printf "\t%s\n") peer. locations12 List.iter (Printf.printf "\t%s\n") peer.pack.info.locations 13 13 14 14 let remove_repo id = -
trunk/cli/pull.ml
r31 r42 76 76 output_string file txt; close_out file 77 77 78 let per_text url dir filter print i id time title authors topics = match id with78 let per_text url dir filter print i id time title authors topics _refs _reps = match id with 79 79 | "" -> Printf.eprintf "\nInvalid id for %s\n" title 80 80 | id -> let open Logarion in … … 128 128 let pull got_one peer_url = if got_one then got_one else 129 129 (pull_index peer_url auths topics) in 130 let open Logarion in 130 131 let fold_locations init peer = 131 ignore @@ List.fold_left pull init peer. Logarion.Peers.locations;132 ignore @@ List.fold_left pull init peer.Peers.pack.Header_pack.info.locations; 132 133 false 133 134 in 134 ignore @@ Logarion.Peers.fold fold_locations false;135 ignore @@ Peers.fold fold_locations false; 135 136 Curl.global_cleanup () 136 137 -
trunk/lib/file_store.ml
r32 r42 70 70 let expand_dir d = Array.(to_list @@ map (Filename.concat d) (Sys.readdir d)) in 71 71 let rec loop result = function 72 | f::fs when valid_dir f -> expand_dir f |> List.append fs |> loop result72 | f::fs when valid_dir f -> prerr_endline f; expand_dir f |> List.append fs |> loop result 73 73 | f::fs -> loop (f::result) fs 74 74 | [] -> result in -
trunk/lib/header_pack.ml
r22 r42 11 11 let str = Msgpck.of_string 12 12 let str_list ls = Msgpck.of_list @@ List.map str ls 13 let to_str_list x = List.map Msgpck.to_string (Msgpck.to_list x) 13 let to_str_list x = List.map Msgpck.to_string 14 (try Msgpck.to_list x with e -> prerr_endline "to_str_list"; raise e) 14 15 15 16 let of_set field t = … … 20 21 let to_sec = function Msgpck.Int i -> Int32.of_int i | Msgpck.Uint32 i -> i | x -> Msgpck.to_uint32 x 21 22 22 let fields = Msgpck.(List [String "id"; String "time"; String "title"; String "authors"; String "topics"]) 23 let fields = Msgpck.(List [ 24 String "id"; String "time"; String "title"; String "authors"; String "topics"; 25 String "references"; String "replies"; 26 ]) 23 27 let to_fields fieldpack = List.map Msgpck.to_string (Msgpck.to_list fieldpack) 24 28 … … 36 40 let open Text in 37 41 Msgpck.(List [ 38 of_id t.id; of_uint32 (date (Date.listing t.date)); 39 String t.title; persons t.authors; List (of_set "topics" t) 42 of_id t.id; 43 of_uint32 (date (Date.listing t.date)); 44 String t.title; 45 persons t.authors; 46 List (of_set "topics" t); 47 List (of_set "references" t); 48 List (of_set "in-reply-to" t); 40 49 ]) :: a 41 50 … … 82 91 let numof_texts pack = List.length (Msgpck.to_list pack.texts) 83 92 84 let iteri fn pack =85 let of_pck i = function Msgpck.List (id::time::title::authors::topics::[]) ->93 let txt_iter_apply fn i = function 94 | Msgpck.List (id::time::title::authors::topics::extra) -> 86 95 let t = match time with Msgpck.Int i -> Int32.of_int i | Msgpck.Uint32 i -> i 87 96 | x -> Msgpck.to_uint32 x in … … 90 99 let topics = to_str_list topics in 91 100 let authors = to_str_list authors in 92 fn i id t title authors topics 101 let references, replies = 102 try begin match extra with [] -> [], [] 103 | refs::[] -> to_str_list refs, [] 104 | refs::replies::_xs -> to_str_list refs, to_str_list replies 105 end with e -> prerr_endline "iter ref reps"; raise e 106 in 107 fn i id t title authors topics references replies 93 108 | _ -> prerr_endline ("\n\nInvalid record structure\n\n") 94 in List.iteri of_pck (Msgpck.to_list pack.texts);95 109 96 (*let pack_filename ?(filename="index.pck") archive =*) 97 (* let dir = Store.KV.find "Export-Dir" archive.File_store.kv in (*raises Not_found*)*) 98 (* dir ^ "/" ^ filename*) 110 let txt_fold_apply fn i m = 111 (* Printf.eprintf "%s\n%!" @@ Msgpck.show m;*) 112 match m with 113 | Msgpck.List (id::time::title::authors::topics::extra) -> 114 let t = match time with Msgpck.Int i -> Int32.of_int i | Msgpck.Uint32 i -> i 115 | x -> Msgpck.to_uint32 x in 116 let id = to_id id in 117 let title = Msgpck.to_string title in 118 let topics = try to_str_list topics with _e -> Printf.eprintf "topics %s" title; [] in 119 let authors = try to_str_list authors with _e -> Printf.eprintf "authors %s" title; [] in 120 let references, replies = begin match extra with 121 | [] -> [], [] 122 | refs::[] -> (try to_str_list refs, [] with e -> prerr_endline "fold ref"; raise e) 123 | refs::replies::_xs -> to_str_list refs, to_str_list replies 124 end 125 in 126 fn i id t title authors topics references replies 127 | x -> Printf.eprintf "Invalid record structure: %s\n%!" (Msgpck.show x); i 99 128 100 (*let add archive records =*) 101 (* let fname = pack_filename archive in*) 102 (* let append published (t, _f) = if List.exists (contains t) published then published else to_pack published t in*) 103 (* match list fname with Error e -> prerr_endline e | Ok published_list ->*) 104 (* let header_pack = List.fold_left append published_list records in*) 105 (* let archive = Msgpck.(List [*) 106 (* Int 0; String archive.File_store.name; persons archive.people]) in*) 107 (* File_store.file fname @@ Bytes.to_string*) 108 (* @@ Msgpck.Bytes.to_string (List [archive; fields; Msgpck.List header_pack])*) 129 let iteri fn pack = List.iteri (txt_iter_apply fn) (Msgpck.to_list pack.texts) 130 let fold fn init pack = List.fold_left (txt_fold_apply fn) init 131 (try Msgpck.to_list pack.texts with e -> prerr_string "Pack.fold"; raise e) -
trunk/lib/peers.ml
r31 r42 1 1 let text_dir = Filename.concat (File_store.txtdir ()) "peers" 2 2 3 type t = { path: string; locations: string list }3 type t = { path: string; pack: Header_pack.t } 4 4 5 5 let fold fn init = match Sys.readdir text_dir with … … 14 14 | true -> match Header_pack.of_string (File_store.to_string pack_path) with 15 15 | Error s -> Printf.eprintf "%s %s\n" s pack_path; init 16 | Ok p -> fn init { path; locations = Header_pack.(p.info.locations)}16 | Ok pack -> fn init { path; pack } 17 17 end else init 18 18 in
Note:
See TracChangeset
for help on using the changeset viewer.