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


Python webservice.WebService类代码示例

本文整理汇总了Python中stoqlib.lib.webservice.WebService的典型用法代码示例。如果您正苦于以下问题:Python WebService类的具体用法?Python WebService怎么用?Python WebService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了WebService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: download_plugin

    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,代码行数:35,代码来源:pluginmanager.py

示例2: next_step

    def next_step(self):
        # We already sent the details, but may still be on the same step.
        if self.wizard.tef_request_done:
            return StoqAdminPasswordStep(self.wizard, self.previous)

        webapi = WebService()
        response = webapi.tef_request(self.model.name, self.model.email,
                                      self.model.phone)
        response.addCallback(self._on_response_done)
        response.addErrback(self._on_response_error)

        # FIXME: This is a hack, remove it when we can avoid
        #        calling dialog.run()
        if not reactor.running:
            reactor.run()

        self.send_progress.show()
        self.send_progress.set_text(_('Sending...'))
        self.send_progress.set_pulse_step(0.05)
        self.details_table.set_sensitive(False)
        self.wizard.next_button.set_sensitive(False)
        glib.timeout_add(50, self._pulse)

        # Cancel the request after 30 seconds without a reply
        glib.timeout_add(30000, self._cancel_request)

        # Stay on the same step while sending the details
        return self
开发者ID:leandrorchaves,项目名称:stoq,代码行数:28,代码来源:config.py

示例3: next_step

    def next_step(self):
        # We already sent the details, but may still be on the same step.
        # Also, if the user didn't choose to "register now", respect his
        # decision
        if not self.model.register_now or self.wizard.link_request_done:
            return FinishInstallationStep(self.wizard)

        webapi = WebService()
        response = webapi.link_registration(
            self.model.name, self.model.email, self.model.phone)
        response.addCallback(self._on_response_done)
        response.addErrback(self._on_response_error)

        # FIXME: This is a hack, remove it when we can avoid
        #        calling dialog.run()
        if not reactor.running:
            reactor.run()

        self.send_progress.show()
        self.send_progress.set_text(_('Sending...'))
        self.send_progress.set_pulse_step(0.05)
        self.wizard.next_button.set_sensitive(False)
        glib.timeout_add(50, self._pulse)

        # Cancel the request after 30 seconds without a reply
        glib.timeout_add(30000, self._cancel_request)

        # Stay on the same step while sending the details
        return self
开发者ID:adrianoaguiar,项目名称:stoq,代码行数:29,代码来源:config.py

示例4: download_plugin

    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:,项目名称:,代码行数:55,代码来源:

示例5: validate_confirm

    def validate_confirm(self):
        if not self._can_submit_feedback():
            return False

        webapi = WebService()
        d = webapi.feedback(self.application_screen,
                            self.model.email,
                            self.model.feedback)
        d.addCallback(self._on_feedback_reply)
        self.disable_ok()
        return False
开发者ID:Guillon88,项目名称:stoq,代码行数:11,代码来源:feedbackdialog.py

示例6: _check_information

    def _check_information(self):
        """Check some information with Stoq Web API

        - Check if there are new versions of Stoq Available
        - Check if this Stoq Instance uses Stoq Link (and send data to us if
          it does).
        """
        # Check version
        self._version_checker = VersionChecker(self.store, self)
        self._version_checker.check_new_version()
        if not api.sysparam.get_bool('ONLINE_SERVICES'):
            return
        # Check Stoq Link usage
        webapi = WebService()
        webapi.link_update(self.store)
开发者ID:fuinha,项目名称:stoq,代码行数:15,代码来源:shellwindow.py

示例7: download_plugin

    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,代码行数:22,代码来源:pluginmanager.py

示例8: next_step

    def next_step(self):
        # We already sent the details, but may still be on the same step.
        # Also, if the user didn't choose to "register now", respect his
        # decision
        if not self.model.register_now or self.wizard.link_request_done:
            return FinishInstallationStep(self.wizard)

        webapi = WebService()
        webapi.link_registration(
            self.model.name, self.model.email, self.model.phone,
            callback=lambda r: schedule_in_main_thread(self._on_response_done, r),
            errback=lambda e: schedule_in_main_thread(self._on_response_error, e))

        self.send_progress.show()
        self.send_progress.set_text(_('Sending...'))
        self.send_progress.set_pulse_step(0.05)
        self.wizard.next_button.set_sensitive(False)
        GLib.timeout_add(50, self._pulse)

        # Cancel the request after 30 seconds without a reply
        GLib.timeout_add(30000, self._cancel_request)

        # Stay on the same step while sending the details
        return self
开发者ID:hackedbellini,项目名称:stoq,代码行数:24,代码来源:config.py

示例9: ReportSubmitter

class ReportSubmitter(gobject.GObject):
    gsignal("failed", object)
    gsignal("submitted", object)

    def __init__(self):
        gobject.GObject.__init__(self)

        self._count = 0
        self._api = WebService()
        self.report = collect_report()

    def _done(self, args):
        self.emit("submitted", args)

    def _error(self, args):
        self.emit("failed", args)

    def submit(self):
        return self._api.bug_report(self.report, callback=self._on_report__callback, errback=self._on_report__errback)

    def _on_report__callback(self, response):
        if response.status_code == 200:
            self._on_success(response.json())
        else:
            self._on_error()

    def _on_report__errback(self, failure):
        self._on_error(failure)

    def _on_error(self, data=None):
        log.info("Failed to report bug: %r count=%d" % (data, self._count))
        if self._count < _N_TRIES:
            self.submit()
        else:
            schedule_in_main_thread(self.emit, "failed", data)
        self._count += 1

    def _on_success(self, data):
        log.info("Finished sending bugreport: %r" % (data,))
        schedule_in_main_thread(self.emit, "submitted", data)
