当前位置: 首页>>代码示例>>Python>>正文


Python WebService.download_plugin方法代码示例

本文整理汇总了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)
开发者ID:amaurihamasu,项目名称:stoq,代码行数:37,代码来源:pluginmanager.py

示例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")
开发者ID:,项目名称:,代码行数:57,代码来源:

示例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)
开发者ID:zoiobnu,项目名称:stoq,代码行数:24,代码来源:pluginmanager.py

示例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")
开发者ID:hackedbellini,项目名称:stoq,代码行数:66,代码来源:pluginmanager.py


注:本文中的stoqlib.lib.webservice.WebService.download_plugin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。