Ejemplo n.º 1
0
    def restore(args):
        try:
            conf = load_conf()
            client = CosS3Client(conf)
            while args.cos_path.startswith('/'):
                args.cos_path = args.cos_path[1:]

            if not isinstance(args.cos_path, text_type):
                args.cos_path = args.cos_path.decode(fs_coding)
            Interface = client.op_int()
            kwargs = {}
            kwargs['day'] = args.day
            kwargs['tier'] = args.tier
            if args.recursive:
                if not Interface.restore_folder(cos_path=args.cos_path,
                                                **kwargs):
                    return 0
                else:
                    return -1
            else:
                if not Interface.restore_file(cos_path=args.cos_path, **
                                              kwargs):
                    return 0
                else:
                    return -1
        except Exception as e:
            logger.warn(e)
            return -2
Ejemplo n.º 2
0
 def download(args):
     try:
         conf = load_conf()
         client = CosS3Client(conf)
         Interface = client.op_int()
         if not isinstance(args.local_path, text_type):
             args.local_path = args.local_path.decode(fs_coding)
         if not isinstance(args.cos_path, text_type):
             args.cos_path = args.cos_path.decode(fs_coding)
         args.cos_path, args.local_path = concat_path(
             args.cos_path, args.local_path)
         if args.cos_path.startswith('/'):
             args.cos_path = args.cos_path[1:]
         kwargs = {}
         kwargs['force'] = args.force
         kwargs['sync'] = args.sync
         kwargs['num'] = min(20, args.num)
         kwargs['ignore'] = args.ignore.split(',')
         if args.recursive:
             rt = Interface.download_folder(args.cos_path, args.local_path,
                                            args.headers, **kwargs)
             return rt
         else:
             rt = Interface.download_file(args.cos_path, args.local_path,
                                          args.headers, **kwargs)
             return rt
         return -1
     except Exception as e:
         logger.warn(e)
         return -2
Ejemplo n.º 3
0
 def list_parts(args):
     try:
         conf = load_conf()
         client = CosS3Client(conf)
         Interface = client.op_int()
         if Interface.list_multipart(cos_path=args.cos_path):
             return 0
         else:
             return -1
     except Exception as e:
         logger.warn(e)
         return -2
Ejemplo n.º 4
0
 def create_bucket(args):
     try:
         conf = load_conf()
         client = CosS3Client(conf)
         Interface = client.op_int()
         if Interface.create_bucket():
             return 0
         else:
             logger.warn("Create bucket fail")
             return -1
     except Exception as e:
         logger.warn(e)
         return -2
Ejemplo n.º 5
0
 def get_bucket_versioning(args):
     try:
         conf = load_conf()
         client = CosS3Client(conf)
         Interface = client.op_int()
         rt = Interface.get_bucket_versioning()
         if rt is True:
             return 0
         else:
             logger.warn("Get bucket versioning fail")
             return -1
     except Exception as e:
         logger.warn(e)
         return -2
Ejemplo n.º 6
0
 def put_bucket_acl(args):
     try:
         conf = load_conf()
         client = CosS3Client(conf)
         Interface = client.op_int()
         rt = Interface.put_bucket_acl(args.grant_read, args.grant_write,
                                       args.grant_full_control)
         if rt is True:
             return 0
         else:
             logger.warn("put bucket acl fail")
             return -1
     except Exception as e:
         logger.warn(e)
         return -2
Ejemplo n.º 7
0
 def delete_bucket(args):
     try:
         conf = load_conf()
         client = CosS3Client(conf)
         Interface = client.op_int()
         kwargs = {}
         kwargs['force'] = args.force
         if Interface.delete_bucket(**kwargs):
             return 0
         else:
             logger.warn("Delete bucket fail")
             return -1
     except Exception as e:
         logger.warn(e)
         return -2