开发者ID:stoq,项目名称:stoq,代码行数:40,代码来源:crashreport.py

示例10: ReportSubmitter

class ReportSubmitter(gobject.GObject):
    gsignal("failed", object)
    gsignal("submitted", object)

    def __init__(self):
        gobject.GObject.__init__(self)

        self._api = WebService()
        self._report = collect_report()
        self._count = 0

    def _done(self, args):
        self.emit("submitted", args)

    def _error(self, args):
        self.emit("failed", args)

    @property
    def report(self):
        return self._report

    def submit(self):
        response = self._api.bug_report(self._report)
        response.addCallback(self._on_report__callback)
        response.addErrback(self._on_report__errback)
        return response

    def _on_report__callback(self, data):
        log.info("Finished sending bugreport: %r" % (data,))
        self._done(data)

    def _on_report__errback(self, failure):
        log.info("Failed to report bug: %r count=%d" % (failure, self._count))
        if self._count < _N_TRIES:
            self.submit()
        else:
            self._error(failure)
        self._count += 1
开发者ID:pkaislan,项目名称:stoq,代码行数:38,代码来源:crashreport.py

示例11: _setup_stoq_link

 def _setup_stoq_link(self):
     from stoqlib.domain.events import SaleStatusChangedEvent
     from stoqlib.lib.webservice import WebService
     self._api = WebService()
     SaleStatusChangedEvent.connect(self._update_stoq_link)
开发者ID:amaurihamasu,项目名称:stoq,代码行数:5,代码来源:bootstrap.py

示例12: download_plugin

    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,代码行数:64,代码来源:pluginmanager.py

示例13: _BackupStatus

class _BackupStatus(ResourceStatus):

    name = "backup"
    label = _("Backup")
    priority = 98

    def __init__(self):
        ResourceStatus.__init__(self)
        self._webservice = WebService()
        self._server = ServerProxy()

    def refresh(self):
        if not api.sysparam.get_bool("ONLINE_SERVICES"):
            self.status = ResourceStatus.STATUS_NA
            self.reason = _("Backup service not running because " '"Online Services" is disabled')
            self.reason_long = _('Enable the parameter "Online Services" ' 'on the "Admin" app to solve this issue')
            return

        try:
            key = self._server.call("get_backup_key")
        except ServerError:
            pass
        else:
            if not key:
                self.status = self.STATUS_WARNING
                self.reason = _("Backup key not configured")
                self.reason_long = _('Click on "Configure" button to ' "configure the backup key")
                return

        request = self._webservice.status()
        try:
            response = request.get_response()
        except Exception as e:
            self.status = self.STATUS_WARNING
            self.reason = _("Could not communicate with Stoq.link")
            self.reason_long = str(e)
            return

        if response.status_code != 200:
            self.status = self.STATUS_WARNING
            self.reason = _("Could not communicate with Stoq.link")
            self.reason_long = None
            return

        data = response.json()
        if data["latest_backup_date"]:
            backup_date = dateutil.parser.parse(data["latest_backup_date"])
            delta = datetime.datetime.today() - backup_date

            if delta.days > 3:
                self.status = self.STATUS_WARNING
                self.reason = _("Backup is late. Last backup date is %s") % (backup_date.strftime("%x"))
                self.reason_long = _("Check your Stoq Server logs to see if " "there's any problem with it")
            else:
                self.status = self.STATUS_OK
                self.reason = _("Backup is up-to-date. Last backup date is %s") % (backup_date.strftime("%x"))
                self.reason_long = None
        else:
            self.status = self.STATUS_WARNING
            self.reason = _("There's no backup data yet")
            self.reason_long = None

    def get_actions(self):
        if self.status != ResourceStatus.STATUS_NA:
            yield ResourceStatusAction(self, "backup-now", _("Backup now"), self._on_backup_now, threaded=True)
            yield ResourceStatusAction(self, "configure", _("Configure"), self._on_configure, threaded=False)

    def _on_configure(self):
        key = self._server.call("get_backup_key")

        with api.new_store() as store:
            rv = run_dialog(BackupSettingsEditor, None, store, Settable(key=key))

        if rv:
            key = self._server.call("set_backup_key", rv.key)

    def _on_backup_now(self):
        self._server.call("backup_database")
开发者ID:stoq,项目名称:stoq,代码行数:78,代码来源:status.py

示例14: _download_details

 def _download_details(self):
     log.debug('Downloading new version information')
     webapi = WebService()
     response = webapi.version(self.store, stoq.version)
     response.addCallback(self._on_response_done)
开发者ID:,项目名称:,代码行数:5,代码来源:

示例15: __init__

 def __init__(self):
     ResourceStatus.__init__(self)
     self._webservice = WebService()
     self._server = ServerProxy()
开发者ID:stoq,项目名称:stoq,代码行数:4,代码来源:status.py


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