def __bulk_add_new_file_dids(files, account, dataset_meta=None, session=None):
"""
Bulk add new dids.
:param dids: the list of new files.
:param account: The account owner.
:param session: The database session in use.
:returns: True is successful.
"""
for file in files:
new_did = models.DataIdentifier(scope=file['scope'], name=file['name'],
account=file.get('account') or account,
did_type=DIDType.FILE, bytes=file['bytes'],
md5=file.get('md5'), adler32=file.get('adler32'),
is_new=None)
for key in file.get('meta', []):
new_did.update({key: file['meta'][key]})
for key in dataset_meta or {}:
new_did.update({key: dataset_meta[key]})
new_did.save(session=session, flush=False)
try:
session.flush()
except IntegrityError, error:
raise exception.RucioException(error.args)
except DatabaseError, error:
raise exception.RucioException(error.args)
except FlushError, error:
if match('New instance .* with identity key .* conflicts with persistent instance', error.args[0]):
raise exception.DataIdentifierAlreadyExists('Data Identifier already exists!')
raise exception.RucioException(error.args)
return True
评论列表
文章目录