Exemplo n.º 1
0
    def execute(self, obj, method, *args):
        """
        Same as call() but uses the notify mechanism to notify exceptions.

        Note that you'll need to bind gettext as texts sent to the notify
        module are localized.

        :param obj:
        :param method:
        :param args:
        :return:
        """
        count = 1
        while True:
            try:
                return self.call(obj, method, *args)
            except RpcProtocolException as err:
                if not Notifier.notifyLostConnection(count):
                    raise
            except RpcServerException as err:
                if err.type in ('warning', 'UserError'):
                    if err.info in ('ConcurrencyException') and len(args) > 4:
                        if Notifier.notifyConcurrencyError(args[0], args[2] and args[2][0], args[4]):
                            if ConcurrencyCheckField in args[4]:
                                del args[4][ConcurrencyCheckField]
                            return self.execute(obj, method, *args)
                    else:
                        Notifier.notifyWarning(err.info, err.data)
                else:
                    Notifier.notifyError(_('Application Error'), _(
                        'View details'), err.backtrace)
                raise
            count += 1
Exemplo n.º 2
0
    def __init__(self, url):
        Connection.__init__(self, url)
        self.url += '/rpc'

        from Koo.Common.Settings import Settings
        Pyro.config.PYRO_TRACELEVEL = int(Settings.value('pyro.tracelevel'))
        Pyro.config.PYRO_LOGFILE = Settings.value('pyro.logfile')
        Pyro.config.PYRO_DNS_URI = int(Settings.value('pyro.dns_uri'))

        if self.url.startswith('PYROLOCSSL'):
            Pyro.config.PYROSSL_CERTDIR = Settings.value('pyrossl.certdir')
            Pyro.config.PYROSSL_CERT = Settings.value('pyrossl.cert')
            Pyro.config.PYROSSL_KEY = Settings.value('pyrossl.key')
            Pyro.config.PYROSSL_CA_CERT = Settings.value('pyrossl.ca_cert')
            Pyro.config.PYROSSL_POSTCONNCHECK = int(
                Settings.value('pyrossl.postconncheck'))

        try:
            self.proxy = Pyro.core.getProxyForURI(self.url)
        except SSLError as e:
            title = _('SSL Error')
            if e.message == 'No such file or directory':
                msg = _('Please check your SSL certificate: ')
                msg += e.message
                msg += '\n%s' % os.path.join(Pyro.config.PYROSSL_CERTDIR,
                                             Pyro.config.PYROSSL_CERT)
                details = traceback.format_exc()
                Notifier.notifyError(title, msg, details)
            else:
                raise

        except Exception as e:
            raise
Exemplo n.º 3
0
 def execute(self, obj, method, *args):
     count = 1
     while True:
         try:
             return self.call(obj, method, *args)
         except RpcProtocolException, err:
             if not Notifier.notifyLostConnection(count):
                 raise
         except RpcServerException, err:
             if err.type in ('warning', 'UserError'):
                 if err.args[0] in (
                         'ConcurrencyException') and len(args) > 4:
                     if Notifier.notifyConcurrencyError(
                             args[0], args[2] and args[2][0], args[4]):
                         if ConcurrencyCheckField in args[4]:
                             del args[4][ConcurrencyCheckField]
                         return self.execute(obj, method, *args)
                 else:
                     Notifier.notifyWarning(err.args[0], err.args[1])
             else:
                 Notifier.notifyError(
                     _('Application Error: %s') % err.get_title(),
                     _('View details: %s') % err.get_details(),
                     err.backtrace)
             raise
Exemplo n.º 4
0
def exceptionHook(type, value, backtrace):
    from PyQt4.QtGui import QApplication
    cursor = QApplication.overrideCursor()
    if cursor:
        QApplication.restoreOverrideCursor()
    from Settings import Settings
    import traceback
    backtrace = ''.join(traceback.format_tb(backtrace))
    if Settings.value('client.debug'):
        from Koo.Common import Notifier
        Notifier.notifyError(type, value, backtrace)
    else:
        error('Error: %s\n%s\n%s' % (type, value, backtrace))
Exemplo n.º 5
0
    def hasFinished(self):
        if self.exception:
            if self.useNotifications:
                # Note that if there's an error or warning
                # callback is called anyway with value None
                if self.error:
                    Notifier.notifyError(*self.error)
                elif self.warning:
                    Notifier.notifyWarning(*self.warning)
                else:
                    raise self.exception
            self.exception.emit(self.exception)
        else:
            self.called.emit(self.result)

        if self.callback:
            self.callback(self.result, self.exception)

        # Free session and thus server  as soon as possible
        self.session = None