Ejemplo n.º 8
0
    def delete(args):
        try:
            conf = load_conf()
            client = CosS3Client(conf)
            while args.cos_path.startswith('/'):
                args.cos_path = args.cos_path[1:]
            Interface = client.op_int()

            if not isinstance(args.cos_path, text_type):
                args.cos_path = args.cos_path.decode(fs_coding)

            kwargs = {}
            kwargs['force'] = args.force
            kwargs['versions'] = args.versions
            kwargs['versionId'] = args.versionId
            if args.recursive:
                if args.cos_path.endswith('/') is False:
                    args.cos_path += '/'
                if args.cos_path == '/':
                    args.cos_path = ''
                if not Interface.delete_folder(args.cos_path, **kwargs):
                    logger.debug(
                        "delete all files under {cos_path} successfully!".
                        format(cos_path=to_printable_str(args.cos_path)))
                    return 0
                else:
                    logger.debug(
                        "delete all files under {cos_path} failed!".format(
                            cos_path=to_printable_str(args.cos_path)))
                    return -1
            else:
                if args.cos_path == '':
                    logger.warn("not support delete empty path")
                    return -1
                if not Interface.delete_file(args.cos_path, **kwargs):
                    logger.debug(
                        "delete all files under {cos_path} successfully!".
                        format(cos_path=to_printable_str(args.cos_path)))
                    return 0
                else:
                    logger.debug(
                        "delete all files under {cos_path} failed!".format(
                            cos_path=to_printable_str(args.cos_path)))
                    return -1
        except Exception as e:
            logger.warn(e)
            return -2
Ejemplo n.º 9
0
 def probe(args):
     try:
         conf = load_conf()
         client = CosS3Client(conf)
         Interface = client.op_int()
         kwargs = {}
         kwargs['test_num'] = args.num
         kwargs['file_size'] = args.size
         rt = Interface.probe(**kwargs)
         if 0 == rt:
             return 0
         else:
             logger.warn("probe failed")
             return -1
     except Exception as e:
         logger.warn(e)
         return -2
Ejemplo n.º 10
0
    def info(args):
        try:
            conf = load_conf()
            client = CosS3Client(conf)
            while args.cos_path.startswith('/'):
                args.cos_path = args.cos_path[1:]

            if not isinstance(args.cos_path, text_type):
                args.cos_path = args.cos_path.decode(fs_coding)
            Interface = client.op_int()
            if not Interface.info_object(args.cos_path, _human=args.human):
                return 0
            else:
                return -1
        except Exception as e:
            logger.warn(e)
            return -2
Ejemplo n.º 11
0
    def get_object_acl(args):
        try:
            conf = load_conf()
            client = CosS3Client(conf)
            while args.cos_path.startswith('/'):
                args.cos_path = args.cos_path[1:]
            if not isinstance(args.cos_path, text_type):
                args.cos_path = args.cos_path.decode(fs_coding)
            Interface = client.op_int()

            rt = Interface.get_object_acl(args.cos_path)
            if rt is True:
                return 0
            else:
                logger.warn("Get object acl fail")
                return -1
        except Exception as e:
            logger.warn(e)
            return -2
Ejemplo n.º 12
0
 def signurl(args):
     try:
         conf = load_conf()
         client = CosS3Client(conf)
         if not isinstance(args.cos_path, text_type):
             args.cos_path = args.cos_path.decode(fs_coding)
         while args.cos_path.startswith('/'):
             args.cos_path = args.cos_path[1:]
         try:
             Interface = client.op_int()
             rt = Interface.sign_url(args.cos_path, args.timeout)
             if rt:
                 return 0
             else:
                 return -1
         except Exception:
             logger.warn('Geturl fail')
             return -1
     except Exception as e:
         logger.warn(e)
         return -2
