Merge "Add wrap option to keystone token-get for humans"
This commit is contained in:
@@ -39,12 +39,25 @@ def print_list(objs, fields, formatters={}):
|
|||||||
print pt.get_string(sortby=fields[0])
|
print pt.get_string(sortby=fields[0])
|
||||||
|
|
||||||
|
|
||||||
def print_dict(d):
|
def _word_wrap(string, max_length=0):
|
||||||
|
"""wrap long strings to be no longer then max_length"""
|
||||||
|
if max_length <= 0:
|
||||||
|
return string
|
||||||
|
return '\n'.join([string[i:i + max_length] for i in
|
||||||
|
range(0, len(string), max_length)])
|
||||||
|
|
||||||
|
|
||||||
|
def print_dict(d, wrap=0):
|
||||||
|
"""pretty table prints dictionaries.
|
||||||
|
|
||||||
|
Wrap values to max_length wrap if wrap>0
|
||||||
|
"""
|
||||||
pt = prettytable.PrettyTable(['Property', 'Value'], caching=False)
|
pt = prettytable.PrettyTable(['Property', 'Value'], caching=False)
|
||||||
pt.aligns = ['l', 'l']
|
pt.aligns = ['l', 'l']
|
||||||
for (prop, value) in d.iteritems():
|
for (prop, value) in d.iteritems():
|
||||||
if value is None:
|
if value is None:
|
||||||
value = ''
|
value = ''
|
||||||
|
value = _word_wrap(value, max_length=wrap)
|
||||||
pt.add_row([prop, value])
|
pt.add_row([prop, value])
|
||||||
print pt.get_string(sortby='Property')
|
print pt.get_string(sortby='Property')
|
||||||
|
|
||||||
|
@@ -406,6 +406,9 @@ def do_endpoint_delete(kc, args):
|
|||||||
print 'Unable to delete endpoint.'
|
print 'Unable to delete endpoint.'
|
||||||
|
|
||||||
|
|
||||||
|
@utils.arg('--wrap', metavar='<integer>', default=79,
|
||||||
|
help='wrap PKI tokens to a specified length, or 0 to disable')
|
||||||
def do_token_get(kc, args):
|
def do_token_get(kc, args):
|
||||||
"""Display the current user token"""
|
"""Display the current user token"""
|
||||||
utils.print_dict(kc.service_catalog.get_token())
|
utils.print_dict(kc.service_catalog.get_token(),
|
||||||
|
wrap=int(args.wrap))
|
||||||
|
Reference in New Issue
Block a user