Exemplo n.º 6
0
def exceptionHook(type, value, backtrace):
    from PyQt5.QtWidgets import QApplication
    from Koo.Common.Version import Version
    cursor = QApplication.overrideCursor()
    if cursor:
        QApplication.restoreOverrideCursor()
    from .Settings import Settings
    import traceback

    sentry_dsn = Settings.get("client.sentry_dsn")
    if sentry_dsn:
        client = Client(sentry_dsn)

        extra = Settings.options
        extra.update({"version": Version})
        client.captureException(exc_info=(type, value, backtrace), extra=extra)

    backtrace = ''.join(traceback.format_tb(backtrace))
    if Settings.value('client.debug'):
        from Koo.Common import Notifier
        Notifier.notifyError(type, value, backtrace)
    else:
        error('Error: %s\n%s\n%s' % (type, value, backtrace))
Exemplo n.º 7
0
    def executeButton(self, screen, id):
        type = self.attrs.get('type', 'workflow')
        if type == 'workflow':
            QApplication.setOverrideCursor(Qt.WaitCursor)
            try:
                # TODO: Uncomment when our patch will be applied in the server
                #result = Rpc.session.execute('/object', 'exec_workflow', screen.name, self.name, id, self.record.context())
                result = Rpc.session.execute('/object', 'exec_workflow',
                                             screen.name, self.name, id)
                if isinstance(result, dict):
                    if result['type'] == 'ir.actions.act_window_close':
                        screen.close()
                    else:
                        if result['type'] == 'ir.actions.act_window':
                            QApplication.setOverrideCursor(Qt.ArrowCursor)
                        Api.instance.executeAction(result, {'ids': [id]})
                        if result['type'] == 'ir.actions.act_window':
                            QApplication.restoreOverrideCursor()

                elif isinstance(result, list):
                    for r in result:
                        if result['type'] == 'ir.actions.act_window':
                            QApplication.setOverrideCursor(Qt.ArrowCursor)
                        Api.instance.executeAction(r, {'ids': [id]})
                        if result['type'] == 'ir.actions.act_window':
                            QApplication.restoreOverrideCursor()
            except Rpc.RpcException as e:
                pass
            QApplication.restoreOverrideCursor()
        elif type == 'object':
            if not id:
                return
            QApplication.setOverrideCursor(Qt.WaitCursor)
            try:
                result = Rpc.session.execute('/object', 'execute', screen.name,
                                             self.name, [id],
                                             self.record.context())
            except Rpc.RpcException as e:
                QApplication.restoreOverrideCursor()
                return
            QApplication.restoreOverrideCursor()
            if isinstance(result, dict):
                screen.close()
                datas = {
                    'ids': [id],
                    'model': screen.name,
                }
                Api.instance.executeAction(result, datas, screen.context)

        elif type == 'action':
            action_id = int(self.attrs['name'])
            Api.instance.execute(action_id, {
                'model': screen.name,
                'id': id,
                'ids': [id]
            },
                                 context=screen.context)
        else:
            Notifier.notifyError(_('Error in Button'),
                                 _('Button type not allowed'),
                                 _('Button type not allowed'))

        QApplication.setOverrideCursor(Qt.WaitCursor)
        try:
            screen.reload()
        except Rpc.RpcException as e:
            pass
        QApplication.restoreOverrideCursor()
Exemplo n.º 8
0
                }
                if 'datas' in result:
                    datas.update(result['datas'])
                Api.instance.executeAction(result, datas, screen.context)

        elif type == 'action':
            action_id = int(self.attrs['name'])
            Api.instance.execute(action_id, {
                'model': screen.name,
                'id': id,
                'ids': [id]
            },
                                 context=screen.context)
        else:
            Notifier.notifyError(_('Error in Button'),
                                 _('Button type not allowed'),
                                 _('Button type not allowed'))

        QApplication.setOverrideCursor(Qt.WaitCursor)
        try:
            screen.reload()
        except Rpc.RpcException, e:
            pass
        QApplication.restoreOverrideCursor()

    def click(self):
        if not self.record:
            return

        # TODO: Remove screen dependency and thus ViewForm.screen
        screen = self.view.screen