Skip to content

Commit

Permalink
Fixed AtributeError in issue #4 now if an attribute does not exist on…
Browse files Browse the repository at this point in the history
… an object, it is simply not printed.
  • Loading branch information
ryansb committed Feb 21, 2012
1 parent 590e2ba commit f7c6b15
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bin/impulse-query
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ def format_object(obj, headers=('Name', 'Owner', 'Modified')):
if not isinstance(obj, list):
obj = [obj, ]

def exists(o, h):
"""
Try to pull out a specified attribute from an object.
Returns True if successful, False if AttributeError
"""
try:
HEADERS[h]['get'](o)
return True
except AttributeError:
return False

headers = filter(lambda h: exists(obj[0], h), headers)

for h in headers:
formatter_string += "%%-%ds" % HEADERS[h]['length']
ret += formatter_string % headers
Expand Down

0 comments on commit f7c6b15

Please sign in to comment.