def test_batch_rename_force(self): ret,info = self.bucket.rename(bucket_name, 'copyfrom', 'copyfrom', force='true') print(info) assert info.status_code == 200 ops = build_batch_rename(bucket_name, {'copyfrom':'copyfrom'}, force='true') ret, info = self.bucket.batch(ops) print(info) assert ret[0]['code'] == 200
def test_batch_rename_force(self): ret, info = self.bucket.rename(bucket_name, 'copyfrom', 'copyfrom', force='true') print(info) assert info.status_code == 200 ops = build_batch_rename(bucket_name, {'copyfrom': 'copyfrom'}, force='true') ret, info = self.bucket.batch(ops) print(info) assert ret[0]['code'] == 200
def test_batch_rename_force(self): ret, info = self.bucket.rename(bucket_name, "copyfrom", "copyfrom", force="true") print(info) assert info.status_code == 200 ops = build_batch_rename(bucket_name, {"copyfrom": "copyfrom"}, force="true") ret, info = self.bucket.batch(ops) print(info) assert ret[0]["code"] == 200
def batch_rename(self, keys_dict): """ Batch rename files :param keys_dict: File name and new file name key value pair -> { 'filename1': 'new_filename1', 'filename2': 'new_filenamw2', } :return: True or False """ for k in keys_dict.keys(): keys_dict[k] = self._legal_file_name(keys_dict[k]) ops = qiniu.build_batch_rename(self._bucket, keys_dict, force='true') ret, info = self._bucket_manager.batch(ops) return True if info.status_code == 200 else False
def rename_static_file_in_cdn(self): exclude_files = [ r'.DS_Store', ] cdn_file_path = configs.CDN_STATIC_ROOT file_list = {} for x in os.listdir(cdn_file_path): if x in exclude_files: continue file_list[x] = x.replace(Command.SLASH_SUBSTITUTE_BY, '/') q = Auth(self.access_key, self.secret_key) bucket = BucketManager(q) # force为true时强制同名覆盖, 字典的键为原文件,值为目标文件 ops = build_batch_rename(self.bucket_name, file_list, force='false') ret, info = bucket.batch(ops) print(ret) print(info)
# -*- coding: utf-8 -*- """ 批量重命名文件 https://developer.qiniu.com/kodo/api/1250/batch """ from qiniu import build_batch_rename, Auth, BucketManager access_key = '' secret_key = '' q = Auth(access_key, secret_key) bucket = BucketManager(q) bucket_name = '' # force为true时强制同名覆盖, 字典的键为原文件,值为目标文件 ops = build_batch_rename( bucket_name, { 'src_key1': 'target_key1', 'src_key2': 'target_key2'}, force='true') ret, info = bucket.batch(ops) print(info)
# -*- coding: utf-8 -*- # flake8: noqa from qiniu import Auth from qiniu import BucketManager from qiniu import build_batch_copy from qiniu import build_batch_move, build_batch_rename access_key = '...' secret_key = '...' # 初始化Auth状态 q = Auth(access_key, secret_key) # 初始化BucketManager bucket = BucketManager(q) keys = {'123.jpg': '123.jpg'} # ops = build_batch_copy( 'teest', keys, 'teest',force='true') # ops = build_batch_move('teest', keys, 'teest', force='true') ops = build_batch_rename('teest', keys, force='true') ret, info = bucket.batch(ops) print(ret) print(info) assert ret == {}
# -*- coding: utf-8 -*- # flake8: noqa from qiniu import Auth from qiniu import BucketManager,build_batch_rename # from qiniu import build_batch_copy, # from qiniu import build_batch_move,build_batch_rename access_key = '...' secret_key = '...' # 初始化Auth状态 q = Auth(access_key, secret_key) # 初始化BucketManager bucket = BucketManager(q) keys = {'123.jpg':'123.jpg'} # ops = build_batch_copy( 'teest', keys, 'teest',force='true') # ops = build_batch_move('teest', keys, 'teest', force='true') ops = build_batch_rename('teest', keys,force='true') ret, info = bucket.batch(ops) print(ret) print(info) assert ret == {}