本文整理汇总了Python中qiita_db.artifact.Artifact.copy方法的典型用法代码示例。如果您正苦于以下问题:Python Artifact.copy方法的具体用法?Python Artifact.copy怎么用?Python Artifact.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qiita_db.artifact.Artifact
的用法示例。
在下文中一共展示了Artifact.copy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: copy_raw_data
# 需要导入模块: from qiita_db.artifact import Artifact [as 别名]
# 或者: from qiita_db.artifact.Artifact import copy [as 别名]
def copy_raw_data(prep_template, artifact_id):
"""Creates a new raw data by copying from artifact_id
Parameters
----------
prep_template : qiita_db.metadata_template.prep_template.PrepTemplate
The template to attach the artifact
artifact_id : int
The id of the artifact to duplicate
Returns
-------
dict of {str: str}
A dict of the form {'status': str, 'message': str}
"""
from qiita_db.artifact import Artifact
status = 'success'
msg = ''
try:
Artifact.copy(Artifact(artifact_id), prep_template)
except Exception as e:
# We should hit this exception rarely (that's why it is an
# exception) since at this point we have done multiple checks.
# However, it can occur in weird cases, so better let the GUI know
# that this failed
return {'status': 'danger',
'message': "Error creating artifact: %s" % str(e)}
return {'status': status, 'message': msg}
示例2: artifact_post_req
# 需要导入模块: from qiita_db.artifact import Artifact [as 别名]
# 或者: from qiita_db.artifact.Artifact import copy [as 别名]
def artifact_post_req(user_id, filepaths, artifact_type, name,
prep_template_id, artifact_id=None):
"""Creates the initial artifact for the prep template
Parameters
----------
user_id : str
User adding the atrifact
filepaths : dict of str
Comma-separated list of files to attach to the artifact,
keyed by file type
artifact_type : str
The type of the artifact
name : str
Name to give the artifact
prep_template_id : int or str castable to int
Prep template to attach the artifact to
artifact_id : int or str castable to int, optional
The id of the imported artifact
Returns
-------
dict of objects
A dictionary containing the new artifact ID
{'status': status,
'message': message,
'artifact': id}
"""
prep = PrepTemplate(int(prep_template_id))
study_id = prep.study_id
# First check if the user has access to the study
access_error = check_access(study_id, user_id)
if access_error:
return access_error
if artifact_id:
# if the artifact id has been provided, import the artifact
try:
artifact = Artifact.copy(Artifact(artifact_id), prep)
except Exception as e:
# We should hit this exception rarely (that's why it is an
# exception) since at this point we have done multiple checks.
# However, it can occur in weird cases, so better let the GUI know
# that this failed
return {'status': 'error',
'message': "Error creating artifact: %s" % str(e)}
else:
uploads_path = get_mountpoint('uploads')[0][1]
path_builder = partial(join, uploads_path, str(study_id))
cleaned_filepaths = []
for ftype, file_list in viewitems(filepaths):
# JavaScript sends us this list as a comma-separated list
for fp in file_list.split(','):
# JavaScript will send this value as an empty string if the
# list of files was empty. In such case, the split will
# generate a single element containing the empty string. Check
# for that case here and, if fp is not the empty string,
# proceed to check if the file exists
if fp:
# Check if filepath being passed exists for study
full_fp = path_builder(fp)
exists = check_fp(study_id, full_fp)
if exists['status'] != 'success':
return {'status': 'error',
'message': 'File does not exist: %s' % fp}
cleaned_filepaths.append((full_fp, ftype))
# This should never happen, but it doesn't hurt to actually have
# a explicit check, in case there is something odd with the JS
if not cleaned_filepaths:
return {'status': 'error',
'message': "Can't create artifact, no files provided."}
try:
artifact = Artifact.create(cleaned_filepaths, artifact_type,
name=name, prep_template=prep)
except Exception as e:
# We should hit this exception rarely (that's why it is an
# exception) since at this point we have done multiple checks.
# However, it can occur in weird cases, so better let the GUI know
# that this failed
return {'status': 'error',
'message': "Error creating artifact: %s" % str(e)}
return {'status': 'success',
'message': '',
'artifact': artifact.id}
示例3: copy_raw_data
# 需要导入模块: from qiita_db.artifact import Artifact [as 别名]
# 或者: from qiita_db.artifact.Artifact import copy [as 别名]
def copy_raw_data(prep_template, artifact_id):
"""Creates a new raw data by copying from artifact_id"""
Artifact.copy(Artifact(artifact_id), prep_template)