示例#1
0
    def mv(self, args):
        opts = utils.CommandOptions(args)
        client = storage.Client(**opts.client_kwargs)

        if self.cp(args) is not False:
            if '://' in args.src:
                parts = args.src.split('://', 1)
                client.remove_object(
                    '_global', bucket_name=parts[0], object_name=parts[1])
            else:
                os.remove(args.src)
示例#2
0
    def rm(self, args):
        opts = utils.CommandOptions(args)
        client = storage.Client(**opts.client_kwargs)

        for obj in args.object:
            if '://' not in obj:
                print('*** specify objects in the format bucket://object')
                return False

            parts = obj.split('://', 1)
            client.remove_object(
                '_global', bucket_name=parts[0], object_name=parts[1])
示例#3
0
    def cat(self, args):
        opts = utils.CommandOptions(args)
        client = storage.Client(**opts.client_kwargs)

        for obj in args.object:
            if '://' not in obj:
                print('*** specify objects in the format bucket://object')
                return False

            parts = obj.split('://', 1)

            content = client.download_object(
                '_global', bucket_name=parts[0], object_name=parts[1])
            sys.stdout.buffer.write(content)
示例#4
0
    def _cp_file_to_object(self, opts, src, dst):
        if os.path.isdir(src):
            print('*** {} is a directory'.format(src))
            return False

        parts = dst.split('://', 1)
        dst_bucket = parts[0]
        if len(parts) > 1:
            dst_object = parts[1]
        else:
            _, dst_object = os.path.split(src)

        client = storage.Client(**opts.client_kwargs)
        client.upload_object(
            '_global', bucket_name=dst_bucket, object_name=dst_object, file_obj=src)
示例#5
0
    def _cp_object_to_file(self, opts, src, dst):
        parts = src.split('://', 1)
        src_bucket = parts[0]
        src_object = parts[1]
        _, src_filename = os.path.split(src_object)

        client = storage.Client(**opts.client_kwargs)
        content = client.download_object(
            '_global', bucket_name=src_bucket, object_name=src_object)

        if os.path.isdir(dst):
            target_file = os.path.join(dst, src_filename)
        else:
            target_file = dst

        with open(target_file, 'wb') as f:
            f.write(content)
示例#6
0
    def ls(self, args):
        opts = utils.CommandOptions(args)
        client = storage.Client(**opts.client_kwargs)

        if args.bucket:
            if '://' in args.bucket:
                bucket_name, prefix = args.bucket.split('://', 1)
            else:
                bucket_name = args.bucket
                prefix = None

            delimiter = '/'
            if args.recurse:
                delimiter = None

            listing = client.list_objects(opts.instance,
                                          bucket_name=bucket_name,
                                          delimiter=delimiter,
                                          prefix=prefix)
            rows = []
            for prefix in listing.prefixes:
                url = '{}://{}'.format(bucket_name, prefix)
                if args.long:
                    rows.append(['0', '', url])
                else:
                    rows.append([url])

            for obj in listing.objects:
                url = '{}://{}'.format(bucket_name, obj.name)
                if args.long:
                    rows.append(
                        [str(obj.size),
                         to_isostring(obj.created), url])
                else:
                    rows.append([url])

            utils.print_table(rows)
        else:
            for bucket in client.list_buckets(opts.instance):
                print(bucket.name)
from __future__ import print_function

from yamcs import storage
from yamcs.core import GLOBAL_INSTANCE


def print_buckets(instance):
    for bucket in client.list_buckets(instance=instance):
        print(' {} ({} objects, {} bytes)'.format(bucket, bucket.object_count,
                                                  bucket.size))
        listing = bucket.list_objects()
        print('  prefixes:', listing.prefixes)
        for obj in listing.objects:
            print('  object:', obj)


if __name__ == '__main__':
    client = storage.Client('localhost:8090')

    print('Buckets:')
    print_buckets(instance='simulator')

    print('\nGlobal buckets:')
    print_buckets(instance=GLOBAL_INSTANCE)
示例#8
0
    def rb(self, args):
        opts = utils.CommandOptions(args)
        client = storage.Client(**opts.client_kwargs)

        for bucket in args.bucket:
            client.remove_bucket('_global', bucket_name=bucket)
示例#9
0
    def mb(self, args):
        opts = utils.CommandOptions(args)
        client = storage.Client(**opts.client_kwargs)

        for bucket in args.bucket:
            client.create_bucket(opts.instance, bucket_name=bucket)