From abf1b0df06ef1a1806da00eb91d98c5fe7a4bd72 Mon Sep 17 00:00:00 2001 From: Gauvain Pocentek Date: Sat, 18 May 2013 16:27:47 +0200 Subject: [PATCH] add a GitlabObject.pretty_print method --- gitlab.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gitlab.py b/gitlab.py index d0476d489..088d26663 100644 --- a/gitlab.py +++ b/gitlab.py @@ -448,6 +448,23 @@ def __init__(self, gl, data=None, **kwargs): def __str__(self): return '%s => %s' % (type(self), str(self.__dict__)) + def pretty_print(self, depth=0): + print "%sid: %s" % (" " * depth * 2, self.id) + for k in sorted(self.__dict__.keys()): + if k == "id": + continue + v = self.__dict__[k] + if isinstance(v, GitlabObject): + if depth == 0: + print "%s:" % k + v.pretty_print(1) + else: + print "%s: %s" % (k, v.id) + else: + if isinstance(v, Gitlab): + continue + print "%s%s: %s" % (" " * depth * 2, k, v) + def json(self): return json.dumps(self.__dict__, cls=jsonEncoder)