Revision fa9c0c38 kamaki/cli/commands/pithos.py
b/kamaki/cli/commands/pithos.py | ||
---|---|---|
34 | 34 |
from sys import stdout |
35 | 35 |
from time import localtime, strftime |
36 | 36 |
from os import path, makedirs, walk |
37 |
from io import StringIO |
|
37 | 38 |
|
38 | 39 |
from kamaki.cli import command |
39 | 40 |
from kamaki.cli.command_tree import CommandTree |
40 | 41 |
from kamaki.cli.errors import raiseCLIError, CLISyntaxError, CLIBaseUrlError |
41 | 42 |
from kamaki.cli.utils import ( |
42 |
format_size, to_bytes, print_dict, print_items, page_hold, bold, ask_user,
|
|
43 |
format_size, to_bytes, print_dict, print_items, pager, bold, ask_user,
|
|
43 | 44 |
get_path_size, print_json, guess_mime_type) |
44 | 45 |
from kamaki.cli.argument import FlagArgument, ValueArgument, IntArgument |
45 | 46 |
from kamaki.cli.argument import KeyValueArgument, DateArgument |
... | ... | |
354 | 355 |
format=ValueArgument( |
355 | 356 |
'format to parse until data (default: d/m/Y H:M:S )', '--format'), |
356 | 357 |
shared=FlagArgument('show only shared', '--shared'), |
357 |
more=FlagArgument( |
|
358 |
'output results in pages (-n to set items per page, default 10)', |
|
359 |
'--more'), |
|
358 |
more=FlagArgument('read long results', '--more'), |
|
360 | 359 |
exact_match=FlagArgument( |
361 | 360 |
'Show only objects that match exactly with path', |
362 | 361 |
'--exact-match'), |
... | ... | |
367 | 366 |
if self['json_output']: |
368 | 367 |
print_json(object_list) |
369 | 368 |
return |
370 |
limit = int(self['limit']) if self['limit'] > 0 else len(object_list)
|
|
369 |
out = StringIO() if self['more'] else stdout
|
|
371 | 370 |
for index, obj in enumerate(object_list): |
372 | 371 |
if self['exact_match'] and self.path and not ( |
373 | 372 |
obj['name'] == self.path or 'content_type' in obj): |
... | ... | |
384 | 383 |
isDir = False |
385 | 384 |
size = format_size(obj['bytes']) |
386 | 385 |
pretty_obj['bytes'] = '%s (%s)' % (obj['bytes'], size) |
387 |
oname = bold(obj['name']) |
|
386 |
oname = obj['name'] if self['more'] else bold(obj['name'])
|
|
388 | 387 |
prfx = ('%s%s. ' % (empty_space, index)) if self['enum'] else '' |
389 | 388 |
if self['detail']: |
390 |
print('%s%s' % (prfx, oname))
|
|
391 |
print_dict(pretty_obj, exclude=('name')) |
|
392 |
print
|
|
389 |
out.writelines(u'%s%s\n' % (prfx, oname))
|
|
390 |
print_dict(pretty_obj, exclude=('name'), out=out)
|
|
391 |
out.writelines(u'\n')
|
|
393 | 392 |
else: |
394 |
oname = '%s%9s %s' % (prfx, size, oname) |
|
395 |
oname += '/' if isDir else ''
|
|
396 |
print(oname)
|
|
397 |
if self['more']:
|
|
398 |
page_hold(index, limit, len(object_list))
|
|
393 |
oname = u'%s%9s %s' % (prfx, size, oname)
|
|
394 |
oname += u'/' if isDir else u''
|
|
395 |
out.writelines(oname + u'\n')
|
|
396 |
if self['more']: |
|
397 |
pager(out.getvalue())
|
|
399 | 398 |
|
400 | 399 |
def print_containers(self, container_list): |
401 | 400 |
if self['json_output']: |
402 | 401 |
print_json(container_list) |
403 | 402 |
return |
404 |
limit = int(self['limit']) if self['limit'] > 0\ |
|
405 |
else len(container_list) |
|
403 |
out = StringIO() if self['more'] else stdout |
|
406 | 404 |
for index, container in enumerate(container_list): |
407 | 405 |
if 'bytes' in container: |
408 | 406 |
size = format_size(container['bytes']) |
409 | 407 |
prfx = ('%s. ' % (index + 1)) if self['enum'] else '' |
410 |
cname = '%s%s' % (prfx, bold(container['name'])) |
|
408 |
_cname = container['name'] if ( |
|
409 |
self['more']) else bold(container['name']) |
|
410 |
cname = u'%s%s' % (prfx, _cname) |
|
411 | 411 |
if self['detail']: |
412 |
print(cname)
|
|
412 |
out.writelines(cname + u'\n')
|
|
413 | 413 |
pretty_c = container.copy() |
414 | 414 |
if 'bytes' in container: |
415 | 415 |
pretty_c['bytes'] = '%s (%s)' % (container['bytes'], size) |
416 |
print_dict(pretty_c, exclude=('name')) |
|
417 |
print
|
|
416 |
print_dict(pretty_c, exclude=('name'), out=out)
|
|
417 |
out.writelines(u'\n')
|
|
418 | 418 |
else: |
419 | 419 |
if 'count' in container and 'bytes' in container: |
420 |
print('%s (%s, %s objects)' % ( |
|
421 |
cname, |
|
422 |
size, |
|
423 |
container['count'])) |
|
420 |
out.writelines(u'%s (%s, %s objects)\n' % ( |
|
421 |
cname, size, container['count'])) |
|
424 | 422 |
else: |
425 |
print(cname)
|
|
426 |
if self['more']:
|
|
427 |
page_hold(index + 1, limit, len(container_list))
|
|
423 |
out.writelines(cname + '\n')
|
|
424 |
if self['more']: |
|
425 |
pager(out.getvalue())
|
|
428 | 426 |
|
429 | 427 |
@errors.generic.all |
430 | 428 |
@errors.pithos.connection |
... | ... | |
1239 | 1237 |
* download <container>:<path> <local dir> -R |
1240 | 1238 |
will download all files on <container> prefixed as <path>, |
1241 | 1239 |
to <local dir>/<full path> (or <local dir>\<full path> in windows) |
1242 |
* download <container>:<path> <local dir> --exact-match
|
|
1243 |
will download only one file, exactly matching <path>
|
|
1240 |
* download <container>:<path> <local dir> |
|
1241 |
will download only one file<path> |
|
1244 | 1242 |
ATTENTION: to download cont:dir1/dir2/file there must exist objects |
1245 | 1243 |
cont:dir1 and cont:dir1/dir2 of type application/directory |
1246 | 1244 |
To create directory objects, use /file mkdir |
Also available in: Unified diff