[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#747883: ben: please let "ben monitor" output in a more machine readable format



Package: ben
Version: 0.6.11
Severity: wishlist
Tags: patch

Hi,

while the Levels and Text format are already quite parsable, it would be
nice if consumers of "ben monitor" output would not have to create a
specific parser for either format or trust in the format not
unexpectedly changing in the future. It would thus be nice if an
existing format like json, yaml, csv or xml could be used. Attached
please find a patch that enables json output.

cheers, josch
>From f1f4462f110161029a886fb14e50504074888a1b Mon Sep 17 00:00:00 2001
From: josch <j.schauer@email.de>
Date: Mon, 12 May 2014 16:16:53 +0200
Subject: [PATCH] add json support

---
 frontends/ben_monitor.ml | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/frontends/ben_monitor.ml b/frontends/ben_monitor.ml
index 30e8c2d..16bb005 100644
--- a/frontends/ben_monitor.ml
+++ b/frontends/ben_monitor.ml
@@ -30,8 +30,8 @@ let use_colors = ref false
 let output_file = ref None
 let baseurl = ref "file:///.."
 
-type output_type = Text | Xhtml | Levels
-let output_type = ref Levels
+type output_type = Text | Xhtml | Levels | Json
+let output_type = ref Json
 
 let p = Benl_clflags.progress
 let ( // ) = Filename.concat
@@ -92,6 +92,9 @@ let rec parse_local_args = function
   | "--html"::xs ->
       output_type := Xhtml;
       parse_local_args xs
+  | "--json"::xs ->
+      output_type := Json;
+      parse_local_args xs
   | "--use-projectb"::xs ->
       Benl_data.use_projectb := true;
       parse_local_args xs
@@ -114,6 +117,7 @@ let help () =
       "--color", "Color if text output";
       "--text", "Select text output format";
       "--html", "Select HTML output format";
+      "--json", "Select JSON output format";
       "--output|-o", "Select output file";
       "--template", "Select an HTML template";
     ]
@@ -527,6 +531,14 @@ let print_dependency_levels dep_graph rounds =
     end packages
   end rounds
 
+let print_json_monitor rounds = begin
+  printf "[%s]\n%!" begin String.concat "," begin List.map begin fun xs ->
+      let packages = List.sort (fun x y -> compare !!!x !!!y) xs in
+      let strpkgs = List.map begin fun src -> "\""^(!!!src)^"\"" end packages in
+      "["^(String.concat "," strpkgs)^"]"
+    end rounds end end
+end
+
 let compute_graph () =
   let {src_map = sources; bin_map = binaries} = get_data is_affected in
   let src_of_bin : ([`binary], [`source] Package.Name.t) M.t =
@@ -548,6 +560,7 @@ let main args =
   match !output_type with
     | Levels -> print_dependency_levels dep_graph rounds
     | Text -> print_text_monitor sources binaries rounds
+    | Json -> print_json_monitor rounds
     | Xhtml ->
       let template = Benl_templates.get_registered_template () in
       let (_, _, _, output) =
-- 
1.9.2


Reply to: