def format_s3_path(file, owner, dataset_name, path):
format_params = dict(file)
format_params.update({
'owner': owner,
'dataset': dataset_name,
'path': path,
'basename': os.path.basename(path),
'dirname': os.path.dirname(path),
'extension': os.path.splitext(path)[1],
})
if 'md5' in format_params:
try:
md5 = base64.b64decode(format_params['md5'])
format_params['md5_hex'] = codecs.encode(md5, 'hex').decode('ascii')
except Exception:
pass
try:
s3path = config['STORAGE_PATH_PATTERN'].format(**format_params)
except KeyError as e:
msg = ('STORAGE_PATH_PATTERN contains variable not found in file info: %s' % e)
raise ValueError(msg)
return s3path
评论列表
文章目录