Skip to content

Commit abf1b0d

Browse files
author
Gauvain Pocentek
committed
add a GitlabObject.pretty_print method
1 parent bc9d440 commit abf1b0d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

gitlab.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,23 @@ def __init__(self, gl, data=None, **kwargs):
448448
def __str__(self):
449449
return '%s => %s' % (type(self), str(self.__dict__))
450450

451+
def pretty_print(self, depth=0):
452+
print "%sid: %s" % (" " * depth * 2, self.id)
453+
for k in sorted(self.__dict__.keys()):
454+
if k == "id":
455+
continue
456+
v = self.__dict__[k]
457+
if isinstance(v, GitlabObject):
458+
if depth == 0:
459+
print "%s:" % k
460+
v.pretty_print(1)
461+
else:
462+
print "%s: %s" % (k, v.id)
463+
else:
464+
if isinstance(v, Gitlab):
465+
continue
466+
print "%s%s: %s" % (" " * depth * 2, k, v)
467+
451468
def json(self):
452469
return json.dumps(self.__dict__, cls=jsonEncoder)
453470

0 commit comments

Comments
 (0)