This commit is contained in:
swrup 2026-02-17 06:29:06 +01:00
parent 45648f15c1
commit 1e1b5dd2a9

View file

@ -26,7 +26,7 @@ module Recfile = struct
(fun hd tl -> String.of_seq (List.to_seq (hd :: tl))) (fun hd tl -> String.of_seq (List.to_seq (hd :: tl)))
first_char (many subsequent_char) first_char (many subsequent_char)
(* todo handle '\' escape and '+' on next line *) (* TODO handle '\' escape and '+' on next line *)
let field_value = take_till is_newline <* newline let field_value = take_till is_newline <* newline
let field = let field =
@ -51,30 +51,17 @@ module Recfile = struct
let parse s = parse_string ~consume:All recfile s let parse s = parse_string ~consume:All recfile s
end end
let url = let download url =
"https://git-www.gnunet.org/gana.git/plain/gnunet-signatures/registry.rec"
let registry_file = "registry.rec"
let download () =
let open Bos in let open Bos in
let res = let res =
OS.Cmd.run OS.Cmd.(
Cmd.( to_string
v "curl" (run_out
% "--silent" Cmd.(v "curl" % "--silent" % "--show-error" % "-X" % "GET" % url)))
% "--show-error"
% "-o"
% registry_file
% "-X"
% "GET"
% url)
in in
match res with match res with
| Error (`Msg s) -> Fmt.failwith "download failure: %s" s | Error (`Msg s) -> Fmt.failwith "download failure: %s" s
| Ok () -> () | Ok registry_rec -> registry_rec
let read_file file = In_channel.with_open_bin file In_channel.input_all
type purpose = { type purpose = {
number: int32; number: int32;
@ -100,13 +87,7 @@ let parse_purposes records =
| _ -> None) | _ -> None)
|> List.filter (fun v -> v.number >= 1000_l) |> List.filter (fun v -> v.number >= 1000_l)
let () = let print_module purposes =
download ();
let content = read_file registry_file in
match Recfile.parse content with
| Error msg -> Fmt.failwith "Recfile parse error: %s" msg
| Ok records ->
let purposes = parse_purposes records in
let header = let header =
{|(* This file was generated from the GANA database: {|(* This file was generated from the GANA database:
https://git-www.gnunet.org/gana.git/tree/gnunet-signatures/registry.rec *)|} https://git-www.gnunet.org/gana.git/tree/gnunet-signatures/registry.rec *)|}
@ -116,3 +97,16 @@ let () =
in in
Fmt.pr "%s\n\n%a@." header (Fmt.list ~sep:Fmt.nop pp) purposes; Fmt.pr "%s\n\n%a@." header (Fmt.list ~sep:Fmt.nop pp) purposes;
() ()
let url =
"https://git-www.gnunet.org/gana.git/plain/gnunet-signatures/registry.rec"
let main () =
let registry_rec = download url in
match Recfile.parse registry_rec with
| Error msg -> Fmt.failwith "Recfile parse error: %s" msg
| Ok records ->
print_module (parse_purposes records);
()
let () = main ()