Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[util] move pretty_json to datadog/util #92

Merged
merged 2 commits into from
Oct 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions datadog/dogshell/downtime.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 3p
import simplejson as json
from datadog.util.format import pretty_json

# datadog
from datadog import api
Expand Down Expand Up @@ -58,7 +59,7 @@ def _schedule_downtime(cls, args):
report_warnings(res)
report_errors(res)
if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand All @@ -71,7 +72,7 @@ def _update_downtime(cls, args):
report_warnings(res)
report_errors(res)
if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand All @@ -91,7 +92,7 @@ def _show_downtime(cls, args):
report_warnings(res)
report_errors(res)
if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand All @@ -103,6 +104,6 @@ def _show_all_downtime(cls, args):
report_warnings(res)
report_errors(res)
if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))
5 changes: 3 additions & 2 deletions datadog/dogshell/host.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 3p
import simplejson as json
from datadog.util.format import pretty_json

# datadog
from datadog import api
Expand Down Expand Up @@ -36,7 +37,7 @@ def _mute(cls, args):
report_warnings(res)
report_errors(res)
if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand All @@ -48,6 +49,6 @@ def _unmute(cls, args):
report_warnings(res)
report_errors(res)
if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))
15 changes: 8 additions & 7 deletions datadog/dogshell/monitor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 3p
import simplejson as json
from datadog.util.format import pretty_json

# datadog
from datadog import api
Expand Down Expand Up @@ -88,7 +89,7 @@ def _post(cls, args):
report_warnings(res)
report_errors(res)
if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand All @@ -107,7 +108,7 @@ def _update(cls, args):
report_warnings(res)
report_errors(res)
if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand All @@ -123,7 +124,7 @@ def _show(cls, args):
res["id"] = str(res["id"])

if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand All @@ -140,7 +141,7 @@ def _show_all(cls, args):
d["id"] = str(d["id"])

if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
elif format == 'raw':
print(json.dumps(res))
else:
Expand Down Expand Up @@ -174,7 +175,7 @@ def _mute_all(cls, args):
report_warnings(res)
report_errors(res)
if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand All @@ -194,7 +195,7 @@ def _mute(cls, args):
report_warnings(res)
report_errors(res)
if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand All @@ -205,6 +206,6 @@ def _unmute(cls, args):
report_warnings(res)
report_errors(res)
if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))
15 changes: 8 additions & 7 deletions datadog/dogshell/screenboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# 3p
import simplejson as json
from datadog.util.format import pretty_json

# datadog
from datadog import api
Expand Down Expand Up @@ -131,7 +132,7 @@ def _push(cls, args):
report_errors(res)

if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand Down Expand Up @@ -180,7 +181,7 @@ def _post(cls, args):
report_warnings(res)
report_errors(res)
if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand All @@ -203,7 +204,7 @@ def _update(cls, args):
report_warnings(res)
report_errors(res)
if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand All @@ -225,7 +226,7 @@ def _show(cls, args):
res["id"] = str(res["id"])

if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand All @@ -245,7 +246,7 @@ def _share(cls, args):
res = api.Screenboard.share(args.screenboard_id)

if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand All @@ -256,7 +257,7 @@ def _revoke(cls, args):
res = api.Screenboard.revoke(args.screenboard_id)

if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand All @@ -280,7 +281,7 @@ def _new_file(cls, args):
cls._write_screen_to_file(res['id'], args.filename, args.timeout, format, args.string_ids)

if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand Down
3 changes: 2 additions & 1 deletion datadog/dogshell/service_check.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 3p
import simplejson as json
from datadog.util.format import pretty_json

# datadog
from datadog import api
Expand Down Expand Up @@ -33,6 +34,6 @@ def _check(cls, args):
report_warnings(res)
report_errors(res)
if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))
19 changes: 8 additions & 11 deletions datadog/dogshell/timeboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# datadog
from datadog import api
from datadog.util.format import pretty_json
from datadog.dogshell.common import report_errors, report_warnings, print_err
from datetime import datetime

Expand Down Expand Up @@ -109,7 +110,7 @@ def _title_to_filename(title):
return no_punct.replace(" ", "_").replace("-", "_").strip("_")

format = args.format
res = api.Timeboard.get_all()()
res = api.Timeboard.get_all()
report_warnings(res)
report_errors(res)

Expand Down Expand Up @@ -152,7 +153,7 @@ def _new_file(cls, args):
args.timeout, format, args.string_ids)

if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand Down Expand Up @@ -214,7 +215,7 @@ def _push(cls, args):
report_errors(res)

if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand All @@ -237,7 +238,7 @@ def _post(cls, args):
report_warnings(res)
report_errors(res)
if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand All @@ -259,7 +260,7 @@ def _update(cls, args):
report_warnings(res)
report_errors(res)
if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand All @@ -275,7 +276,7 @@ def _show(cls, args):
res["dash"]["id"] = str(res["dash"]["id"])

if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
else:
print(json.dumps(res))

Expand All @@ -292,7 +293,7 @@ def _show_all(cls, args):
d["id"] = str(d["id"])

if format == 'pretty':
print(cls._pretty_json(res))
print(pretty_json(res))
elif format == 'raw':
print(json.dumps(res))
else:
Expand Down Expand Up @@ -320,10 +321,6 @@ def _web_view(cls, args):
def _escape(cls, s):
return s.replace("\r", "\\r").replace("\n", "\\n").replace("\t", "\\t")

@classmethod
def _pretty_json(cls, obj):
return json.dumps(obj, sort_keys=True, indent=2)


def _template_variables(tpl_var_input):
if '[' not in tpl_var_input:
Expand Down
6 changes: 6 additions & 0 deletions datadog/util/format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 3p
import simplejson as json


def pretty_json(obj):
return json.dumps(obj, sort_keys=True, indent=2)