本文整理汇总了Python中plugin.Plugin.create_from_zip方法的典型用法代码示例。如果您正苦于以下问题:Python Plugin.create_from_zip方法的具体用法?Python Plugin.create_from_zip怎么用?Python Plugin.create_from_zip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plugin.Plugin
的用法示例。
在下文中一共展示了Plugin.create_from_zip方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from plugin import Plugin [as 别名]
# 或者: from plugin.Plugin import create_from_zip [as 别名]
def post(self):
data = StringIO(request.data)
try:
plugin = Plugin.create_from_zip(data)
except ValidationError as e:
return {'result': 'error', 'message': "%s" % e}
return {'result': 'success', 'plugin': plugin.metadata}
示例2: plugin_upload
# 需要导入模块: from plugin import Plugin [as 别名]
# 或者: from plugin.Plugin import create_from_zip [as 别名]
def plugin_upload():
message = None
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
message = 'No file part'
else:
file = request.files['file']
# if user does not select file, browser also
# submit a empty part without filename
if file.filename == '':
message = 'No selected file'
elif file and '.' in file.filename and \
file.filename.rsplit('.', 1)[1] == 'zip':
file.filename = secure_filename(file.filename)
# Create plugin
try:
plugin = Plugin.create_from_zip(file, file.filename)
message = 'Plugin {} version {} created'.format(plugin.name, plugin.version)
except ValidationError as e:
render_error('<b>{}</b> is not valid {}'.format(key, e))
else:
message = 'File does not have a zip extension'
log("Plugin upload message: %s" % message)
return render_template('upload.html', message=message)
示例3: app_bootstrap
# 需要导入模块: from plugin import Plugin [as 别名]
# 或者: from plugin.Plugin import create_from_zip [as 别名]
def app_bootstrap():
"""Load all zipfile plugins from the zipfiles folder"""
zipfolder = os.path.join(os.path.dirname(__file__), 'zipfiles')
if os.path.isdir(zipfolder):
for path in [f for f in os.listdir(zipfolder)
if (os.path.isfile(os.path.join(zipfolder, f))
and f.endswith('.zip'))]:
try:
plugin = Plugin.create_from_zip(open(os.path.join(zipfolder, path)))
log("Plugin: %s has been succesfully loaded" % plugin.key)
except ValidationError as e:
log("Plugin file: %s could not be loaded: %s" % (path, e))