Skip to content

Commit

Permalink
improve pretty_print()
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauvain Pocentek committed Jun 29, 2013
1 parent 53562b3 commit 05ab473
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions gitlab.py
Expand Up @@ -504,6 +504,17 @@ def short_print(self, depth=0):
self.shortPrintAttr.replace('_', '-'),
self.__dict__[self.shortPrintAttr]))

@staticmethod
def _obj_to_str(obj):
if isinstance(obj, dict):
s = ", ".join(["%s: %s" % (x, GitlabObject._obj_to_str(y)) for (x, y) in obj.items()])
return "{ %s }" % s
elif isinstance(obj, list):
s = ", ".join([GitlabObject._obj_to_str(x) for x in obj])
return "[ %s ]" %s
else:
return str(obj)

def pretty_print(self, depth=0):
id = self.__dict__[self.idAttr]
print("%s%s: %s" % (" " * depth * 2, self.idAttr, id))
Expand All @@ -521,6 +532,7 @@ def pretty_print(self, depth=0):
else:
if isinstance(v, Gitlab):
continue
v = GitlabObject._obj_to_str(v)
print("%s%s: %s" % (" " * depth * 2, pretty_k, v))

def json(self):
Expand Down

0 comments on commit 05ab473

Please sign in to comment.