本文整理匯總了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")