Ejemplo n.º 13
0
 def list(args):
     try:
         conf = load_conf()
         client = CosS3Client(conf)
         while args.cos_path.startswith('/'):
             args.cos_path = args.cos_path[1:]
         if not isinstance(args.cos_path, text_type):
             args.cos_path = args.cos_path.decode(fs_coding)
         Interface = client.op_int()
         kwargs = {}
         kwargs['recursive'] = args.recursive
         kwargs['all'] = args.all
         kwargs['num'] = args.num
         kwargs['human'] = args.human
         kwargs['versions'] = args.versions
         if not Interface.list_objects(cos_path=args.cos_path, **kwargs):
             return 0
         else:
             return -1
     except Exception as e:
         logger.warn(e)
         return -2
Ejemplo n.º 14
0
    def copy(args):
        try:
            conf = load_conf()
            client = CosS3Client(conf)
            Interface = client.op_int()
            _, args.cos_path = concat_path(args.source_path, args.cos_path)
            while args.cos_path.startswith('/'):
                args.cos_path = args.cos_path[1:]
            if not isinstance(args.source_path, text_type):
                args.source_path = args.source_path.decode(fs_coding)
            if not isinstance(args.cos_path, text_type):
                args.cos_path = args.cos_path.decode(fs_coding)

            kwargs = {}
            kwargs['sync'] = args.sync
            kwargs['directive'] = args.directive
            if args.recursive:
                _, args.cos_path = concat_path(args.source_path, args.cos_path)
                if args.cos_path.endswith('/') is False:
                    args.cos_path += '/'
                if args.cos_path.startswith('/'):
                    args.cos_path = args.cos_path[1:]
                if not Interface.copy_folder(args.source_path, args.cos_path,
                                             args.headers, **kwargs):
                    return 0
                else:
                    return 1
            else:
                if not Interface.copy_file(args.source_path, args.cos_path,
                                           args.headers, **kwargs):
                    return 0
                else:
                    return -1
        except Exception as e:
            logger.warn(e)
            return -2
Ejemplo n.º 15
0
    def upload(args):
        try:
            conf = load_conf()
            client = CosS3Client(conf)
            while args.cos_path.startswith('/'):
                args.cos_path = args.cos_path[1:]
            if args.cos_path == "":
                args.cos_path = "/"
            Interface = client.op_int()

            if not isinstance(args.local_path, text_type):
                args.local_path = args.local_path.decode(fs_coding)
            if not isinstance(args.cos_path, text_type):
                args.cos_path = args.cos_path.decode(fs_coding)

            if not os.path.exists(args.local_path):
                logger.warn("cannot stat '%s': No such file or directory" %
                            to_printable_str(args.local_path))
                return -1

            if not os.access(args.local_path, os.R_OK):
                logger.warn('local_path %s is not readable!' %
                            to_printable_str(args.local_path))
                return -1
            args.local_path, args.cos_path = concat_path(
                args.local_path, args.cos_path)
            if args.cos_path.startswith('/'):
                args.cos_path = args.cos_path[1:]
            kwargs = {}
            kwargs['sync'] = args.sync
            kwargs['mutex'] = args.mutex
            kwargs['skipmd5'] = args.skipmd5
            kwargs['ignore'] = args.ignore.split(',')
            kwargs['force'] = args.force
            if args.recursive:
                if os.path.isfile(args.local_path) is True:
                    rt = Interface.upload_file(args.local_path, args.cos_path,
                                               args.headers, **kwargs)
                    return rt
                elif os.path.isdir(args.local_path):
                    rt = Interface.upload_folder(args.local_path,
                                                 args.cos_path, args.headers,
                                                 **kwargs)
                    return rt
            else:
                if os.path.isdir(args.local_path):
                    logger.warn(
                        "\"{path}\" is a directory, use \'-r\' option to upload it please"
                        .format(path=to_printable_str(args.local_path)))
                    return -1
                if os.path.isfile(args.local_path) is False:
                    logger.warn("cannot stat '%s': No such file or directory" %
                                to_printable_str(args.local_path))
                    return -1
                rt = Interface.upload_file(args.local_path, args.cos_path,
                                           args.headers, **kwargs)
                return rt
            return -1
        except Exception as e:
            logger.wran(e)
            return -2