[bind10-dev] pretty-printing stats (and bindctl results in general)

Jelte Jansen jelte at isc.org
Wed Jan 12 21:33:00 UTC 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


to save us from a little bit of task overhead, pretty-printing command
results (for instance the Stats show output) is quite easy, and a
trivial fix:

index 0e5b1bd..cb33977 100644
- --- a/src/bin/bindctl/bindcmd.py
+++ b/src/bin/bindctl/bindcmd.py
@@ -625,6 +625,9 @@ class BindCmdInterpreter(Cmd):
         print("send the command to cmd-ctrld")
         reply = self.send_POST(url, cmd.params)
         data = reply.read().decode()
- -        print("received reply:", data)
+        # The reply is a string containing JSON data,
+        # parse it, then prettyprint
+        if data != "" and data != "{}":
+            print(json.dumps(json.loads(data), sort_keys=True, indent=4))

this changes two things; it will no longer print 'empty' results
(commands that don't actually return any data still result in '{}' being
printed right now, and map results like Stats show are sorted and nicely
printed.

If someone could ack this i can just push the change :)

Jelte
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk0uHgwACgkQ4nZCKsdOncU8xACgk2XUyRIMhGssJc56Q2cGHPLw
D4QAoJx83a2BkpkmFy05RAuVsL1GNGvk
=0tJd
-----END PGP SIGNATURE-----



More information about the bind10-dev mailing list