This commit is contained in:
parent
49352fa7ca
commit
ae4acc5537
3 changed files with 310 additions and 19 deletions
|
|
@ -8,7 +8,4 @@
|
|||
(public_name gen_signatures_registry)
|
||||
(name gen_signatures_registry)
|
||||
(modules gen_signatures_registry)
|
||||
(libraries angstrom fmt))
|
||||
|
||||
; fetch `gnunet-signatures/registry.rec` with:
|
||||
; curl -s -o registry.rec -X GET "https://git-www.gnunet.org/gana.git/plain/gnunet-signatures/registry.rec"
|
||||
(libraries angstrom bos fmt))
|
||||
|
|
|
|||
|
|
@ -51,13 +51,29 @@ let parse s = parse_string ~consume:All recfile s
|
|||
|
||||
(* -- *)
|
||||
|
||||
let 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 res =
|
||||
OS.Cmd.run Cmd.(v "curl" % "-s" % "-o" % registry_file % "-X" % "GET" % url)
|
||||
in
|
||||
match res with
|
||||
| Error (`Msg s) -> Fmt.failwith "download failure: %s" s
|
||||
| Ok () -> ()
|
||||
|
||||
let read_file file = In_channel.with_open_bin file In_channel.input_all
|
||||
|
||||
type purpose = {
|
||||
number: int32;
|
||||
name: string;
|
||||
comment: string;
|
||||
}
|
||||
|
||||
let f records =
|
||||
let parse_purposes records =
|
||||
records
|
||||
|> List.filter_map (fun l ->
|
||||
match l with
|
||||
|
|
@ -68,27 +84,25 @@ let f records =
|
|||
Some
|
||||
{
|
||||
number= Int32.of_int (int_of_string a.v);
|
||||
name= b.v;
|
||||
name= String.lowercase_ascii b.v;
|
||||
comment= c.v;
|
||||
})
|
||||
| _ -> None)
|
||||
|>
|
||||
(*GNU Taler, >= 1000*)
|
||||
List.filter (fun v -> v.number >= 1000_l)
|
||||
|
||||
let read_file file = In_channel.with_open_bin file In_channel.input_all
|
||||
let file_header = {|...|}
|
||||
|> List.filter (fun v -> v.number >= 1000_l)
|
||||
|
||||
let () =
|
||||
let content = read_file "registry.rec" in
|
||||
download ();
|
||||
let content = read_file registry_file in
|
||||
match parse content with
|
||||
| Error msg -> Fmt.failwith "Parse error: %s" msg
|
||||
| Error msg -> Fmt.failwith "Recfile parse error: %s" msg
|
||||
| Ok records ->
|
||||
let purposes = f records in
|
||||
|
||||
let pp_purpose ppf { number; name; comment } =
|
||||
let purposes = parse_purposes records in
|
||||
let header =
|
||||
{|(* This file was generated from the GANA database:
|
||||
https://git-www.gnunet.org/gana.git/tree/gnunet-signatures/registry.rec *)|}
|
||||
in
|
||||
let pp ppf { number; name; comment } =
|
||||
Fmt.pf ppf "(** %s *)\nlet %s : int32 = %ld\n\n" comment name number
|
||||
in
|
||||
|
||||
Fmt.pr "%a@." (Fmt.list ~sep:Fmt.nop pp_purpose) purposes;
|
||||
Fmt.pr "%s\n\n%a@." header (Fmt.list ~sep:Fmt.nop pp) purposes;
|
||||
()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue