Revision 8fa6ef6a

b/kamaki/cli/commands/pithos_cli.py
44 44
from sys import stdout
45 45
from time import localtime, strftime
46 46
from logging import getLogger
47
from os import path
47 48

  
48 49
kloger = getLogger('kamaki')
49 50

  
......
423 424
                        'No container %s in account %s'\
424 425
                        % (self.container, self.account),
425 426
                        details=self.generic_err_details)
427
                elif 'object' in ('%s' % err).lower():
428
                    raiseCLIError(
429
                        err,
430
                        'No object %s in container %s'\
431
                        % (self.path, self.container),
432
                        details=self.generic_err_details)
426 433
            raise_connection_errors(err)
427 434
            raiseCLIError(err)
428 435
        except Exception as err:
......
454 461
                        'No container %s in account %s'\
455 462
                        % (self.container, self.account),
456 463
                        details=self.generic_err_details)
464
                elif 'object' in ('%s' % err).lower():
465
                    raiseCLIError(
466
                        err,
467
                        'No object %s in container %s'\
468
                        % (self.path, self.container),
469
                        details=self.generic_err_details)
457 470
            raise_connection_errors(err)
458 471
            raiseCLIError(err)
459 472
        except Exception as err:
......
488 501
                        'No container %s in account %s'\
489 502
                        % (self.container, self.account),
490 503
                        details=self.generic_err_details)
504
                elif 'object' in ('%s' % err).lower():
505
                    raiseCLIError(
506
                        err,
507
                        'No object %s in container %s'\
508
                        % (self.path, self.container),
509
                        details=self.generic_err_details)
491 510
            raise_connection_errors(err)
492 511
            raiseCLIError(err)
493 512
        except Exception as e:
......
551 570
                        'No container %s in account %s'\
552 571
                        % (cont_msg, self.account),
553 572
                        details=self.generic_err_details)
573
                elif 'object' in ('%s' % err).lower():
574
                    raiseCLIError(
575
                        err,
576
                        'No object %s in container %s'\
577
                        % (self.path, self.container),
578
                        details=self.generic_err_details)
554 579
            raise_connection_errors(err)
555 580
            raiseCLIError(err)
556 581
        except Exception as e:
......
608 633
                        'No container %s in account %s'\
609 634
                        % (cont_msg, self.account),
610 635
                        details=self.generic_err_details)
636
                elif 'object' in ('%s' % err).lower():
637
                    raiseCLIError(
638
                        err,
639
                        'No object %s in container %s'\
640
                        % (self.path, self.container),
641
                        details=self.generic_err_details)
611 642
            raise_connection_errors(err)
612 643
            raiseCLIError(err)
613 644
        except Exception as e:
......
645 676
                        'No container %s in account %s'\
646 677
                        % (self.container, self.account),
647 678
                        details=self.generic_err_details)
679
                elif 'object' in ('%s' % err).lower():
680
                    raiseCLIError(
681
                        err,
682
                        'No object %s in container %s'\
683
                        % (self.path, self.container),
684
                        details=self.generic_err_details)
648 685
            raise_connection_errors(err)
649 686
            raiseCLIError(err)
650 687
        except Exception as e:
......
659 696
    """Truncate remote file up to a size"""
660 697

  
661 698
    def main(self, container___path, size=0):
662
        super(self.__class__,
663
            self).main(container___path, path_is_optional=False)
699
        super(self.__class__, self).main(container___path)
664 700
        try:
665 701
            self.client.truncate_object(self.path, size)
666 702
        except ClientError as err:
703
            if err.status == 404:
704
                if 'container' in ('%s' % err).lower():
705
                    raiseCLIError(
706
                        err,
707
                        'No container %s in account %s'\
708
                        % (self.container, self.account),
709
                        details=self.generic_err_details)
710
                elif 'object' in ('%s' % err).lower():
711
                    raiseCLIError(
712
                        err,
713
                        'No object %s in container %s'\
714
                        % (self.path, self.container),
715
                        details=self.generic_err_details)
716
            if err.status == 400 and\
717
                'object length is smaller than range length'\
718
                in ('%s' % err).lower():
719
                raiseCLIError(err, 'Object %s:%s <= %sb' % (
720
                    self.container,
721
                    self.path,
722
                    size))
723
            raise_connection_errors(err)
667 724
            raiseCLIError(err)
725
        except Exception as e:
726
            raiseCLIError(e)
668 727

  
669 728

  
670 729
@command(pithos_cmds)
......
680 739

  
681 740
    def main(self, local_path, container___path, start, end):
682 741
        super(self.__class__,
683
            self).main(container___path, path_is_optional=False)
742
            self).main(container___path, path_is_optional=True)
684 743
        try:
685
            f = open(local_path, 'rb')
686 744
            progress_bar = self.arguments['progress_bar']
745
            f = open(local_path, 'rb')
687 746
            try:
688 747
                upload_cb = progress_bar.get_generator('Overwritting blocks')
689 748
            except Exception:
690 749
                upload_cb = None
691
            self.client.overwrite_object(object=self.path,
750
            self.path = self.path if self.path else path.basename(local_path)
751
            self.client.overwrite_object(
752
                obj=self.path,
692 753
                start=start,
693 754
                end=end,
694 755
                source_file=f,
695 756
                upload_cb=upload_cb)
696 757
        except ClientError as err:
697 758
            progress_bar.finish()
759
            if err.status == 404:
760
                if 'container' in ('%s' % err).lower():
761
                    raiseCLIError(
762
                        err,
763
                        'No container %s in account %s'\
764
                        % (self.container, self.account),
765
                        details=self.generic_err_details)
766
                elif 'object' in ('%s' % err).lower():
767
                    raiseCLIError(
768
                        err,
769
                        'No object %s in container %s'\
770
                        % (self.path, self.container),
771
                        details=self.generic_err_details)
772
            raise_connection_errors(err)
698 773
            raiseCLIError(err)
774
        except Exception as e:
775
            progress_bar.finish()
776
            raiseCLIError(e)
699 777
        finally:
700 778
            progress_bar.finish()
701 779

  
702 780

  
703 781
@command(pithos_cmds)
704 782
class store_manifest(_store_container_command):
705
    """Create a remote file with uploaded parts by manifestation"""
783
    """Create a remote file of uploaded parts by manifestation
784
    How to use manifest:
785
    - upload parts of the file on a with names X.1, X.2, ...
786
    - /store manifest X
787
    An empty object X will behave as the result file of the
788
    union of X.1, X.2, ...
789
    """
706 790

  
707 791
    arguments = dict(
708 792
        etag=ValueArgument('check written data', '--etag'),
......
712 796
        content_disposition=ValueArgument(
713 797
            'the presentation style of the object',
714 798
            '--content-disposition'),
715
        content_type=ValueArgument('specify content type', '--content-type'),
799
        content_type=ValueArgument(
800
            'specify content type',
801
            '--content-type',
802
            default='application/octet-stream'),
716 803
        sharing=SharingArgument(
717 804
            'define object sharing policy \n' +\
718 805
            '    ( "read=user1,grp1,user2,... write=user1,grp2,..." )',
......
732 819
                sharing=self['sharing'],
733 820
                public=self['public'])
734 821
        except ClientError as err:
822
            if err.status == 404:
823
                if 'container' in ('%s' % err).lower():
824
                    raiseCLIError(
825
                        err,
826
                        'No container %s in account %s'\
827
                        % (self.container, self.account),
828
                        details=self.generic_err_details)
829
                elif 'object' in ('%s' % err).lower():
830
                    raiseCLIError(
831
                        err,
832
                        'No object %s in container %s'\
833
                        % (self.path, self.container),
834
                        details=self.generic_err_details)
835
            raise_connection_errors(err)
735 836
            raiseCLIError(err)
837
        except Exception as e:
838
            raiseCLIError(e)
736 839

  
737 840

  
738 841
@command(pithos_cmds)

Also available in: Unified diff