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

2014-10-25 Thread Mehdi Dogguy

Le 2014-05-12 17:16, Johannes Schauer a écrit :

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.



Thanks for the patch (and sorry for the very late reply).

I had a look at the patch, but it doesn't look complete compared to the 
Text
output. I'd rather add something really useful for everybody than some 
nitch

feature for a specific person.

I've updated the patch (following recent changes in the code). I'll 
implement

the missing bits some day.

Cheers.

--
MehdiFrom 213d950cd7c832ec373acd14dd7c5be96222cba3 Mon Sep 17 00:00:00 2001
From: josch j.scha...@email.de
Date: Mon, 12 May 2014 16:16:53 +0200
Subject: [PATCH] add json support

---
 frontends/ben_monitor.ml |   14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/frontends/ben_monitor.ml b/frontends/ben_monitor.ml
index 3d70d16..7522ba3 100644
--- a/frontends/ben_monitor.ml
+++ b/frontends/ben_monitor.ml
@@ -33,7 +33,7 @@ let output_file = ref None
 let input_config = ref None
 let baseurl = ref file:///..
 
-type output_type = Text | Xhtml | Levels
+type output_type = Text | Xhtml | Levels | Json
 let output_type = ref Levels
 
 let p = Benl_clflags.progress
@@ -104,6 +104,9 @@ let spec = Arg.align [
   --html, Arg.Unit (fun () -
 output_type := Xhtml)
   ,  Select HTML output format;
+  --json, Arg.Unit (fun () -
+output_type := Json)
+  ,  Select JSON output format;
   --use-projectb, Arg.Set Benl_data.use_projectb,  Get package lists from Projectb database;
   --output  , Arg.String (fun filename -
 output_file := Some filename
@@ -353,6 +356,14 @@ let beautify_text =
   )
   t
 
+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 data config =
   let architectures =
 List.map
@@ -607,6 +618,7 @@ let main _ =
   match !output_type with
 | Levels - print_dependency_levels dep_graph rounds
 | Text - print_text_monitor config sources binaries rounds
+| Json - print_json_monitor rounds
 | Xhtml -
   let template = Benl_templates.get_registered_template () in
   let monitor_data = compute_monitor_data config sources binaries rounds in
-- 
1.7.10.4



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

2014-05-12 Thread Johannes Schauer
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.scha...@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