Revision df55e7aa kamaki/cli/utils/__init__.py
b/kamaki/cli/utils/__init__.py | ||
---|---|---|
48 | 48 |
|
49 | 49 |
suggest = dict(ansicolors=dict( |
50 | 50 |
active=False, |
51 |
url='#install-ansicolors-progress',
|
|
51 |
url='#install-ansicolors', |
|
52 | 52 |
description='Add colors to console responses')) |
53 | 53 |
|
54 | 54 |
try: |
... | ... | |
173 | 173 |
|
174 | 174 |
:param out: Input/Output stream to dump values into |
175 | 175 |
""" |
176 |
s = encode_for_console(dumps(data, indent=INDENT_TAB), encoding)
|
|
177 |
out.write(s + '\n')
|
|
176 |
out.write(dumps(data, indent=INDENT_TAB))
|
|
177 |
out.write('\n') |
|
178 | 178 |
out.flush() |
179 | 179 |
|
180 | 180 |
|
... | ... | |
213 | 213 |
print_str += '%s.' % (i + 1) if with_enumeration else '' |
214 | 214 |
print_str += '%s:' % k |
215 | 215 |
if isinstance(v, dict): |
216 |
out.write(encode_for_console(print_str) + '\n')
|
|
216 |
out.write(print_str + '\n')
|
|
217 | 217 |
print_dict( |
218 | 218 |
v, exclude, indent + INDENT_TAB, |
219 | 219 |
recursive_enumeration, recursive_enumeration, out) |
220 | 220 |
elif isinstance(v, list) or isinstance(v, tuple): |
221 |
out.write(encode_for_console(print_str) + '\n')
|
|
221 |
out.write(print_str + '\n')
|
|
222 | 222 |
print_list( |
223 | 223 |
v, exclude, indent + INDENT_TAB, |
224 | 224 |
recursive_enumeration, recursive_enumeration, out) |
225 | 225 |
else: |
226 |
out.write(encode_for_console('%s %s\n' % (print_str, v)))
|
|
226 |
out.write('%s %s\n' % (print_str, v))
|
|
227 | 227 |
out.flush() |
228 | 228 |
|
229 | 229 |
|
... | ... | |
260 | 260 |
print_str += '%s.' % (i + 1) if with_enumeration else '' |
261 | 261 |
if isinstance(item, dict): |
262 | 262 |
if with_enumeration: |
263 |
out.write(encode_for_console(print_str) + '\n')
|
|
263 |
out.write(print_str + '\n')
|
|
264 | 264 |
elif i and i < len(l): |
265 | 265 |
out.write('\n') |
266 | 266 |
print_dict( |
... | ... | |
269 | 269 |
recursive_enumeration, recursive_enumeration, out) |
270 | 270 |
elif isinstance(item, list) or isinstance(item, tuple): |
271 | 271 |
if with_enumeration: |
272 |
out.write(encode_for_console(print_str) + '\n')
|
|
272 |
out.write(print_str + '\n')
|
|
273 | 273 |
elif i and i < len(l): |
274 | 274 |
out.write('\n') |
275 | 275 |
print_list( |
... | ... | |
279 | 279 |
item = ('%s' % item).strip() |
280 | 280 |
if item in exclude: |
281 | 281 |
continue |
282 |
out.write(encode_for_console('%s%s\n' % (print_str, item)))
|
|
282 |
out.write('%s%s\n' % (print_str, item))
|
|
283 | 283 |
out.flush() |
284 | 284 |
out.flush() |
285 | 285 |
|
... | ... | |
304 | 304 |
return |
305 | 305 |
if not (isinstance(items, dict) or isinstance(items, list) or isinstance( |
306 | 306 |
items, tuple)): |
307 |
out.write(encode_for_console('%s\n' % items))
|
|
307 |
out.write('%s\n' % items)
|
|
308 | 308 |
out.flush() |
309 | 309 |
return |
310 | 310 |
|
311 | 311 |
for i, item in enumerate(items): |
312 | 312 |
if with_enumeration: |
313 |
out.write(encode_for_console('%s. ' % (i + 1)))
|
|
313 |
out.write('%s. ' % (i + 1))
|
|
314 | 314 |
if isinstance(item, dict): |
315 | 315 |
item = dict(item) |
316 | 316 |
title = sorted(set(title).intersection(item)) |
317 | 317 |
pick = item.get if with_redundancy else item.pop |
318 | 318 |
header = ' '.join('%s' % pick(key) for key in title) |
319 |
out.write(encode_for_console( |
|
320 |
(unicode(bold(header) if header else '') + '\n'))) |
|
319 |
out.write((unicode(bold(header) if header else '') + '\n')) |
|
321 | 320 |
print_dict(item, indent=INDENT_TAB, out=out) |
322 | 321 |
elif isinstance(item, list) or isinstance(item, tuple): |
323 | 322 |
print_list(item, indent=INDENT_TAB, out=out) |
324 | 323 |
else: |
325 |
out.write(encode_for_console(' %s\n' % item))
|
|
324 |
out.write(' %s\n' % item)
|
|
326 | 325 |
out.flush() |
327 | 326 |
out.flush() |
328 | 327 |
|
... | ... | |
447 | 446 |
""" |
448 | 447 |
yep = ', '.join(true_resp) |
449 | 448 |
nope = '<not %s>' % yep if 'n' in true_resp or 'N' in true_resp else 'N' |
450 |
out.write(encode_for_console('%s [%s/%s]: ' % (msg, yep, nope)))
|
|
449 |
out.write('%s [%s/%s]: ' % (msg, yep, nope))
|
|
451 | 450 |
out.flush() |
452 | 451 |
user_response = user_in.readline() |
453 | 452 |
return user_response[0].lower() in [s.lower() for s in true_resp] |
Also available in: Unified diff