rename
This commit is contained in:
parent
1e30753ba9
commit
84472e93dd
160 changed files with 18460 additions and 90 deletions
89
.jjconflict-side-1/tools/gen_registry_files.ml
Normal file
89
.jjconflict-side-1/tools/gen_registry_files.ml
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
module Signature_code = struct
|
||||
type t = {
|
||||
number: int32;
|
||||
name: string;
|
||||
comment: string;
|
||||
}
|
||||
end
|
||||
|
||||
let parse_signature_codes 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
|
||||
Signature_code.
|
||||
{
|
||||
number= Int32.of_int (int_of_string a.v);
|
||||
name= String.lowercase_ascii b.v;
|
||||
comment= c.v;
|
||||
})
|
||||
| _ -> None)
|
||||
|> List.filter (fun v -> v.Signature_code.number >= 1000_l)
|
||||
|
||||
let pp_taler_signatures_ml ppf 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 Signature_code.{ number; name; comment } =
|
||||
Fmt.pf ppf "(** %s *)\nlet %s : int32 = %ld_l\n\n" comment name number
|
||||
in
|
||||
Fmt.pf ppf "%s\n\n%a@." header (Fmt.list ~sep:Fmt.nop pp) purposes;
|
||||
()
|
||||
|
||||
let download ~tmp ~url =
|
||||
let open Bos in
|
||||
let res =
|
||||
OS.Cmd.run
|
||||
Cmd.(
|
||||
v "curl" % "--silent" % "--show-error" % "-o" % tmp % "-X" % "GET" % url)
|
||||
in
|
||||
match res with
|
||||
| Error (`Msg s) -> Fmt.failwith "download failure: %s" s
|
||||
| Ok () -> ()
|
||||
|
||||
let signatures ~output =
|
||||
let url =
|
||||
"https://git-www.gnunet.org/gana.git/plain/gnunet-signatures/registry.rec"
|
||||
in
|
||||
let tmp_file = Bos.OS.File.tmp "registry.rec.%s" |> Result.get_ok in
|
||||
download ~tmp:(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 ->
|
||||
let purposes = parse_signature_codes records in
|
||||
let module_content = Fmt.str "%a" pp_taler_signatures_ml purposes in
|
||||
Bos.OS.File.write (Fpath.v output) module_content |> Result.get_ok
|
||||
|
||||
(* --- *)
|
||||
open Cmdliner
|
||||
open Cmdliner.Term.Syntax
|
||||
|
||||
let output =
|
||||
let doc = "output file" in
|
||||
Arg.(required & opt (some filepath) None & info [ "o"; "output" ] ~doc)
|
||||
|
||||
let signatures_cmd =
|
||||
let doc =
|
||||
"Generate taler_signatures.ml from GANA gnunet-signatures registry"
|
||||
in
|
||||
Cmd.make (Cmd.info "signatures" ~doc)
|
||||
@@
|
||||
let+ output = output in
|
||||
signatures ~output
|
||||
|
||||
let cli =
|
||||
let info =
|
||||
let doc = "Tool to generate OCaml module from GANA registries" in
|
||||
Cmd.info "gen_registry_files" ~doc
|
||||
in
|
||||
Cmd.group info [ signatures_cmd ]
|
||||
|
||||
let main () = Cmd.eval cli
|
||||
let () = if !Sys.interactive then () else exit (main ())
|
||||
Loading…
Add table
Add a link
Reference in a new issue