[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



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.

--
Mehdi
From 213d950cd7c832ec373acd14dd7c5be96222cba3 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 |   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


Reply to: