38 |
38 |
|
39 |
39 |
from kamaki.cli import command
|
40 |
40 |
from kamaki.cli.command_tree import CommandTree
|
41 |
|
from kamaki.cli.errors import raiseCLIError, CLISyntaxError, CLIBaseUrlError
|
|
41 |
from kamaki.cli.errors import (
|
|
42 |
raiseCLIError, CLISyntaxError, CLIBaseUrlError, CLIInvalidArgument)
|
42 |
43 |
from kamaki.cli.utils import (
|
43 |
44 |
format_size, to_bytes, bold, get_path_size, guess_mime_type)
|
44 |
45 |
from kamaki.cli.argument import FlagArgument, ValueArgument, IntArgument
|
... | ... | |
338 |
339 |
exact_match=FlagArgument(
|
339 |
340 |
'Show only objects that match exactly with path',
|
340 |
341 |
'--exact-match'),
|
341 |
|
enum=FlagArgument('Enumerate results', '--enumerate')
|
|
342 |
enum=FlagArgument('Enumerate results', '--enumerate'),
|
|
343 |
recursive=FlagArgument(
|
|
344 |
'Recursively list containers and their contents',
|
|
345 |
('-R', '--recursive'))
|
342 |
346 |
)
|
343 |
347 |
|
344 |
348 |
def print_objects(self, object_list):
|
... | ... | |
392 |
396 |
else:
|
393 |
397 |
self.writeln(cname)
|
394 |
398 |
|
|
399 |
def _argument_context_check(self):
|
|
400 |
container_level_only = ('recursive', )
|
|
401 |
object_level_only = ('delimiter', 'path', 'exact_match')
|
|
402 |
details, mistake = [], ''
|
|
403 |
if self.container:
|
|
404 |
for term in container_level_only:
|
|
405 |
if self[term]:
|
|
406 |
details = [
|
|
407 |
'This is a container-level argument',
|
|
408 |
'Use it without a <container> parameter']
|
|
409 |
mistake = self.arguments[term]
|
|
410 |
else:
|
|
411 |
for term in object_level_only:
|
|
412 |
if self[term]:
|
|
413 |
details = [
|
|
414 |
'This is an opbject-level argument',
|
|
415 |
'Use it with a <container> parameter']
|
|
416 |
mistake = self.arguments[term]
|
|
417 |
if mistake and details:
|
|
418 |
raise CLIInvalidArgument(
|
|
419 |
'Invalid use of %s argument' % '/'.join(mistake.parsed_name),
|
|
420 |
details=details + ['Try --help for more details'])
|
|
421 |
|
395 |
422 |
@errors.generic.all
|
396 |
423 |
@errors.pithos.connection
|
397 |
424 |
@errors.pithos.object_path
|
398 |
425 |
@errors.pithos.container
|
399 |
426 |
def _run(self):
|
400 |
427 |
files, prnt = None, None
|
401 |
|
if self.container is None:
|
|
428 |
self._argument_context_check()
|
|
429 |
if not self.container:
|
402 |
430 |
r = self.client.account_get(
|
403 |
431 |
limit=False if self['more'] else self['limit'],
|
404 |
432 |
marker=self['marker'],
|