本文整理汇总了Python中stoqlib.lib.webservice.WebService.download_plugin方法的典型用法代码示例。如果您正苦于以下问题:Python WebService.download_plugin方法的具体用法?Python WebService.download_plugin怎么用?Python WebService.download_plugin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stoqlib.lib.webservice.WebService
的用法示例。
在下文中一共展示了WebService.download_plugin方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download_plugin
# 需要导入模块: from stoqlib.lib.webservice import WebService [as 别名]
# 或者: from stoqlib.lib.webservice.WebService import download_plugin [as 别名]
def download_plugin(self, plugin_name):
"""Download a plugin from webservice
:param plugin_name: the name of the plugin to download
:returns: a deferred
"""
from stoqlib.lib.webservice import WebService
def callback(filename):
md5sum = unicode(md5sum_for_filename(filename))
with open(filename) as f:
with new_store() as store:
existing_egg = store.find(PluginEgg,
plugin_name=plugin_name).one()
if existing_egg is not None:
existing_egg.egg_content = f.read()
existing_egg.md5sum = md5sum
else:
PluginEgg(
store=store,
plugin_name=plugin_name,
egg_md5sum=md5sum,
egg_content=f.read(),
)
self._reload()
default_store = get_default_store()
existing_egg = default_store.find(PluginEgg,
plugin_name=plugin_name).one()
md5sum = existing_egg and existing_egg.egg_md5sum
webapi = WebService()
return webapi.download_plugin(plugin_name, callback=callback,
md5sum=md5sum)
示例2: download_plugin
# 需要导入模块: from stoqlib.lib.webservice import WebService [as 别名]
# 或者: from stoqlib.lib.webservice.WebService import download_plugin [as 别名]
def download_plugin(self, plugin_name):
"""Download a plugin from webservice
:param plugin_name: the name of the plugin to download
:returns: a deferred
"""
from stoqlib.lib.webservice import WebService
default_store = get_default_store()
existing_egg = default_store.find(PluginEgg,
plugin_name=plugin_name).one()
md5sum = existing_egg and existing_egg.egg_md5sum
webapi = WebService()
r = webapi.download_plugin(plugin_name, md5sum=md5sum)
try:
response = r.get_response()
except Exception as e:
return False, _("Failed to do the request: %s" % (e, ))
code = response.status_code
if code == 204:
msg = _("No update needed. The plugin is already up to date.")
log.info(msg)
return True, msg
if code != 200:
return_messages = {
400: _("Plugin not available for this stoq version"),
401: _("The instance is not authorized to download the plugin"),
404: _("Plugin does not exist"),
405: _("This instance has not acquired the specified plugin"),
}
msg = return_messages.get(code, str(code))
log.warning(msg)
return False, msg
content = response.content
md5sum = unicode(hashlib.md5(content).hexdigest())
with new_store() as store:
existing_egg = store.find(PluginEgg,
plugin_name=plugin_name).one()
if existing_egg is not None:
existing_egg.egg_content = content
existing_egg.egg_md5sum = md5sum
else:
PluginEgg(
store=store,
plugin_name=plugin_name,
egg_md5sum=md5sum,
egg_content=content,
)
self._reload()
return True, _("Plugin download successful")
示例3: download_plugin
# 需要导入模块: from stoqlib.lib.webservice import WebService [as 别名]
# 或者: from stoqlib.lib.webservice.WebService import download_plugin [as 别名]
def download_plugin(self, plugin_name):
"""Download a plugin from webservice
:param plugin_name: the name of the plugin to download
:returns: a deferred
"""
from stoqlib.lib.webservice import WebService
def callback(filename):
md5sum = unicode(md5sum_for_filename(filename))
with open(filename) as f:
with new_store() as store:
PluginEgg(
store=store,
plugin_name=plugin_name,
egg_md5sum=md5sum,
egg_content=f.read(),
)
self._reload()
webapi = WebService()
return webapi.download_plugin(plugin_name, callback=callback)
示例4: download_plugin
# 需要导入模块: from stoqlib.lib.webservice import WebService [as 别名]
# 或者: from stoqlib.lib.webservice.WebService import download_plugin [as 别名]
def download_plugin(self, plugin_name, channel=u'stable'):
"""Download a plugin from webservice
:param plugin_name: the name of the plugin to download
:param channel: the channel the plugin belongs
:returns: a deferred
"""
from stoqlib.lib.webservice import WebService
default_store = get_default_store()
existing_egg = default_store.find(PluginEgg,
plugin_name=plugin_name).one()
md5sum = existing_egg and existing_egg.egg_md5sum
webapi = WebService()
r = webapi.download_plugin(plugin_name, md5sum=md5sum, channel=channel)
try:
response = r.get_response()
except Exception as e:
return False, _("Failed to do the request: %s" % (e, ))
code = response.status_code
if code == 204:
msg = _("No update needed. The plugin is already up to date.")
log.info(msg)
return True, msg
if code != 200:
return_messages = {
400: _("Plugin not available for this stoq version"),
401: _("The instance is not authorized to download the plugin"),
404: _("Plugin does not exist"),
405: _("This instance has not acquired the specified plugin"),
}
msg = return_messages.get(code, str(code))
log.warning(msg)
return False, msg
try:
with io.BytesIO() as f:
f.write(response.content)
with ZipFile(f) as egg:
if egg.testzip() is not None:
raise BadZipfile
md5sum = hashlib.md5(f.getvalue()).hexdigest()
with new_store() as store:
existing_egg = store.find(PluginEgg,
plugin_name=plugin_name).one()
if existing_egg is not None:
existing_egg.egg_content = f.getvalue()
existing_egg.egg_md5sum = md5sum
else:
PluginEgg(
store=store,
plugin_name=plugin_name,
egg_md5sum=md5sum,
egg_content=f.getvalue(),
)
except BadZipfile:
return False, _("The downloaded plugin is corrupted")
self._reload()
return True, _("Plugin download successful")