本文整理汇总了Python中qiita_db.metadata_template.prep_template.PrepTemplate.extend方法的典型用法代码示例。如果您正苦于以下问题:Python PrepTemplate.extend方法的具体用法?Python PrepTemplate.extend怎么用?Python PrepTemplate.extend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qiita_db.metadata_template.prep_template.PrepTemplate
的用法示例。
在下文中一共展示了PrepTemplate.extend方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_prep_template
# 需要导入模块: from qiita_db.metadata_template.prep_template import PrepTemplate [as 别名]
# 或者: from qiita_db.metadata_template.prep_template.PrepTemplate import extend [as 别名]
def update_prep_template(prep_id, fp):
"""Updates a prep template
Parameters
----------
prep_id : int
Prep template id to be updated
fp : str
The file path to the template file
Returns
-------
dict of {str: str}
A dict of the form {'status': str, 'message': str}
"""
import warnings
from os import remove
from qiita_db.metadata_template.util import load_template_to_dataframe
from qiita_db.metadata_template.prep_template import PrepTemplate
msg = ''
status = 'success'
prep = PrepTemplate(prep_id)
try:
with warnings.catch_warnings(record=True) as warns:
df = load_template_to_dataframe(fp)
prep.extend(df)
prep.update(df)
remove(fp)
if warns:
msg = '\n'.join(set(str(w.message) for w in warns))
status = 'warning'
except Exception as e:
status = 'danger'
msg = str(e)
return {'status': status, 'message': msg}
示例2: update_prep_template
# 需要导入模块: from qiita_db.metadata_template.prep_template import PrepTemplate [as 别名]
# 或者: from qiita_db.metadata_template.prep_template.PrepTemplate import extend [as 别名]
def update_prep_template(self, study, user, callback):
"""Update a prep template from the POST method
Parameters
----------
study : Study
The current study object
user : User
The current user object
callback : function
The callback function to call with the results once the processing
is done
Raises
------
HTTPError
If the prep template file does not exists
"""
# If we are on this function, the arguments "prep_template_id",
# "update_prep_template_file" must defined. If not, let tornado
# raise its error
pt_id = int(self.get_argument('prep_template_id'))
prep_template = self.get_argument('update_prep_template_file')
# Define here the message and message level in case of success
msg = "The prep template '%s' has been updated" % prep_template
msg_level = "success"
# Get the uploads folder
_, base_fp = get_mountpoint("uploads")[0]
# Get the path of the prep template in the uploads folder
fp = join(base_fp, str(study.id), prep_template)
if not exists(fp):
# The file does not exist, fail nicely
# Using 400 because we want the user to get the error in the GUI
raise HTTPError(400, "This file doesn't exist: %s" % fp)
try:
with warnings.catch_warnings(record=True) as warns:
pt = PrepTemplate(pt_id)
df = load_template_to_dataframe(fp)
pt.extend(df)
pt.update(df)
remove(fp)
# join all the warning messages into one. Note that this info
# will be ignored if an exception is raised
if warns:
msg = '\n'.join(set(str(w.message) for w in warns))
msg_level = 'warning'
except (TypeError, QiitaDBColumnError, QiitaDBExecutionError,
QiitaDBDuplicateError, IOError, ValueError, KeyError,
CParserError, QiitaDBDuplicateHeaderError, QiitaDBError) as e:
# Some error occurred while processing the sample template
# Show the error to the user so they can fix the template
msg = html_error_message % ('updating the prep template:',
basename(fp), str(e))
msg = convert_text_html(msg)
msg_level = "danger"
callback((msg, msg_level, 'prep_template_tab', pt_id, None))