def rpc_exec_auth(self, obj, method, *args): if self._open: try: sock = self._gw(self._url, self.db, self.uid, self._passwd, obj) return sock.exec_auth(method, *args) except socket.error, e: common.message(_('Unable to reach to OpenERP server !\nYou should check your connection to the network and the OpenERP server.'), _('Connection Error'), type=gtk.MESSAGE_ERROR) raise rpc_exception(69, 'Connection refused!') except Exception, e: if isinstance(e, (xmlrpclib.Fault, tiny_socket.Myexception)): a = rpc_exception(e.faultCode, e.faultString) if isinstance(e.faultCode, int): a.type = 'UserError' a.message = 'Error %s' % e.faultCode a.data = e.faultString if a.type in ('warning','UserError'): if a.message in ('ConcurrencyException') and len(args) > 4: if common.concurrency(args[0], args[2][0], args[4]): if CONCURRENCY_CHECK_FIELD in args[4]: del args[4][CONCURRENCY_CHECK_FIELD] return self.rpc_exec_auth(obj, method, *args) else: common.warning(a.data, a.message) else: common.error(_('Application Error'), e.faultCode, e.faultString) else: common.error(_('Application Error'), _('View details'), str(e)) #TODO Must propagate the exception? raise
def rpc_exec_auth(self, obj, method, *args): if self._open: try: sock = self._gw(self._url, self.db, self.uid, self._passwd, obj) return sock.exec_auth(method, *args) except socket.error, e: common.message(_('Unable to reach to OpenERP server !\nYou should check your connection to the network and the OpenERP server.'), _('Connection Error'), type=gtk.MESSAGE_ERROR) raise rpc_exception(69, 'Connection refused!') except Exception, e: if isinstance(e, xmlrpclib.Fault) \ or isinstance(e, tiny_socket.Myexception): a = rpc_exception(e.faultCode, e.faultString) if a.type in ('warning','UserError'): if a.message in ('ConcurrencyException') and len(args) > 4: if common.concurrency(args[0], args[2][0], args[4]): if CONCURRENCY_CHECK_FIELD in args[4]: del args[4][CONCURRENCY_CHECK_FIELD] return self.rpc_exec_auth(obj, method, *args) else: common.warning(a.data, a.message) else: common.error(_('Application Error'), e.faultCode, e.faultString) else: common.error(_('Application Error'), _('View details'), str(e)) #TODO Must propagate the exception? raise
else: return result def __execute(self, obj, method, args=(), auth=True): try: result = self.__rpc__(obj, method, args, auth=auth) return self.__convert(result) except socket.error, e: raise openobject.errors.TinyException(e.message or e.strerror, title=_('Application Error')) except RPCException, err: if err.type in ('warning', 'UserError'): if err.message in ('ConcurrencyException') and len(args) > 4: common.concurrency(err.message, err.data, args) else: common.warning(err.data) elif err.code.startswith('AccessDenied'): raise openobject.errors.AccessDenied(err.code, _('Access Denied')) else: common.error(_('Application Error'), err.backtrace) except Exception, e: common.error(_('Application Error'), str(e)) def execute(self, obj, method, *args): """Excecute the method of the obj with the given arguments. @param obj: the remote object
return newres else: return result def __execute(self, obj, method, args=(), auth=True): try: result = self.__rpc__(obj, method, args, auth=auth) return self.__convert(result) except socket.error, e: raise openobject.errors.TinyException(e.message or e.strerror, title=_('Application Error')) except RPCException, err: if err.type in ('warning', 'UserError'): if err.message in ('ConcurrencyException') and len(args) > 4: common.concurrency(err.message, err.data, args) else: common.warning(err.data) elif err.code.startswith('updater.py'): common.error('updater.py', err.code) elif err.code.startswith('ServerUpdate'): common.error('ServerUpdate', err.code) elif err.code.startswith('PatchFailed'): common.error('PatchFailed', err.code) elif err.code.startswith('AccessDenied'): raise openobject.errors.AccessDenied(err.code, _('Access Denied')) else: common.error(_('Application Error'), err.backtrace) except Exception, e: common.error(_('Application Error'), str(e))
class wizard_progress(object): def __init__(self, parent=None): self.res = None self.error = False self.parent = parent self.exception = None def run(self): def go(wiz_id, datas, state): ctx = context.copy() ctx.update(rpc.session.context) try: self.res = rpc.session.rpc_exec_auth_try( '/wizard', 'execute', wiz_id, datas, state, ctx) except Exception, e: self.error = True self.res = False self.exception = e return True if not self.res: self.error = True return True thread.start_new_thread(go, (wiz_id, datas, state)) i = 0 win = None pb = None while (not self.res) and (not self.error): time.sleep(0.1) i += 1 if i > 10: if not win or not pb: win, pb = common.OpenERP_Progressbar(self.parent) pb.pulse() gtk.main_iteration() if win: win.destroy() gtk.main_iteration() if self.exception: import xmlrpclib import socket from rpc import rpc_exception, CONCURRENCY_CHECK_FIELD import tiny_socket try: raise self.exception except socket.error, e: common.message(str(e), title=_('Connection refused !'), type=gtk.MESSAGE_ERROR, parent=self.parent) except xmlrpclib.Fault, err: a = rpc_exception(err.faultCode, err.faultString) if a.type in ('warning', 'UserError'): if a.message in ( 'ConcurrencyException') and len(args) > 4: if common.concurrency(args[0], args[2][0], args[4]): if CONCURRENCY_CHECK_FIELD in args[4]: del args[4][CONCURRENCY_CHECK_FIELD] return self.rpc_exec_auth( obj, method, *args) else: common.warning(a.data, a.message, parent=self.parent) else: common.error(_('Application Error'), err.faultCode, err.faultString)
class wizard_progress(object): def __init__(self, parent=None): self.res = None self.error = False self.parent = parent self.exception = None def run(self): def go(wiz_id, datas, state): ctx = context.copy() ctx.update(rpc.session.context) try: self.res = rpc.session.rpc_exec_auth_try( '/wizard', 'execute', wiz_id, datas, state, ctx) except Exception, e: self.error = True self.res = False self.exception = e return True if not self.res: self.error = True return True thread.start_new_thread(go, (wiz_id, datas, state)) i = 0 win = None pb = None while (not self.res) and (not self.error): time.sleep(0.1) i += 1 if i > 10: if not win or not pb: win = gtk.Window(type=gtk.WINDOW_TOPLEVEL) win.set_title(_('OpenERP Computing')) win.set_position(gtk.WIN_POS_CENTER_ON_PARENT) vbox = gtk.VBox(False, 0) hbox = gtk.HBox(False, 13) hbox.set_border_width(10) img = gtk.Image() img.set_from_stock('gtk-dialog-info', gtk.ICON_SIZE_DIALOG) hbox.pack_start(img, expand=True, fill=False) vbox2 = gtk.VBox(False, 0) label = gtk.Label() label.set_markup('<b>' + _('Operation in progress') + '</b>') label.set_alignment(0.0, 0.5) vbox2.pack_start(label, expand=True, fill=False) vbox2.pack_start(gtk.HSeparator(), expand=True, fill=True) vbox2.pack_start(gtk.Label( _("Please wait,\nthis operation may take a while..." )), expand=True, fill=False) hbox.pack_start(vbox2, expand=True, fill=True) vbox.pack_start(hbox) pb = gtk.ProgressBar() pb.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT) vbox.pack_start(pb, expand=True, fill=False) win.add(vbox) if not self.parent: self.parent = service.LocalService( 'gui.main').window win.set_transient_for(self.parent) win.show_all() pb.pulse() gtk.main_iteration() if win: win.destroy() gtk.main_iteration() if self.exception: import xmlrpclib import socket from rpc import rpc_exception, CONCURRENCY_CHECK_FIELD import tiny_socket try: raise self.exception except socket.error, e: common.message(str(e), title=_('Connection refused !'), type=gtk.MESSAGE_ERROR) except xmlrpclib.Fault, err: a = rpc_exception(err.faultCode, err.faultString) if a.type in ('warning', 'UserError'): if a.message in ( 'ConcurrencyException') and len(args) > 4: if common.concurrency(args[0], args[2][0], args[4]): if CONCURRENCY_CHECK_FIELD in args[4]: del args[4][CONCURRENCY_CHECK_FIELD] return self.rpc_exec_auth( obj, method, *args) else: common.warning(a.data, a.message) else: common.error(_('Application Error'), err.faultCode, err.faultString)