Revision ca092af4 kamaki/cli/commands/errors.py

b/kamaki/cli/commands/errors.py
37 37
from kamaki.clients import ClientError
38 38
from kamaki.cli.errors import CLIError, raiseCLIError, CLISyntaxError
39 39
from kamaki.cli import _debug, kloger
40
from kamaki.cli.utils import format_size
40 41

  
41 42
sendlog = logging.getLogger('clients.send')
42 43
datasendlog = logging.getLogger('data.send')
......
398 399
    '  1. Set store.container variable (permanent)',
399 400
    '     /config set store.container <container>',
400 401
    '  2. --container=<container> (temporary, overrides 1)',
401
    '  3. Use the container:path format (temporary, overrides all)']
402
    '  3. Use the container:path format (temporary, overrides all)',
403
    'For a list of containers: /store list']
402 404

  
403 405
    @classmethod
404 406
    def connection(this, foo):
......
429 431
                return foo(self, *args, **kwargs)
430 432
            except ClientError as ce:
431 433
                if ce.status == 404 and 'container' in ('%s' % ce).lower():
432
                        cont = '%s or %s' if dst_cont else self.container
434
                        cont = '%s or %s' % (self.container, dst_cont)\
435
                        if dst_cont else self.container
433 436
                        raiseCLIError(ce,
434
                            'No container %s in account %s' % (
437
                            'Is container %s in account %s ?' % (
435 438
                                cont,
436 439
                                self.account),
437 440
                            details=this.container_howto)
......
452 455
                        details=this.container_howto)
453 456
                raise
454 457
        return _raise
458

  
459
    @classmethod
460
    def object_size(this, foo):
461
        def _raise(self, *args, **kwargs):
462
            size = kwargs.get('size', None)
463
            start = kwargs.get('start', 0)
464
            end = kwargs.get('end', 0)
465
            if size:
466
                try:
467
                    size = int(size)
468
                except ValueError as ve:
469
                    raiseCLIError(ve,
470
                        'Invalid file size %s ' % size,
471
                        details=['size must be a positive integer'],
472
                        importance=1)
473
            else:
474
                try:
475
                    start = int(start)
476
                except ValueError as e:
477
                    raiseCLIError(e,
478
                        'Invalid start value %s in range' % start,
479
                        details=['size must be a positive integer'],
480
                        importance=1)
481
                try:
482
                    end = int(end)
483
                except ValueError as e:
484
                    raiseCLIError(e,
485
                        'Invalid end value %s in range' % end,
486
                        details=['size must be a positive integer'],
487
                        importance=1)
488
                if start > end:
489
                    raiseCLIError(
490
                        'Invalid range %s-%s' % (start, end),
491
                        details=['size must be a positive integer'],
492
                        importance=1)
493
                size = end - start
494
            try:
495
                return foo(self, *args, **kwargs)
496
            except ClientError as ce:
497
                err_msg = ('%s' % ce).lower()
498
                if size and (ce.status == 416 or
499
                (ce.status == 400 and\
500
                    'object length is smaller than range length' in err_msg)):
501
                    raiseCLIError(ce,
502
                        'Remote object %s:%s <= %s %s' % (
503
                            self.container,
504
                            self.path,
505
                            format_size(size),
506
                            ('(%sB)' % size) if size >= 1024 else ''))
507
                raise
508
        return _raise

Also available in: Unified diff