Revision f551841a
b/kamaki/cli/command_shell.py | ||
---|---|---|
176 | 176 |
cmd_args = {} |
177 | 177 |
for arg in instance.arguments.values(): |
178 | 178 |
cmd_args[','.join(arg.parsed_name)] = arg.help |
179 |
print_dict(cmd_args, ident=14)
|
|
179 |
print_dict(cmd_args, ident=2)
|
|
180 | 180 |
stdout.write('%s %s' % (self.prompt, line)) |
181 | 181 |
return subcmd.get_subnames() |
182 | 182 |
self._register_method(complete_method, 'complete_%s' % cmd.name) |
b/kamaki/cli/commands/cyclades_cli.py | ||
---|---|---|
72 | 72 |
super(server_list, self).__init__(arguments) |
73 | 73 |
self.arguments['detail'] = FlagArgument('show detailed output', '-l') |
74 | 74 |
|
75 |
def _info_print(self, server): |
|
76 |
addr_dict = {} |
|
77 |
if 'attachments' in server: |
|
78 |
for addr in server['attachments']['values']: |
|
79 |
ips = addr.pop('values', []) |
|
80 |
for ip in ips: |
|
81 |
addr['IPv%s' % ip['version']] = ip['addr'] |
|
82 |
if 'firewallProfile' in addr: |
|
83 |
addr['firewall'] = addr.pop('firewallProfile') |
|
84 |
addr_dict[addr.pop('id')] = addr |
|
85 |
server['attachments'] = addr_dict if addr_dict is not {} else None |
|
86 |
if 'metadata' in server: |
|
87 |
server['metadata'] = server['metadata']['values'] |
|
88 |
print_dict(server, ident=2) |
|
89 |
|
|
75 | 90 |
def _print(self, servers): |
76 | 91 |
for server in servers: |
77 | 92 |
sname = server.pop('name') |
78 | 93 |
sid = server.pop('id') |
79 |
print('%s (%s)' % (bold(sname), bold(unicode(sid))))
|
|
94 |
print('%s (%s)' % (sid, bold(sname)))
|
|
80 | 95 |
if self.get_argument('detail'): |
81 |
server_info._print(server)
|
|
82 |
print('- - -')
|
|
96 |
self._info_print(server)
|
|
97 |
print(' ')
|
|
83 | 98 |
|
84 | 99 |
def main(self): |
85 | 100 |
super(self.__class__, self).main() |
86 | 101 |
try: |
87 | 102 |
servers = self.client.list_servers(self.get_argument('detail')) |
88 | 103 |
self._print(servers) |
89 |
#print_items(servers) |
|
90 | 104 |
except ClientError as err: |
91 | 105 |
raiseCLIError(err) |
92 | 106 |
|
... | ... | |
109 | 123 |
server['attachments'] = addr_dict if addr_dict is not {} else None |
110 | 124 |
if 'metadata' in server: |
111 | 125 |
server['metadata'] = server['metadata']['values'] |
112 |
print_dict(server, ident=14)
|
|
126 |
print_dict(server, ident=2)
|
|
113 | 127 |
|
114 | 128 |
def main(self, server_id): |
115 | 129 |
super(self.__class__, self).main() |
... | ... | |
435 | 449 |
super(flavor_list, self).__init__(arguments) |
436 | 450 |
self.arguments['detail'] = FlagArgument('show detailed output', '-l') |
437 | 451 |
|
452 |
@classmethod |
|
453 |
def _print(self, flist): |
|
454 |
for i, flavor in enumerate(flist): |
|
455 |
print(bold('%s. %s' % (i, flavor['name']))) |
|
456 |
print_dict(flavor, exclude=('name'), ident=2) |
|
457 |
print(' ') |
|
458 |
|
|
438 | 459 |
def main(self): |
439 | 460 |
super(self.__class__, self).main() |
440 | 461 |
try: |
441 | 462 |
flavors = self.client.list_flavors(self.get_argument('detail')) |
442 | 463 |
except ClientError as err: |
443 | 464 |
raiseCLIError(err) |
444 |
print_items(flavors) |
|
465 |
#print_list(flavors) |
|
466 |
self._print(flavors) |
|
445 | 467 |
|
446 | 468 |
|
447 | 469 |
@command(flavor_cmds) |
... | ... | |
522 | 544 |
if 'attachments' in net: |
523 | 545 |
att = net['attachments']['values'] |
524 | 546 |
net['attachments'] = att if len(att) > 0 else None |
525 |
print_dict(net, ident=14)
|
|
547 |
print_dict(net, ident=2)
|
|
526 | 548 |
|
527 | 549 |
def main(self, network_id): |
528 | 550 |
super(self.__class__, self).main() |
b/kamaki/cli/commands/image_cli.py | ||
---|---|---|
263 | 263 |
for img in images: |
264 | 264 |
iname = img.pop('name') |
265 | 265 |
iid = img.pop('id') |
266 |
print('%s (%s)' % (bold(iname), bold(unicode(iid))))
|
|
266 |
print('%s (%s)' % (unicode(iid), bold(iname)))
|
|
267 | 267 |
if self.get_argument('detail'): |
268 |
image_info._print(img) |
|
268 |
if 'metadata' in img: |
|
269 |
img['metadata'] = img['metadata']['values'] |
|
270 |
print_dict(img, ident=2) |
|
271 |
print(' ') |
|
269 | 272 |
|
270 | 273 |
def main(self): |
271 | 274 |
super(self.__class__, self).main() |
... | ... | |
284 | 287 |
def _print(self, image): |
285 | 288 |
if 'metadata' in image: |
286 | 289 |
image['metadata'] = image['metadata']['values'] |
287 |
print_dict(image, ident=14)
|
|
290 |
print_dict(image) |
|
288 | 291 |
|
289 | 292 |
def main(self, image_id): |
290 | 293 |
super(self.__class__, self).main() |
b/kamaki/cli/commands/pithos_cli.py | ||
---|---|---|
1168 | 1168 |
for acc in accounts: |
1169 | 1169 |
stdout.write(bold(acc['name']) + ' ') |
1170 | 1170 |
if self.get_argument('detail'): |
1171 |
print_dict(acc, exclude='name', ident=18)
|
|
1171 |
print_dict(acc, exclude='name', ident=4)
|
|
1172 | 1172 |
if not self.get_argument('detail'): |
1173 | 1173 |
|
1174 | 1174 |
|
b/kamaki/cli/utils.py | ||
---|---|---|
69 | 69 |
return new_d |
70 | 70 |
|
71 | 71 |
|
72 |
def print_dict(d, exclude=(), ident=0, rjust=True):
|
|
72 |
def print_dict(d, exclude=(), ident=0): |
|
73 | 73 |
if not isinstance(d, dict): |
74 | 74 |
raise CLIError(message='Cannot dict_print a non-dict object') |
75 |
if rjust: |
|
76 |
try: |
|
77 |
margin = max( |
|
78 |
1 + max(len(unicode(key).strip()) for key in d.keys() \ |
|
79 |
if not (isinstance(key, dict) or isinstance(key, list))), |
|
80 |
ident) |
|
81 |
except ValueError: |
|
82 |
margin = ident |
|
83 |
else: |
|
84 |
margin = ident |
|
75 |
|
|
76 |
margin = max(len(unicode(key).strip())\ |
|
77 |
for key in d.keys() if key not in exclude) |
|
85 | 78 |
|
86 | 79 |
for key, val in sorted(d.items()): |
87 | 80 |
if key in exclude: |
88 | 81 |
continue |
89 |
print_str = '%s:\t' % unicode(key).strip() |
|
90 |
print_str = print_str.rjust(margin) if rjust\ |
|
91 |
else '%s%s' % (' ' * margin, print_str) |
|
82 |
print_str = ' ' * ident |
|
83 |
print_str += ('%s' % key).strip() |
|
84 |
print_str += ' ' * (margin - len(unicode(key).strip())) |
|
85 |
print_str += ': ' |
|
92 | 86 |
if isinstance(val, dict): |
93 |
print(print_str + ' {') |
|
94 |
print_dict(val, exclude=exclude, ident=margin + 6, rjust=rjust) |
|
95 |
if rjust: |
|
96 |
print '}'.rjust(margin) |
|
97 |
else: |
|
98 |
print '}' |
|
87 |
print(print_str) |
|
88 |
print_dict(val, exclude=exclude, ident=margin + ident) |
|
99 | 89 |
elif isinstance(val, list): |
100 |
print(print_str + ' [') |
|
101 |
print_list(val, exclude=exclude, ident=margin + 6, rjust=rjust) |
|
102 |
if rjust: |
|
103 |
print ']'.rjust(margin) |
|
104 |
else: |
|
105 |
print']' |
|
90 |
print(print_str) |
|
91 |
print_list(val, exclude=exclude, ident=margin + ident) |
|
106 | 92 |
else: |
107 | 93 |
print print_str + ' ' + unicode(val).strip() |
108 | 94 |
|
109 | 95 |
|
110 |
def print_list(l, exclude=(), ident=0, rjust=True):
|
|
96 |
def print_list(l, exclude=(), ident=0): |
|
111 | 97 |
if not isinstance(l, list): |
112 | 98 |
raise CLIError(message='Cannot list_print a non-list object') |
113 |
try: |
|
114 |
margin = max( |
|
115 |
1 + max(len(unicode(item).strip()) for item in l \ |
|
116 |
if not isinstance(item, dict) and not isinstance(item, list)), |
|
117 |
ident) |
|
118 |
except ValueError: |
|
119 |
margin = ident |
|
99 |
|
|
100 |
margin = max(len(unicode(item).strip())\ |
|
101 |
for item in l if item not in exclude) |
|
120 | 102 |
|
121 | 103 |
for item in sorted(l): |
122 | 104 |
if item in exclude: |
123 | 105 |
continue |
124 | 106 |
if isinstance(item, dict): |
125 |
print '{'.rjust(margin) if rjust else '{' |
|
126 |
print_dict(item, exclude=exclude, ident=margin + 6) |
|
127 |
print '}'.rjust(margin) if rjust else '}' |
|
107 |
print_dict(item, exclude=exclude, ident=margin + ident) |
|
128 | 108 |
elif isinstance(item, list): |
129 |
print '['.rjust(margin) if rjust else ']' |
|
130 |
print_list(item, exclude=exclude, ident=margin + 6) |
|
131 |
print ']'.rjust(margin) if rjust else ']' |
|
109 |
print_list(item, exclude=exclude, ident=margin + ident) |
|
132 | 110 |
else: |
133 |
print unicode(item).rjust(margin) if rjust else unicode(item)
|
|
111 |
print ' ' * ident + unicode(item)
|
|
134 | 112 |
|
135 | 113 |
|
136 | 114 |
def print_items(items, title=('id', 'name')): |
Also available in: Unified diff