diff options
author | Lars Wirzenius <liw@liw.fi> | 2019-03-23 13:49:36 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2019-03-23 13:49:36 +0200 |
commit | 4dd778baeaef3db914b783dcf2cc80bb653d8f13 (patch) | |
tree | 1c6dd79fc232908b625c80b14886cd4043a6b509 | |
parent | 453ec49c56f98d88f07bdb9010587133c207e150 (diff) | |
download | effitool-4dd778baeaef3db914b783dcf2cc80bb653d8f13.tar.gz |
Refactor: DRY: move formatting JSON for output to its own method
-rwxr-xr-x | effitool | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -317,7 +317,7 @@ class Tool: token = self.get_admin_token(server) api = HTTPAPI(server['url']) memb = self._fetch_member(api, token, args['rid']) - print(json.dumps(memb, indent=4)) + self._format_json(memb, sys.stdout) def update_member(self, args): rid = args['rid'] @@ -390,7 +390,7 @@ class Tool: rid: self._fetch_member(api, token, rid) for rid in rids } - json.dump(members, sys.stdout, indent=4) + self._format_json(members, sys.stdout) def _fetch_member(self, api, token, rid): headers = { @@ -398,6 +398,9 @@ class Tool: } return api.get_json(token, '/memb', headers=headers) + def _format_json(self, obj, output): + return json.dump(obj, output, indent=4, sort_keys=True) + def uniq(items): return list(sorted(set(items))) |