clean up
This commit is contained in:
parent
45648f15c1
commit
2e5539eeb9
4 changed files with 126 additions and 121 deletions
67
tools/gen_taler_signatures.ml
Normal file
67
tools/gen_taler_signatures.ml
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
type purpose = {
|
||||
number: int32;
|
||||
name: string;
|
||||
comment: string;
|
||||
}
|
||||
|
||||
let download ~output ~url =
|
||||
let open Bos in
|
||||
let res =
|
||||
OS.Cmd.run
|
||||
Cmd.(
|
||||
v "curl"
|
||||
% "--silent"
|
||||
% "--show-error"
|
||||
% "-o"
|
||||
% output
|
||||
% "-X"
|
||||
% "GET"
|
||||
% url)
|
||||
in
|
||||
match res with
|
||||
| Error (`Msg s) -> Fmt.failwith "download failure: %s" s
|
||||
| Ok () -> ()
|
||||
|
||||
let parse_purposes records =
|
||||
records
|
||||
|> List.filter_map (fun l ->
|
||||
match l with
|
||||
| a :: b :: c :: _ -> (
|
||||
let open Recfile_parser in
|
||||
match a.k = "Number" && b.k = "Name" && c.k = "Comment" with
|
||||
| false -> None
|
||||
| true ->
|
||||
Some
|
||||
{
|
||||
number= Int32.of_int (int_of_string a.v);
|
||||
name= String.lowercase_ascii b.v;
|
||||
comment= c.v;
|
||||
})
|
||||
| _ -> None)
|
||||
|> List.filter (fun v -> v.number >= 1000_l)
|
||||
|
||||
let print_module purposes =
|
||||
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_l\n\n" comment name number
|
||||
in
|
||||
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 tmp_file = Bos.OS.File.tmp "registry.rec.%s" |> Result.get_ok in
|
||||
download ~output:(Fpath.to_string tmp_file) ~url;
|
||||
let content = Bos.OS.File.read tmp_file |> Result.get_ok in
|
||||
match Recfile_parser.parse content with
|
||||
| Error msg -> Fmt.failwith "Recfile_parser parse error: %s" msg
|
||||
| Ok records -> print_module (parse_purposes records)
|
||||
|
||||
let () = main ()
|
||||
Loading…
Add table
Add a link
Reference in a new issue