Remove catch all exceptions
review35008
This commit is contained in:
1 parent
4ef9bbb739
commit
45c7a28212
51 files changed
+486
-493
No files matched your search
+1
-1
@@ -5,7 +5,7 @@ try:
|
||||
'..', '..', 'tryton')))
|
||||
if os.path.isdir(DIR):
|
||||
sys.path.insert(0, os.path.dirname(DIR))
|
||||
except Exception:
|
||||
except NameError:
|
||||
pass
|
||||
|
||||
# True only if running as a py2exe app
|
||||
|
||||
@@ -8,6 +8,7 @@ from tryton.wizard import Wizard
|
||||
from tryton.common import message, error, selection, file_open, mailto
|
||||
from tryton.gui.window import Window
|
||||
from tryton.pyson import PYSONDecoder
|
||||
from tryton.exceptions import TrytonServerError
|
||||
import gettext
|
||||
import tempfile
|
||||
import base64
|
||||
@@ -35,7 +36,7 @@ class Action(object):
|
||||
args = ('model', data['model'], 'search', [], 0, None, None, ctx)
|
||||
try:
|
||||
ids = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
ids = common.process_exception(exception, window, *args)
|
||||
if not ids:
|
||||
return False
|
||||
@@ -47,7 +48,7 @@ class Action(object):
|
||||
rpcprogress = common.RPCProgress('execute', args, window)
|
||||
try:
|
||||
res = rpcprogress.run()
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, window)
|
||||
return False
|
||||
if not res:
|
||||
@@ -80,7 +81,7 @@ class Action(object):
|
||||
try:
|
||||
res = rpc.execute('model', 'ir.action', 'read', act_id,
|
||||
['type'], ctx)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, window)
|
||||
return
|
||||
if not res:
|
||||
@@ -89,7 +90,7 @@ class Action(object):
|
||||
try:
|
||||
res = rpc.execute('model', action_type, 'search_read',
|
||||
[('action', '=', act_id)], 0, 1, None, None, ctx)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, window)
|
||||
return
|
||||
Action._exec_action(res, window, data)
|
||||
@@ -187,7 +188,7 @@ class Action(object):
|
||||
actions = rpc.execute('model', 'ir.action.keyword',
|
||||
'get_keyword', keyword, (data['model'], model_id),
|
||||
rpc.CONTEXT)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, window)
|
||||
return False
|
||||
|
||||
|
||||
@@ -29,24 +29,25 @@ class CellRendererFloat(CellRendererInteger):
|
||||
value = entry.get_text()
|
||||
position = entry.get_position()
|
||||
new_value = value[:position] + new_text + value[position:]
|
||||
decimal_point = locale.localeconv()['decimal_point']
|
||||
|
||||
if new_value in ('-', decimal_point):
|
||||
return
|
||||
|
||||
try:
|
||||
decimal_point = locale.localeconv()['decimal_point']
|
||||
|
||||
if new_value in ('-', decimal_point):
|
||||
return
|
||||
|
||||
locale.atof(new_value)
|
||||
except ValueError:
|
||||
entry.stop_emission('insert-text')
|
||||
return
|
||||
|
||||
new_int = new_value
|
||||
new_decimal = ''
|
||||
if decimal_point in new_value:
|
||||
new_int, new_decimal = new_value.rsplit(decimal_point, 1)
|
||||
new_int = new_value
|
||||
new_decimal = ''
|
||||
if decimal_point in new_value:
|
||||
new_int, new_decimal = new_value.rsplit(decimal_point, 1)
|
||||
|
||||
if len(new_int) > self.digits[0] \
|
||||
or len(new_decimal) > self.digits[1]:
|
||||
entry.stop_emission('insert-text')
|
||||
|
||||
except Exception:
|
||||
if len(new_int) > self.digits[0] \
|
||||
or len(new_decimal) > self.digits[1]:
|
||||
entry.stop_emission('insert-text')
|
||||
|
||||
|
||||
gobject.type_register(CellRendererFloat)
|
||||
@@ -20,11 +20,11 @@ class CellRendererInteger(CellRendererText):
|
||||
value = entry.get_text()
|
||||
position = entry.get_position()
|
||||
new_value = value[:position] + new_text + value[position:]
|
||||
if new_value == '-':
|
||||
return
|
||||
try:
|
||||
if new_value == '-':
|
||||
return
|
||||
locale.atoi(new_value)
|
||||
except Exception:
|
||||
except ValueError:
|
||||
entry.stop_emission('insert-text')
|
||||
|
||||
gobject.type_register(CellRendererInteger)
|
||||
+133
-111
@@ -4,6 +4,7 @@ from __future__ import with_statement
|
||||
|
||||
import gtk
|
||||
import gobject
|
||||
import glib
|
||||
import pango
|
||||
import gettext
|
||||
import os
|
||||
@@ -37,6 +38,12 @@ except ImportError:
|
||||
ssl = None
|
||||
import dis
|
||||
from threading import Lock, Semaphore
|
||||
try:
|
||||
import pytz
|
||||
except ImportError:
|
||||
pytz = None
|
||||
|
||||
from tryton.exceptions import TrytonServerError, TrytonError
|
||||
|
||||
_ = gettext.gettext
|
||||
|
||||
@@ -59,7 +66,7 @@ class TrytonIconFactory(gtk.IconFactory):
|
||||
try:
|
||||
pixbuf = gtk.gdk.pixbuf_new_from_file(
|
||||
os.path.join(PIXMAPS_DIR, fname).decode('utf-8'))
|
||||
except Exception:
|
||||
except IOError:
|
||||
continue
|
||||
icon_set = gtk.IconSet(pixbuf)
|
||||
self.add(name, icon_set)
|
||||
@@ -74,7 +81,7 @@ class TrytonIconFactory(gtk.IconFactory):
|
||||
try:
|
||||
icons = rpc.execute('model', 'ir.ui.icon', 'list_icons',
|
||||
rpc.CONTEXT)
|
||||
except Exception:
|
||||
except TrytonServerError:
|
||||
icons = []
|
||||
for icon_id, icon_name in icons:
|
||||
if refresh and icon_name in self._loaded_icons:
|
||||
@@ -96,7 +103,7 @@ class TrytonIconFactory(gtk.IconFactory):
|
||||
try:
|
||||
icons = rpc.execute('model', 'ir.ui.icon', 'read', ids,
|
||||
['name', 'icon'], rpc.CONTEXT)
|
||||
except Exception:
|
||||
except TrytonServerError:
|
||||
icons = []
|
||||
for icon in icons:
|
||||
# svg file cannot be loaded from data into a pixbuf
|
||||
@@ -314,7 +321,7 @@ def file_selection(title, filename='', parent=None,
|
||||
sys.getfilesystemencoding().encode('utf-8')), 128, 128)
|
||||
img.set_from_pixbuf(pixbuf)
|
||||
have_preview = True
|
||||
except Exception:
|
||||
except (IOError, glib.GError):
|
||||
have_preview = False
|
||||
win.set_preview_widget_active(have_preview)
|
||||
return
|
||||
@@ -337,7 +344,7 @@ def file_selection(title, filename='', parent=None,
|
||||
CONFIG['client.default_path'] = \
|
||||
os.path.dirname(filepath)
|
||||
CONFIG.save()
|
||||
except Exception:
|
||||
except IOError:
|
||||
pass
|
||||
parent.present()
|
||||
win.destroy()
|
||||
@@ -349,7 +356,7 @@ def file_selection(title, filename='', parent=None,
|
||||
try:
|
||||
CONFIG['client.default_path'] = \
|
||||
os.path.dirname(filenames[0])
|
||||
except Exception:
|
||||
except IOError:
|
||||
pass
|
||||
parent.present()
|
||||
win.destroy()
|
||||
@@ -361,20 +368,19 @@ def file_open(filename, type, parent, print_p=False):
|
||||
if print_p:
|
||||
operation = 'print'
|
||||
try:
|
||||
os.startfile(os.path.normpath(filename), operation)
|
||||
except Exception:
|
||||
# Try without operation, it is not supported on version < 2.5
|
||||
try:
|
||||
if sys.version_info[:2] >= (2, 5):
|
||||
os.startfile(os.path.normpath(filename), operation)
|
||||
else:
|
||||
os.startfile(os.path.normpath(filename))
|
||||
except Exception:
|
||||
save_name = file_selection(_('Save As...'), parent=parent,
|
||||
action=gtk.FILE_CHOOSER_ACTION_SAVE)
|
||||
if save_name:
|
||||
file_p = open(filename, 'rb')
|
||||
save_p = open(save_name, 'wb+')
|
||||
save_p.write(file_p.read())
|
||||
save_p.close()
|
||||
file_p.close()
|
||||
except WindowsError:
|
||||
save_name = file_selection(_('Save As...'), parent=parent,
|
||||
action=gtk.FILE_CHOOSER_ACTION_SAVE)
|
||||
if save_name:
|
||||
file_p = open(filename, 'rb')
|
||||
save_p = open(save_name, 'wb+')
|
||||
save_p.write(file_p.read())
|
||||
save_p.close()
|
||||
file_p.close()
|
||||
return
|
||||
elif os.name == 'mac' or \
|
||||
(hasattr(os, 'uname') and os.uname()[0] == 'Darwin'):
|
||||
@@ -384,7 +390,7 @@ def file_open(filename, type, parent, print_p=False):
|
||||
if not pid:
|
||||
try:
|
||||
os.execv('/usr/bin/open', ['/usr/bin/open', filename])
|
||||
except Exception:
|
||||
except OSError:
|
||||
sys.exit(0)
|
||||
time.sleep(0.1)
|
||||
sys.exit(0)
|
||||
@@ -424,7 +430,7 @@ def file_open(filename, type, parent, print_p=False):
|
||||
if not pid:
|
||||
try:
|
||||
os.execv(prog, args)
|
||||
except Exception:
|
||||
except OSError:
|
||||
sys.exit(0)
|
||||
time.sleep(0.1)
|
||||
sys.exit(0)
|
||||
@@ -451,7 +457,7 @@ def mailto(to=None, cc=None, subject=None, body=None, attachment=None):
|
||||
if not pid:
|
||||
try:
|
||||
os.execv(prog, args)
|
||||
except Exception:
|
||||
except OSError:
|
||||
sys.exit(0)
|
||||
time.sleep(0.1)
|
||||
sys.exit(0)
|
||||
@@ -909,11 +915,12 @@ def send_bugtracker(msg, parent):
|
||||
message(_('Created new bug with ID ') + \
|
||||
'issue%s' % issue_id, parent)
|
||||
webbrowser.open(CONFIG['roundup.url'] + 'issue%s' % issue_id, new=2)
|
||||
except Exception, exception:
|
||||
if hasattr(exception, 'faultString') \
|
||||
and 'roundup.cgi.exceptions.Unauthorised' in exception.faultString:
|
||||
message(_('Connection error!\n' \
|
||||
'Bad username or password!'), parent)
|
||||
except (socket.error, xmlrpclib.Fault), exception:
|
||||
if (isinstance(exception, xmlrpclib.Fault)
|
||||
and 'roundup.cgi.exceptions.Unauthorised' in
|
||||
exception.faultString):
|
||||
message(_('Connection error!\nBad username or password!'),
|
||||
parent)
|
||||
return send_bugtracker(msg, parent)
|
||||
tb_s = reduce(lambda x, y: x + y,
|
||||
traceback.format_exception(sys.exc_type,
|
||||
@@ -928,99 +935,105 @@ PLOCK = Lock()
|
||||
|
||||
def process_exception(exception, parent, *args):
|
||||
global _USERNAME, _DATABASE, _SOCK
|
||||
if str(exception.args[0]) == 'BadFingerprint':
|
||||
warning(_('The server fingerprint has changed since last connection!\n'
|
||||
'The application will stop connecting to this server '
|
||||
'until its fingerprint is fixed.'), parent, _('Security risk!'))
|
||||
from tryton.gui.main import Main
|
||||
Main.sig_quit()
|
||||
sys.exit()
|
||||
if str(exception.args[0]) == 'NotLogged':
|
||||
if not rpc._SOCK:
|
||||
message(_('Connection error!\n' \
|
||||
'Unable to connect to the server!'), parent)
|
||||
return False
|
||||
if not PLOCK.acquire(False):
|
||||
return False
|
||||
hostname = rpc._SOCK.hostname
|
||||
port = rpc._SOCK.port
|
||||
try:
|
||||
while True:
|
||||
password = ask(_('Password:'), parent, visibility=False)
|
||||
if password is None:
|
||||
raise Exception('NotLogged')
|
||||
res = rpc.login(rpc._USERNAME, password, hostname, port,
|
||||
rpc._DATABASE)
|
||||
from tryton.gui.main import Main
|
||||
Main.get_main().refresh_ssl()
|
||||
if res == -1:
|
||||
message(_('Connection error!\n' \
|
||||
'Unable to connect to the server!'), parent)
|
||||
return False
|
||||
if res < 0:
|
||||
continue
|
||||
|
||||
if isinstance(exception, TrytonError):
|
||||
if exception.ex_type == 'BadFingerprint':
|
||||
warning(_('The server fingerprint has changed since last'
|
||||
' connection!\nThe application will stop connecting to this'
|
||||
' server until its fingerprint is fixed.'),
|
||||
parent, _('Security risk!'))
|
||||
from tryton.gui.main import Main
|
||||
Main.sig_quit()
|
||||
sys.exit()
|
||||
elif exception.ex_type == 'NotLogged':
|
||||
if not rpc._SOCK:
|
||||
message(_('Connection error!\n' \
|
||||
'Unable to connect to the server!'), parent)
|
||||
return False
|
||||
elif isinstance(exception, TrytonServerError):
|
||||
if exception.ex_type == 'UserWarning':
|
||||
msg = ''
|
||||
if len(exception.args) > 4:
|
||||
msg = exception.args[3]
|
||||
res = userwarning(str(msg), parent, str(exception.args[2]))
|
||||
if res in ('always', 'ok'):
|
||||
args2 = ('model', 'res.user.warning', 'create', {
|
||||
'user': rpc._USER,
|
||||
'name': exception.args[1],
|
||||
'always': (res == 'always'),
|
||||
}, rpc.CONTEXT)
|
||||
try:
|
||||
rpc.execute(*args2)
|
||||
except TrytonServerError, exception:
|
||||
process_exception(exception, parent, *args2)
|
||||
if args:
|
||||
try:
|
||||
return rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
return process_exception(exception, parent, *args)
|
||||
return True
|
||||
finally:
|
||||
PLOCK.release()
|
||||
|
||||
if exception.args[0] == 'ConcurrencyException':
|
||||
if len(args) >= 6:
|
||||
if concurrency(args[1], args[3][0], args[5], parent):
|
||||
if '_timestamp' in args[5]:
|
||||
del args[5]['_timestamp']
|
||||
try:
|
||||
return rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
return process_exception(exception, parent, *args)
|
||||
return False
|
||||
else:
|
||||
message(_('Concurrency Exception'), parent,
|
||||
msg_type=gtk.MESSAGE_ERROR)
|
||||
elif exception.ex_type == 'UserError':
|
||||
msg = ''
|
||||
if len(exception.args) > 3:
|
||||
msg = exception.args[2]
|
||||
warning(str(msg), parent, str(exception.args[1]))
|
||||
return False
|
||||
|
||||
if exception.args[0] == 'UserWarning':
|
||||
msg = ''
|
||||
if len(exception.args) > 4:
|
||||
msg = exception.args[3]
|
||||
res = userwarning(str(msg), parent, str(exception.args[2]))
|
||||
if res in ('always', 'ok'):
|
||||
args2 = ('model', 'res.user.warning', 'create', {
|
||||
'user': rpc._USER,
|
||||
'name': exception.args[1],
|
||||
'always': (res == 'always'),
|
||||
}, rpc.CONTEXT)
|
||||
elif exception.ex_type == 'ConcurrencyException':
|
||||
if len(args) >= 6:
|
||||
if concurrency(args[1], args[3][0], args[5], parent):
|
||||
if '_timestamp' in args[5]:
|
||||
del args[5]['_timestamp']
|
||||
try:
|
||||
return rpc.execute(*args)
|
||||
except TrytonServerError, exception:
|
||||
return process_exception(exception, parent, *args)
|
||||
return False
|
||||
else:
|
||||
message(_('Concurrency Exception'), parent,
|
||||
msg_type=gtk.MESSAGE_ERROR)
|
||||
return False
|
||||
elif exception.ex_type == 'NotLogged':
|
||||
if not PLOCK.acquire(False):
|
||||
return False
|
||||
hostname = rpc._SOCK.hostname
|
||||
port = rpc._SOCK.port
|
||||
try:
|
||||
rpc.execute(*args2)
|
||||
except Exception, exception:
|
||||
process_exception(exception, parent, *args2)
|
||||
if args:
|
||||
try:
|
||||
return rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
return process_exception(exception, parent, *args)
|
||||
return True
|
||||
return False
|
||||
|
||||
if exception.args[0] == 'UserError':
|
||||
msg = ''
|
||||
if len(exception.args) > 3:
|
||||
msg = exception.args[2]
|
||||
warning(str(msg), parent, str(exception.args[1]))
|
||||
return False
|
||||
|
||||
if isinstance(exception, socket.error):
|
||||
while True:
|
||||
password = ask(_('Password:'), parent, visibility=False)
|
||||
if password is None:
|
||||
continue
|
||||
res = rpc.login(rpc._USERNAME, password, hostname, port,
|
||||
rpc._DATABASE)
|
||||
from tryton.gui.main import Main
|
||||
Main.get_main().refresh_ssl()
|
||||
if res == -1:
|
||||
message(_('Connection error!\n' \
|
||||
'Unable to connect to the server!'), parent)
|
||||
return False
|
||||
if res < 0:
|
||||
continue
|
||||
if args:
|
||||
try:
|
||||
return rpc.execute(*args)
|
||||
except TrytonServerError, exception:
|
||||
return process_exception(exception, parent, *args)
|
||||
return True
|
||||
finally:
|
||||
PLOCK.release()
|
||||
elif isinstance(exception, socket.error):
|
||||
msg = ''
|
||||
if len(exception.args) > 2:
|
||||
msg = exception.args[1]
|
||||
warning(msg, parent, _('Network Error!'))
|
||||
return False
|
||||
|
||||
error(str(exception.args[0]), parent, str(exception.args[-1]))
|
||||
if isinstance(exception, TrytonServerError):
|
||||
error_title, error_detail = exception.ex_type, exception.traceback
|
||||
else:
|
||||
error_title = str(exception)
|
||||
error_detail = traceback.format_exc()
|
||||
error(error_title, parent, error_detail)
|
||||
return False
|
||||
|
||||
def node_attributes(node):
|
||||
@@ -1087,7 +1100,7 @@ class DBProgress(object):
|
||||
try:
|
||||
dbs = refresh_dblist(self.host, self.port)
|
||||
createdb = True
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
if exception[0] == 'AccessDenied':
|
||||
dbs, createdb = [], False
|
||||
else:
|
||||
@@ -1146,7 +1159,7 @@ class RPCProgress(object):
|
||||
def start(self):
|
||||
try:
|
||||
self.res = getattr(rpc, self.method)(*self.args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
self.error = True
|
||||
self.res = False
|
||||
self.exception = exception
|
||||
@@ -1275,7 +1288,7 @@ def text_to_float_time(text, conv=None):
|
||||
try:
|
||||
try:
|
||||
return locale.atof(text)
|
||||
except Exception:
|
||||
except ValueError:
|
||||
pass
|
||||
if conv:
|
||||
tmp_conv = FLOAT_TIME_CONV.copy()
|
||||
@@ -1301,7 +1314,7 @@ def text_to_float_time(text, conv=None):
|
||||
try:
|
||||
value += abs(locale.atof(buf))
|
||||
continue
|
||||
except Exception:
|
||||
except ValueError:
|
||||
pass
|
||||
for sep in conv.keys():
|
||||
if buf.endswith(sep):
|
||||
@@ -1310,7 +1323,7 @@ def text_to_float_time(text, conv=None):
|
||||
if text.startswith('-'):
|
||||
value *= -1
|
||||
return value
|
||||
except Exception:
|
||||
except ValueError:
|
||||
return 0.0
|
||||
|
||||
def float_time_to_text(val, conv=None):
|
||||
@@ -1418,3 +1431,12 @@ def safe_eval(source, data=None):
|
||||
'bool': bool,
|
||||
'dict': dict,
|
||||
}}, data)
|
||||
|
||||
def timezoned_date(date):
|
||||
if pytz and rpc.CONTEXT.get('timezone'):
|
||||
lzone = pytz.timezone(rpc.CONTEXT['timezone'])
|
||||
szone = pytz.timezone(rpc.TIMEZONE)
|
||||
sdt = szone.localize(date, is_dst=True)
|
||||
ldt = sdt.astimezone(lzone)
|
||||
date = ldt
|
||||
return date
|
||||
@@ -194,7 +194,7 @@ class DateEntry(gtk.Entry):
|
||||
try:
|
||||
time.strptime(self.compute_date(text, default=default, year='2000'),
|
||||
self.format)
|
||||
except Exception:
|
||||
except ValueError:
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -203,7 +203,7 @@ class DateEntry(gtk.Entry):
|
||||
date = self.compute_date(self.get_text())
|
||||
try:
|
||||
res = datetime.datetime(*time.strptime(date, self.format)[:6])
|
||||
except Exception:
|
||||
except ValueError:
|
||||
return None
|
||||
self.set_text(date)
|
||||
return res
|
||||
@@ -336,7 +336,7 @@ def compute_date(cmd, dt, format):
|
||||
dt = datetime.datetime.now()
|
||||
try:
|
||||
return f(dt, groups)
|
||||
except Exception:
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -20,12 +20,15 @@ class EvalEnvironment(dict):
|
||||
return self.parent._get_on_change_args([item])[item]
|
||||
|
||||
def __getattr__(self, item):
|
||||
return self.__getitem__(item)
|
||||
try:
|
||||
return self.__getitem__(item)
|
||||
except KeyError:
|
||||
raise AttributeError(item)
|
||||
|
||||
def get(self, item, default=None):
|
||||
try:
|
||||
return self.__getattr__(item)
|
||||
except Exception:
|
||||
return self.__getitem__(item)
|
||||
except KeyError:
|
||||
pass
|
||||
return super(EvalEnvironment, self).get(item, default)
|
||||
|
||||
|
||||
+5
-3
@@ -11,6 +11,8 @@ import sys
|
||||
import locale
|
||||
import gtk
|
||||
|
||||
from tryton.exceptions import TrytonError
|
||||
|
||||
_ = gettext.gettext
|
||||
|
||||
def get_home_dir():
|
||||
@@ -122,10 +124,10 @@ class ConfigManager(object):
|
||||
opt, self.arguments = parser.parse_args()
|
||||
|
||||
if len(self.arguments) > 1:
|
||||
raise Exception(_('Too much arguments'))
|
||||
raise TrytonError(_('Too much arguments'))
|
||||
|
||||
if opt.config and not os.path.isfile(opt.config):
|
||||
raise Exception(_('File "%s" not found') % (opt.config,))
|
||||
raise TrytonError(_('File "%s" not found') % (opt.config,))
|
||||
self.rcfile = opt.config or os.path.join(get_config_dir(), 'tryton.conf')
|
||||
self.load()
|
||||
|
||||
@@ -150,7 +152,7 @@ class ConfigManager(object):
|
||||
configparser.add_section(section)
|
||||
configparser.set(section, name, self.config[entry])
|
||||
configparser.write(open(self.rcfile, 'wb'))
|
||||
except Exception:
|
||||
except IOError:
|
||||
logging.getLogger('common.options').warn(
|
||||
_('Unable to write config file %s!') % \
|
||||
(self.rcfile,))
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
#this repository contains the full copyright notices and license terms.
|
||||
|
||||
|
||||
class TrytonServerError(Exception):
|
||||
|
||||
def __init__(self, *args):
|
||||
super(TrytonServerError, self).__init__(*args)
|
||||
self.ex_type = str(args[0])
|
||||
self.traceback = args[-1]
|
||||
|
||||
|
||||
class TrytonError(Exception):
|
||||
|
||||
def __init__(self, ex_type):
|
||||
self.ex_type = ex_type
|
||||
+20
-15
@@ -19,6 +19,7 @@ from tryton.config import CONFIG, TRYTON_ICON, PIXMAPS_DIR, DATA_DIR, \
|
||||
get_config_dir
|
||||
import tryton.common as common
|
||||
from tryton.action import Action
|
||||
from tryton.exceptions import TrytonServerError, TrytonError
|
||||
from tryton.wizard import Wizard
|
||||
from tryton.gui.window import Window
|
||||
from tryton.gui.window.preference import Preference
|
||||
@@ -45,7 +46,7 @@ except ImportError:
|
||||
gtk_osxapplication = None
|
||||
try:
|
||||
import gtkspell
|
||||
except Exception:
|
||||
except ImportError:
|
||||
gtkspell = None
|
||||
|
||||
_ = gettext.gettext
|
||||
@@ -981,7 +982,7 @@ class Main(object):
|
||||
try:
|
||||
values = rpc.execute('model', self.menu_screen.model_name,
|
||||
'read', ids, ['rec_name'], rpc.CONTEXT)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.window)
|
||||
return
|
||||
try:
|
||||
@@ -992,7 +993,7 @@ class Main(object):
|
||||
'user_id': rpc._USER,
|
||||
'resource': self.menu_screen.model_name,
|
||||
}, rpc.CONTEXT)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.window)
|
||||
self.shortcut_set()
|
||||
|
||||
@@ -1006,7 +1007,7 @@ class Main(object):
|
||||
try:
|
||||
shortcuts = rpc.execute('model', 'ir.ui.view_sc', 'get_sc',
|
||||
user, 'ir.ui.menu', rpc.CONTEXT)
|
||||
except Exception:
|
||||
except TrytonServerError:
|
||||
shortcuts = []
|
||||
menu = gtk.Menu()
|
||||
for shortcut in shortcuts:
|
||||
@@ -1146,7 +1147,7 @@ class Main(object):
|
||||
ctx['active_test'] = False
|
||||
try:
|
||||
ids1, ids2 = self.request_set(True)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
if common.process_exception(exception, self.window):
|
||||
ids1, ids2 = self.request_set(True)
|
||||
else:
|
||||
@@ -1173,7 +1174,7 @@ class Main(object):
|
||||
len(ids2))
|
||||
self.sb_requests.set_text(message)
|
||||
return (ids, ids2)
|
||||
except Exception:
|
||||
except TrytonServerError:
|
||||
if exception:
|
||||
raise
|
||||
return ([], [])
|
||||
@@ -1185,15 +1186,16 @@ class Main(object):
|
||||
try:
|
||||
dblogin = DBLogin(self.window)
|
||||
res = dblogin.run(self.window)
|
||||
except Exception, exception:
|
||||
if exception.args == ('QueryCanceled',):
|
||||
except TrytonError, exception:
|
||||
if exception.ex_type == 'QueryCanceled':
|
||||
return False
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.window)
|
||||
return
|
||||
self.window.present()
|
||||
try:
|
||||
log_response = rpc.login(*res)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.window)
|
||||
return
|
||||
rpc.context_reload()
|
||||
@@ -1202,7 +1204,7 @@ class Main(object):
|
||||
try:
|
||||
prefs = rpc.execute('model', 'res.user', 'get_preferences',
|
||||
False, rpc.CONTEXT)
|
||||
except Exception:
|
||||
except TrytonServerError:
|
||||
prefs = None
|
||||
common.ICONFACTORY.load_icons()
|
||||
if prefs and 'language_direction' in prefs:
|
||||
@@ -1338,7 +1340,7 @@ class Main(object):
|
||||
args = ('model', 'res.user', 'get_preferences', False, rpc.CONTEXT)
|
||||
try:
|
||||
prefs = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
prefs = common.process_exception(exception, self.window, *args)
|
||||
if not prefs:
|
||||
return False
|
||||
@@ -1608,7 +1610,7 @@ class Main(object):
|
||||
dbname, passwd), self.window)
|
||||
try:
|
||||
rpcprogress.run()
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
self.refresh_ssl()
|
||||
if exception[0] == "AccessDenied":
|
||||
common.warning(_("Wrong Tryton Server Password" \
|
||||
@@ -1641,7 +1643,7 @@ class Main(object):
|
||||
'restore', dbname, passwd, data_b64, update), self.window)
|
||||
try:
|
||||
res = rpcprogress.run()
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
self.refresh_ssl()
|
||||
if exception[0] == \
|
||||
"Couldn't restore database with password":
|
||||
@@ -1684,7 +1686,7 @@ class Main(object):
|
||||
dbname, passwd), self.window)
|
||||
try:
|
||||
dump_b64 = rpcprogress.run()
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
if exception[0] == "Couldn't dump database with password":
|
||||
common.warning(_("It is not possible to dump a password " \
|
||||
"protected Database.\nBackup and restore " \
|
||||
@@ -1740,7 +1742,7 @@ class Main(object):
|
||||
try:
|
||||
params = dict(param.split('=', 1)
|
||||
for param in urlp.params.split('&'))
|
||||
except Exception:
|
||||
except ValueError:
|
||||
return
|
||||
|
||||
def open_model(path):
|
||||
@@ -1771,6 +1773,7 @@ class Main(object):
|
||||
name=name, limit=limit, auto_refresh=auto_refresh,
|
||||
search_value=search_value)
|
||||
except Exception:
|
||||
# Prevent crashing the client
|
||||
return
|
||||
|
||||
def open_wizard(wizard):
|
||||
@@ -1796,6 +1799,7 @@ class Main(object):
|
||||
direct_print=direct_print, email_print=email_print,
|
||||
email=email, context=context)
|
||||
except Exception:
|
||||
# Prevent crashing the client
|
||||
return
|
||||
|
||||
def open_report(report):
|
||||
@@ -1815,6 +1819,7 @@ class Main(object):
|
||||
direct_print=direct_print, email_print=email_print,
|
||||
email=email, context=context)
|
||||
except Exception:
|
||||
# Prevent crashing the client
|
||||
return
|
||||
|
||||
def open_url():
|
||||
|
||||
@@ -7,6 +7,7 @@ from tryton.signal_event import SignalEvent
|
||||
import tryton.rpc as rpc
|
||||
from tryton.gui.window.view_board import ViewBoard
|
||||
import tryton.common as common
|
||||
from tryton.exceptions import TrytonServerError
|
||||
|
||||
|
||||
class Board(SignalEvent):
|
||||
@@ -19,7 +20,7 @@ class Board(SignalEvent):
|
||||
try:
|
||||
view = rpc.execute('model', 'ir.ui.view', 'read',
|
||||
view_id, ['arch'], context)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, window)
|
||||
raise
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import gettext
|
||||
import re
|
||||
import tryton.common as common
|
||||
from tryton.config import CONFIG, TRYTON_ICON, PIXMAPS_DIR
|
||||
from tryton.exceptions import TrytonServerError
|
||||
import tryton.rpc as rpc
|
||||
|
||||
_ = gettext.gettext
|
||||
@@ -68,7 +69,7 @@ class DBCreate(object):
|
||||
if self.combo_language and host and port:
|
||||
common.refresh_langlist(self.combo_language, host, port)
|
||||
self.server_connection_state(True)
|
||||
except Exception:
|
||||
except TrytonServerError:
|
||||
self.server_connection_state(False)
|
||||
return False
|
||||
return True
|
||||
@@ -308,7 +309,7 @@ class DBCreate(object):
|
||||
self.combo_language.set_model(liststore)
|
||||
try:
|
||||
common.refresh_langlist(self.combo_language, self.host, self.port)
|
||||
except Exception:
|
||||
except TrytonServerError:
|
||||
self.button_create.set_sensitive(False)
|
||||
|
||||
while True:
|
||||
@@ -351,7 +352,7 @@ class DBCreate(object):
|
||||
try:
|
||||
exist = rpc.db_exec(url_m.group(1),
|
||||
int(url_m.group(2)), 'db_exist', dbname)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.dialog)
|
||||
continue
|
||||
if exist:
|
||||
@@ -371,7 +372,7 @@ class DBCreate(object):
|
||||
langreal, admin_passwd.get_text()),
|
||||
self.dialog)
|
||||
rpcprogress.run()
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
if str(exception[0]) == "AccessDenied":
|
||||
common.warning(_("Sorry, wrong password for " \
|
||||
"the Tryton server. Please try again."),
|
||||
|
||||
@@ -16,6 +16,7 @@ import tryton.common as common
|
||||
from tryton.config import CONFIG, TRYTON_ICON, PIXMAPS_DIR, get_config_dir
|
||||
import tryton.rpc as rpc
|
||||
from tryton.gui.window.dbcreate import DBCreate
|
||||
from tryton.exceptions import TrytonError
|
||||
|
||||
_ = gettext.gettext
|
||||
|
||||
@@ -642,7 +643,7 @@ class DBLogin(object):
|
||||
rpc.logout()
|
||||
from tryton.gui.main import Main
|
||||
Main.get_main().refresh_ssl()
|
||||
raise Exception('QueryCanceled')
|
||||
raise TrytonError('QueryCanceled')
|
||||
parent.present()
|
||||
self.dialog.destroy()
|
||||
return result
|
||||
|
||||
@@ -15,7 +15,9 @@ from tryton.gui.window.win_export import WinExport
|
||||
from tryton.gui.window.win_import import WinImport
|
||||
from tryton.gui.window.attachment import Attachment
|
||||
from tryton.signal_event import SignalEvent
|
||||
from tryton.common import TRYTON_ICON, message, sur, sur_3b, COLOR_SCHEMES
|
||||
from tryton.common import (TRYTON_ICON, message, sur, sur_3b, COLOR_SCHEMES,
|
||||
timezoned_date)
|
||||
from tryton.exceptions import TrytonServerError
|
||||
import tryton.common as common
|
||||
import pango
|
||||
from tryton.translate import date_format
|
||||
@@ -186,7 +188,7 @@ class Form(SignalEvent):
|
||||
new_value = value[:position] + new_text + value[position:]
|
||||
try:
|
||||
locale.atoi(new_value)
|
||||
except Exception:
|
||||
except ValueError:
|
||||
widget.stop_emission('insert-text')
|
||||
entry.connect('insert_text', sig_insert_text)
|
||||
table.attach(entry, 1, 2, 1, 2)
|
||||
@@ -263,7 +265,7 @@ class Form(SignalEvent):
|
||||
ctx)
|
||||
try:
|
||||
res = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
res = common.process_exception(exception, self.window, *args)
|
||||
if not res:
|
||||
return
|
||||
@@ -274,17 +276,7 @@ class Form(SignalEvent):
|
||||
if line.get(key, False) \
|
||||
and key in ('create_date', 'write_date'):
|
||||
display_format = date_format() + ' ' + HM_FORMAT
|
||||
date = line[key]
|
||||
if 'timezone' in rpc.CONTEXT:
|
||||
try:
|
||||
import pytz
|
||||
lzone = pytz.timezone(rpc.CONTEXT['timezone'])
|
||||
szone = pytz.timezone(rpc.TIMEZONE)
|
||||
sdt = szone.localize(datetime, is_dst=True)
|
||||
ldt = sdt.astimezone(lzone)
|
||||
date = ldt
|
||||
except Exception:
|
||||
pass
|
||||
date = timezoned_date(line[key])
|
||||
value = common.datetime_strftime(date, display_format)
|
||||
message_str += val + ' ' + value +'\n'
|
||||
message_str += _('Model:') + ' ' + self.model
|
||||
@@ -337,7 +329,7 @@ class Form(SignalEvent):
|
||||
args = ('model', self.model, 'copy', res_ids, {}, ctx)
|
||||
try:
|
||||
new_ids = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
new_ids = common.process_exception(exception, self.window, *args)
|
||||
if new_ids:
|
||||
self.screen.load(new_ids)
|
||||
|
||||
@@ -7,6 +7,7 @@ import tryton.rpc as rpc
|
||||
import copy
|
||||
from tryton.gui.window.view_form.screen import Screen
|
||||
from tryton.config import TRYTON_ICON
|
||||
from tryton.exceptions import TrytonServerError
|
||||
import tryton.common as common
|
||||
|
||||
_ = gettext.gettext
|
||||
@@ -38,7 +39,7 @@ class Preference(object):
|
||||
rpc.CONTEXT)
|
||||
try:
|
||||
view = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
view = common.process_exception(exception, parent, *args)
|
||||
if not view:
|
||||
self.win.destroy()
|
||||
@@ -55,7 +56,7 @@ class Preference(object):
|
||||
args = ('model', 'res.user', 'get_preferences', False, rpc.CONTEXT)
|
||||
try:
|
||||
preferences = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
preferences = common.process_exception(exception, parent, *args)
|
||||
if not preferences:
|
||||
self.win.destroy()
|
||||
@@ -94,7 +95,7 @@ class Preference(object):
|
||||
password, rpc.CONTEXT)
|
||||
try:
|
||||
rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
if not common.process_exception(exception, self.win,
|
||||
*args):
|
||||
continue
|
||||
|
||||
@@ -92,7 +92,7 @@ You can save any graphs in PNG file with right-click on it.
|
||||
|
||||
try:
|
||||
self.number = int(CONFIG['tip.position'])
|
||||
except Exception:
|
||||
except ValueError:
|
||||
self.number = 0
|
||||
|
||||
self.tip_set()
|
||||
|
||||
@@ -13,6 +13,7 @@ from tryton.pyson import PYSONDecoder
|
||||
import gettext
|
||||
from tryton.config import CONFIG
|
||||
from tryton.signal_event import SignalEvent
|
||||
from tryton.exceptions import TrytonServerError
|
||||
_ = gettext.gettext
|
||||
|
||||
|
||||
@@ -28,7 +29,7 @@ class Action(SignalEvent):
|
||||
try:
|
||||
self.action = rpc.execute('model', 'ir.action.act_window', 'read',
|
||||
self.act_id, False, rpc.CONTEXT)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self._window)
|
||||
raise
|
||||
|
||||
@@ -185,7 +186,7 @@ class Action(SignalEvent):
|
||||
try:
|
||||
action_id = rpc.execute('model', 'ir.action',
|
||||
'get_action_id', self.act_id, rpc.CONTEXT)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self._window)
|
||||
if action_id:
|
||||
Action2.execute(action_id, {}, self._window)
|
||||
@@ -212,7 +213,7 @@ class Action(SignalEvent):
|
||||
res_ids = rpc.execute('model', self.action['res_model'], 'search',
|
||||
self.domain, 0, self.action['limit'] or
|
||||
CONFIG['client.limit'], None, rpc.CONTEXT)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self._window)
|
||||
return False
|
||||
if self.screen:
|
||||
|
||||
@@ -9,6 +9,7 @@ import time
|
||||
import datetime
|
||||
from decimal import Decimal
|
||||
import logging
|
||||
from tryton.exceptions import TrytonServerError
|
||||
|
||||
|
||||
class Field(object):
|
||||
@@ -137,12 +138,7 @@ class CharField(object):
|
||||
if (internal or False) != (record.value.get(self.name, False) or False):
|
||||
record.modified_fields.setdefault(self.name)
|
||||
record.signal('record-modified')
|
||||
try:
|
||||
self.sig_changed(record)
|
||||
except Exception:
|
||||
record.value[self.name] = internal
|
||||
record.modified_fields = prev_modified_fields
|
||||
return
|
||||
self.sig_changed(record)
|
||||
record.validate(softvalidation=True)
|
||||
record.signal('record-changed')
|
||||
|
||||
@@ -240,12 +236,7 @@ class FloatField(CharField):
|
||||
if not self.get_state_attrs(record).get('readonly', False):
|
||||
record.modified_fields.setdefault(self.name)
|
||||
record.signal('record-modified')
|
||||
try:
|
||||
self.sig_changed(record)
|
||||
except Exception:
|
||||
record.value[self.name] = internal
|
||||
record.modified_fields = prev_modified_fields
|
||||
return
|
||||
self.sig_changed(record)
|
||||
record.validate(softvalidation=True)
|
||||
record.signal('record-changed')
|
||||
|
||||
@@ -264,12 +255,7 @@ class NumericField(CharField):
|
||||
if not self.get_state_attrs(record).get('readonly', False):
|
||||
record.modified_fields.setdefault(self.name)
|
||||
record.signal('record-modified')
|
||||
try:
|
||||
self.sig_changed(record)
|
||||
except Exception:
|
||||
record.value[self.name] = internal
|
||||
record.prev_modified_fields = prev_modified_fields
|
||||
return
|
||||
self.sig_changed(record)
|
||||
record.validate(softvalidation=True)
|
||||
record.signal('record-changed')
|
||||
|
||||
@@ -292,12 +278,7 @@ class BooleanField(CharField):
|
||||
if internal != bool(record.value.get(self.name, False)):
|
||||
record.modified_fields.setdefault(self.name)
|
||||
record.signal('record-modified')
|
||||
try:
|
||||
self.sig_changed(record)
|
||||
except Exception:
|
||||
record.value[self.name] = internal
|
||||
record.modified_fields = prev_modified_fields
|
||||
return
|
||||
self.sig_changed(record)
|
||||
record.validate(softvalidation=True)
|
||||
record.signal('record-changed')
|
||||
|
||||
@@ -353,7 +334,7 @@ class M2OField(CharField):
|
||||
['rec_name'], rpc.CONTEXT)
|
||||
try:
|
||||
result = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
result = common.process_exception(exception, record.window,
|
||||
*args)
|
||||
if not result:
|
||||
@@ -386,20 +367,11 @@ class M2OField(CharField):
|
||||
if (internal[0] or False) != (record.value[self.name][0] or False):
|
||||
record.modified_fields.setdefault(self.name)
|
||||
record.signal('record-modified')
|
||||
try:
|
||||
self.sig_changed(record)
|
||||
except Exception:
|
||||
record.value[self.name] = internal
|
||||
record.modified_fields = prev_modified_fields
|
||||
return
|
||||
self.sig_changed(record)
|
||||
record.validate(softvalidation=True)
|
||||
record.signal('record-changed')
|
||||
elif force_change:
|
||||
try:
|
||||
self.sig_changed(record)
|
||||
except Exception:
|
||||
record.value[self.name] = internal
|
||||
return
|
||||
self.sig_changed(record)
|
||||
record.validate(softvalidation=True)
|
||||
record.signal('record-changed')
|
||||
|
||||
@@ -584,7 +556,7 @@ class O2MField(CharField):
|
||||
field_names, context)
|
||||
try:
|
||||
fields_to_load = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
fields_dict = common.process_exception(exception,
|
||||
record.window, *args)
|
||||
if not fields_dict:
|
||||
@@ -627,7 +599,7 @@ class O2MField(CharField):
|
||||
field_names, context)
|
||||
try:
|
||||
fields = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
fields = common.process_exception(exception, record.window,
|
||||
*args)
|
||||
if not fields:
|
||||
@@ -766,12 +738,7 @@ class ReferenceField(CharField):
|
||||
if (internal or False) != (record.value[self.name] or False):
|
||||
record.modified_fields.setdefault(self.name)
|
||||
record.signal('record-modified')
|
||||
try:
|
||||
self.sig_changed(record)
|
||||
except Exception:
|
||||
record.value[self.name] = internal
|
||||
record.modified_fields = prev_modified_fields
|
||||
return
|
||||
self.sig_changed(record)
|
||||
record.validate(softvalidation=True)
|
||||
record.signal('record-changed')
|
||||
|
||||
@@ -792,7 +759,7 @@ class ReferenceField(CharField):
|
||||
['rec_name'], rpc.CONTEXT)
|
||||
try:
|
||||
result = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
result = common.process_exception(exception, record.window,
|
||||
*args)
|
||||
if not result:
|
||||
|
||||
@@ -6,6 +6,7 @@ from record import Record
|
||||
from field import Field, O2MField
|
||||
from tryton.signal_event import SignalEvent
|
||||
import tryton.common as common
|
||||
from tryton.exceptions import TrytonServerError
|
||||
|
||||
|
||||
class Group(SignalEvent, list):
|
||||
@@ -159,7 +160,7 @@ class Group(SignalEvent, list):
|
||||
args = ('model', self.model_name, fnct, ids, self.context)
|
||||
try:
|
||||
res += rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
res2 = common.process_exception(exception, self.window, *args)
|
||||
if not res2:
|
||||
return False
|
||||
@@ -352,7 +353,7 @@ class Group(SignalEvent, list):
|
||||
args = ('model', self.model_name, 'default_get', to_add.keys(), ctx)
|
||||
try:
|
||||
values = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
values = common.process_exception(exception, self.window, *args)
|
||||
if not values:
|
||||
return False
|
||||
|
||||
@@ -8,6 +8,7 @@ import field
|
||||
import datetime
|
||||
import logging
|
||||
import time
|
||||
from tryton.exceptions import TrytonServerError
|
||||
|
||||
|
||||
class Record(SignalEvent):
|
||||
@@ -74,7 +75,7 @@ class Record(SignalEvent):
|
||||
args = ('model', self.model_name, 'read', ids, fields, ctx)
|
||||
try:
|
||||
values = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
if raise_exception:
|
||||
raise
|
||||
values = common.process_exception(exception, self.window, *args)
|
||||
@@ -245,7 +246,7 @@ class Record(SignalEvent):
|
||||
self.context_get())
|
||||
try:
|
||||
res = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
res = common.process_exception(exception, self.window,
|
||||
*args)
|
||||
if not res:
|
||||
@@ -266,7 +267,7 @@ class Record(SignalEvent):
|
||||
try:
|
||||
if not rpc.execute(*args):
|
||||
return False
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
res = common.process_exception(exception, self.window,
|
||||
*args)
|
||||
if not res:
|
||||
@@ -288,7 +289,7 @@ class Record(SignalEvent):
|
||||
self.group.fields.keys(), context)
|
||||
try:
|
||||
vals = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
vals = common.process_exception(exception, self.window, *args)
|
||||
if not vals:
|
||||
return
|
||||
@@ -306,7 +307,7 @@ class Record(SignalEvent):
|
||||
args = ('model', self.model_name, 'read', self.id, ['rec_name'], ctx)
|
||||
try:
|
||||
res = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
res = common.process_exception(exception, self.window, *args)
|
||||
if not res:
|
||||
return ''
|
||||
@@ -456,7 +457,7 @@ class Record(SignalEvent):
|
||||
args = ('model', self.model_name, 'on_change_' + fieldname, args, ctx)
|
||||
try:
|
||||
res = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
res = common.process_exception(exception, self.window, *args)
|
||||
if not res:
|
||||
return
|
||||
@@ -506,7 +507,7 @@ class Record(SignalEvent):
|
||||
args, ctx)
|
||||
try:
|
||||
res = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
res = common.process_exception(exception, self.window, *args)
|
||||
if not res:
|
||||
return
|
||||
@@ -529,7 +530,7 @@ class Record(SignalEvent):
|
||||
ctx)
|
||||
try:
|
||||
res = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
res = common.process_exception(exception, self.window, *args)
|
||||
if not res:
|
||||
# ensure res is a list
|
||||
@@ -543,7 +544,7 @@ class Record(SignalEvent):
|
||||
field_name + '=' + str(value), ctx)
|
||||
try:
|
||||
res = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
res = common.process_exception(exception, self.window, *args)
|
||||
if not res:
|
||||
return
|
||||
@@ -558,7 +559,7 @@ class Record(SignalEvent):
|
||||
], rpc.CONTEXT)
|
||||
try:
|
||||
self.attachment_count = rpc.execute(*args)
|
||||
except Exception:
|
||||
except TrytonServerError:
|
||||
return 0
|
||||
return self.attachment_count
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ from tryton.signal_event import SignalEvent
|
||||
from tryton.common import node_attributes
|
||||
from tryton.config import CONFIG
|
||||
import tryton.common as common
|
||||
from tryton.exceptions import TrytonServerError
|
||||
|
||||
|
||||
class Screen(SignalEvent):
|
||||
@@ -49,13 +50,13 @@ class Screen(SignalEvent):
|
||||
self.parent = None
|
||||
self.parent_name = None
|
||||
self.__window = window
|
||||
self.filter_widget = None
|
||||
self.__group = None
|
||||
self.new_group()
|
||||
self.__current_record = None
|
||||
self.current_record = None
|
||||
self.screen_container = ScreenContainer()
|
||||
self.screen_container.alternate_view = alternate_view
|
||||
self.filter_widget = None
|
||||
self.widget = self.screen_container.widget_get()
|
||||
self.__current_view = 0
|
||||
self.limit = limit
|
||||
@@ -88,7 +89,7 @@ class Screen(SignalEvent):
|
||||
self.fields_view_tree = rpc.execute('model',
|
||||
self.model_name, 'fields_view_get', False,
|
||||
'tree', ctx)
|
||||
except Exception:
|
||||
except TrytonServerError:
|
||||
return
|
||||
self.filter_widget = Form(self.fields_view_tree,
|
||||
self.model_name, self.window, self.domain,
|
||||
@@ -132,27 +133,24 @@ class Screen(SignalEvent):
|
||||
values = ['AND', values, self.domain]
|
||||
else:
|
||||
values = self.domain
|
||||
rpc_args = ('model', self.model_name, 'search', values, offset, limit,
|
||||
self.sort, ctx)
|
||||
try:
|
||||
try:
|
||||
ids = rpc.execute('model', self.model_name, 'search', values,
|
||||
offset, limit, self.sort, ctx)
|
||||
except Exception, exception:
|
||||
common.process_exception(exception, self.window)
|
||||
ids = rpc.execute('model', self.model_name, 'search', values,
|
||||
offset, limit, self.sort, ctx)
|
||||
if not only_ids:
|
||||
if len(ids) == limit:
|
||||
try:
|
||||
self.search_count = rpc.execute('model',
|
||||
self.model_name, 'search_count', values, ctx)
|
||||
except Exception, exception:
|
||||
common.process_exception(exception, self.window)
|
||||
self.search_count = rpc.execute('model',
|
||||
self.model_name, 'search_count', values, ctx)
|
||||
else:
|
||||
self.search_count = len(ids)
|
||||
except Exception:
|
||||
ids = []
|
||||
ids = rpc.execute(*rpc_args)
|
||||
except TrytonServerError, exception:
|
||||
ids = (common.process_exception(exception, self.window, rpc_args)
|
||||
or [])
|
||||
if not only_ids:
|
||||
if len(ids) == limit:
|
||||
rpc_args = ('model', self.model_name, 'search_count', values,
|
||||
ctx)
|
||||
try:
|
||||
self.search_count = rpc.execute(*rpc_args)
|
||||
except TrytonServerError, exception:
|
||||
self.search_count = (common.process_exception(exception,
|
||||
self.window, rpc_args) or 0)
|
||||
else:
|
||||
self.search_count = len(ids)
|
||||
self.screen_container.but_prev.set_sensitive(bool(offset))
|
||||
if (len(ids) == limit
|
||||
and self.search_count > limit + offset):
|
||||
@@ -218,9 +216,9 @@ class Screen(SignalEvent):
|
||||
|
||||
def __set_current_record(self, record):
|
||||
self.__current_record = record
|
||||
try:
|
||||
if self.filter_widget:
|
||||
offset = int(self.filter_widget.get_offset())
|
||||
except Exception:
|
||||
else:
|
||||
offset = 0
|
||||
try:
|
||||
pos = self.group.index(record) + offset + 1
|
||||
@@ -339,7 +337,7 @@ class Screen(SignalEvent):
|
||||
ctx)
|
||||
try:
|
||||
view = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
view = common.process_exception(exception, self.window, *args)
|
||||
if not view:
|
||||
return
|
||||
@@ -540,7 +538,7 @@ class Screen(SignalEvent):
|
||||
context)
|
||||
try:
|
||||
res = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
res = common.process_exception(exception, self.window,
|
||||
*args)
|
||||
if not res:
|
||||
@@ -586,7 +584,7 @@ class Screen(SignalEvent):
|
||||
[x.id for x in records], context)
|
||||
try:
|
||||
res = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
res = common.process_exception(exception, self.window,
|
||||
*args)
|
||||
if not res:
|
||||
|
||||
@@ -8,7 +8,7 @@ import locale
|
||||
from interface import WidgetInterface
|
||||
import tryton.rpc as rpc
|
||||
from tryton.common import DT_FORMAT, DHM_FORMAT, HM_FORMAT, message, \
|
||||
TRYTON_ICON
|
||||
TRYTON_ICON, timezoned_date
|
||||
from tryton.common import date_widget, Tooltips, datetime_strftime
|
||||
from tryton.translate import date_format
|
||||
|
||||
@@ -72,7 +72,7 @@ class Calendar(WidgetInterface):
|
||||
return False
|
||||
try:
|
||||
date = datetime.date(*time.strptime(value, self.format)[:3])
|
||||
except Exception:
|
||||
except ValueError:
|
||||
return False
|
||||
return datetime_strftime(date, DT_FORMAT)
|
||||
|
||||
@@ -207,18 +207,9 @@ class DateTime(WidgetInterface):
|
||||
return False
|
||||
try:
|
||||
date = datetime.datetime(*time.strptime(value, self.format)[:6])
|
||||
except Exception:
|
||||
except ValueError:
|
||||
return False
|
||||
if 'timezone' in rpc.CONTEXT and timezone:
|
||||
try:
|
||||
import pytz
|
||||
lzone = pytz.timezone(rpc.CONTEXT['timezone'])
|
||||
szone = pytz.timezone(rpc.TIMEZONE)
|
||||
ldt = lzone.localize(date, is_dst=True)
|
||||
sdt = ldt.astimezone(szone)
|
||||
date = sdt
|
||||
except Exception:
|
||||
pass
|
||||
date = timezoned_date(date)
|
||||
return datetime_strftime(date, DHM_FORMAT)
|
||||
|
||||
def set_value(self, record, field):
|
||||
@@ -236,16 +227,7 @@ class DateTime(WidgetInterface):
|
||||
self.entry.clear()
|
||||
else:
|
||||
date = datetime.datetime(*time.strptime(dt_val, DHM_FORMAT)[:6])
|
||||
if 'timezone' in rpc.CONTEXT and timezone:
|
||||
try:
|
||||
import pytz
|
||||
lzone = pytz.timezone(rpc.CONTEXT['timezone'])
|
||||
szone = pytz.timezone(rpc.TIMEZONE)
|
||||
sdt = szone.localize(date, is_dst=True)
|
||||
ldt = sdt.astimezone(lzone)
|
||||
date = ldt
|
||||
except Exception:
|
||||
pass
|
||||
date = timezoned_date(date)
|
||||
format = self.format
|
||||
if date.year < 10:
|
||||
format = format.replace('%Y', '000%Y')
|
||||
|
||||
@@ -17,7 +17,7 @@ class Float(Integer):
|
||||
def set_value(self, record, field):
|
||||
try:
|
||||
value = locale.atof(self.entry.get_text())
|
||||
except Exception:
|
||||
except ValueError:
|
||||
value = 0.0
|
||||
return field.set_client(record, value)
|
||||
|
||||
@@ -41,30 +41,35 @@ class Float(Integer):
|
||||
ord(locale.localeconv()['decimal_point'])))
|
||||
|
||||
def sig_insert_text(self, entry, new_text, new_text_length, position):
|
||||
if not self.record:
|
||||
entry.stop_emission('insert-text')
|
||||
return
|
||||
|
||||
value = entry.get_text()
|
||||
position = entry.get_position()
|
||||
new_value = value[:position] + new_text + value[position:]
|
||||
decimal_point = locale.localeconv()['decimal_point']
|
||||
|
||||
if new_value in ('-', decimal_point):
|
||||
return
|
||||
|
||||
if isinstance(self.digits, str):
|
||||
digits = self.record.expr_eval(self.digits)
|
||||
else:
|
||||
digits = self.digits
|
||||
|
||||
try:
|
||||
decimal_point = locale.localeconv()['decimal_point']
|
||||
|
||||
if new_value in ('-', decimal_point):
|
||||
return
|
||||
|
||||
if isinstance(self.digits, str):
|
||||
digits = self.record.expr_eval(self.digits)
|
||||
else:
|
||||
digits = self.digits
|
||||
|
||||
locale.atof(new_value)
|
||||
|
||||
new_int = new_value
|
||||
new_decimal = ''
|
||||
if decimal_point in new_value:
|
||||
new_int, new_decimal = new_value.rsplit(decimal_point, 1)
|
||||
|
||||
if len(new_int) > digits[0] \
|
||||
or len(new_decimal) > digits[1]:
|
||||
entry.stop_emission('insert-text')
|
||||
|
||||
except Exception:
|
||||
except ValueError:
|
||||
entry.stop_emission('insert-text')
|
||||
return
|
||||
|
||||
new_int = new_value
|
||||
new_decimal = ''
|
||||
if decimal_point in new_value:
|
||||
new_int, new_decimal = new_value.rsplit(decimal_point, 1)
|
||||
|
||||
if len(new_int) > digits[0] \
|
||||
or len(new_decimal) > digits[1]:
|
||||
entry.stop_emission('insert-text')
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#this repository contains the full copyright notices and license terms.
|
||||
from __future__ import with_statement
|
||||
import gtk
|
||||
import glib
|
||||
import gettext
|
||||
import os
|
||||
import tempfile
|
||||
@@ -208,7 +209,7 @@ class Image(WidgetInterface):
|
||||
try:
|
||||
loader = gtk.gdk.PixbufLoader(ftype)
|
||||
loader.write(data, len(data))
|
||||
except Exception:
|
||||
except glib.GError:
|
||||
continue
|
||||
pixbuf = loader.get_pixbuf()
|
||||
if pixbuf:
|
||||
|
||||
@@ -17,7 +17,7 @@ class Integer(Char):
|
||||
def set_value(self, record, field):
|
||||
try:
|
||||
value = locale.atoi(self.entry.get_text())
|
||||
except Exception:
|
||||
except ValueError:
|
||||
value = 0
|
||||
return field.set_client(record, value)
|
||||
|
||||
@@ -37,9 +37,9 @@ class Integer(Char):
|
||||
value = entry.get_text()
|
||||
position = entry.get_position()
|
||||
new_value = value[:position] + new_text + value[position:]
|
||||
if new_value == '-':
|
||||
return
|
||||
try:
|
||||
if new_value == '-':
|
||||
return
|
||||
locale.atoi(new_value)
|
||||
except Exception:
|
||||
except ValueError:
|
||||
entry.stop_emission('insert-text')
|
||||
@@ -7,6 +7,7 @@ import tryton.rpc as rpc
|
||||
from tryton.gui.window.win_search import WinSearch
|
||||
from tryton.gui.window.win_form import WinForm
|
||||
from tryton.config import CONFIG
|
||||
from tryton.exceptions import TrytonServerError
|
||||
import tryton.common as common
|
||||
import gettext
|
||||
|
||||
@@ -116,7 +117,7 @@ class Many2Many(WidgetInterface):
|
||||
dom = domain
|
||||
ids = rpc.execute('model', self.attrs['relation'], 'search',
|
||||
dom , 0, CONFIG['client.limit'], None, context)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.window)
|
||||
return False
|
||||
if len(ids) != 1 or not value:
|
||||
@@ -179,7 +180,7 @@ class Many2Many(WidgetInterface):
|
||||
try:
|
||||
result = rpc.execute('model', self.attrs['relation'], 'read',
|
||||
ids, ['rec_name'], rpc.CONTEXT)
|
||||
except Exception:
|
||||
except TrytonServerError:
|
||||
return str(ids)
|
||||
return ', '.join(x['rec_name'] for x in result)
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import tryton.rpc as rpc
|
||||
from tryton.action import Action
|
||||
from tryton.config import CONFIG
|
||||
from tryton.pyson import PYSONEncoder
|
||||
from tryton.exceptions import TrytonServerError
|
||||
import pango
|
||||
|
||||
_ = gettext.gettext
|
||||
@@ -113,7 +114,7 @@ class Many2One(WidgetInterface):
|
||||
ids = rpc.execute('model', self.attrs['relation'],
|
||||
'search', dom, 0, CONFIG['client.limit'], None,
|
||||
context)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
self.focus_out = True
|
||||
common.process_exception(exception, self.window)
|
||||
self.changed = True
|
||||
@@ -199,7 +200,7 @@ class Many2One(WidgetInterface):
|
||||
ids = rpc.execute('model', self.attrs['relation'],
|
||||
'search', dom, 0, CONFIG['client.limit'], None,
|
||||
context)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
self.focus_out = True
|
||||
common.process_exception(exception, self.window)
|
||||
self.changed = True
|
||||
@@ -271,7 +272,7 @@ class Many2One(WidgetInterface):
|
||||
'form_relate', (self.attrs['relation'], 0), rpc.CONTEXT)
|
||||
try:
|
||||
relates = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
relates = common.process_exception(exception, self.window)
|
||||
if not relates:
|
||||
return False
|
||||
|
||||
@@ -8,6 +8,7 @@ from tryton.gui.window.view_form.screen import Screen
|
||||
from tryton.gui.window.win_search import WinSearch
|
||||
from tryton.gui.window.win_form import WinForm
|
||||
from tryton.config import CONFIG
|
||||
from tryton.exceptions import TrytonServerError
|
||||
import tryton.common as common
|
||||
import tryton.rpc as rpc
|
||||
import pango
|
||||
@@ -307,7 +308,7 @@ class One2Many(WidgetInterface):
|
||||
dom = ['OR', domain, ('id', 'in', removed_ids)]
|
||||
ids = rpc.execute('model', self.attrs['relation'], 'search', dom,
|
||||
0, CONFIG['client.limit'], None, context)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.window)
|
||||
return False
|
||||
if len(ids) != 1:
|
||||
|
||||
@@ -10,6 +10,7 @@ import tryton.common as common
|
||||
from tryton.config import CONFIG, TRYTON_ICON
|
||||
from tryton.gui.main import Main
|
||||
import logging
|
||||
from tryton.exceptions import TrytonServerError
|
||||
|
||||
_ = gettext.gettext
|
||||
|
||||
@@ -32,7 +33,7 @@ class Button(object):
|
||||
icon = gtk.Image()
|
||||
icon.set_from_stock(stock, gtk.ICON_SIZE_SMALL_TOOLBAR)
|
||||
self.widget.set_image(icon)
|
||||
except Exception:
|
||||
except KeyError:
|
||||
log = logging.getLogger('common')
|
||||
log.warning(_('Wrong icon for the button!'))
|
||||
self.widget.connect('clicked', self.button_clicked)
|
||||
@@ -55,7 +56,7 @@ class Button(object):
|
||||
self.attrs['name'], ctx)
|
||||
try:
|
||||
rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.form.window,
|
||||
*args)
|
||||
elif button_type == 'object':
|
||||
@@ -63,7 +64,7 @@ class Button(object):
|
||||
[obj_id], ctx)
|
||||
try:
|
||||
rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.form.window,
|
||||
*args)
|
||||
elif button_type == 'action':
|
||||
@@ -72,7 +73,7 @@ class Button(object):
|
||||
int(self.attrs['name']), ctx)
|
||||
try:
|
||||
action_id = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
action_id = common.process_exception(exception, self.form.window,
|
||||
*args)
|
||||
if action_id:
|
||||
@@ -101,14 +102,10 @@ class Button(object):
|
||||
if 'icon' in state_changes:
|
||||
stock = state_changes['icon']
|
||||
if stock:
|
||||
try:
|
||||
common.ICONFACTORY.register_icon(stock)
|
||||
icon = gtk.Image()
|
||||
icon.set_from_stock(stock, gtk.ICON_SIZE_SMALL_TOOLBAR)
|
||||
self.widget.set_image(icon)
|
||||
except Exception:
|
||||
log = logging.getLogger('common')
|
||||
log.warning(_('Wrong icon for the button!'))
|
||||
common.ICONFACTORY.register_icon(stock)
|
||||
icon = gtk.Image()
|
||||
icon.set_from_stock(stock, gtk.ICON_SIZE_SMALL_TOOLBAR)
|
||||
self.widget.set_image(icon)
|
||||
else:
|
||||
self.widget.set_image(gtk.Image())
|
||||
|
||||
@@ -685,7 +682,7 @@ class ParserForm(ParserInterface):
|
||||
lang_ids = rpc.execute('model', 'ir.lang',
|
||||
'search', [('translatable', '=', '1')],
|
||||
rpc.CONTEXT)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.window)
|
||||
return False
|
||||
|
||||
@@ -700,7 +697,7 @@ class ParserForm(ParserInterface):
|
||||
langs = rpc.execute('model', 'ir.lang',
|
||||
'read', lang_ids, ['code', 'name'],
|
||||
rpc.CONTEXT)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.window)
|
||||
return False
|
||||
|
||||
@@ -784,7 +781,7 @@ class ParserForm(ParserInterface):
|
||||
try:
|
||||
val = rpc.execute('model', model_name,
|
||||
'read', [obj_id], [name], context)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.window)
|
||||
return False
|
||||
val = val[0]
|
||||
@@ -837,7 +834,7 @@ class ParserForm(ParserInterface):
|
||||
{str(name): new_val['value']}, context)
|
||||
try:
|
||||
rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.window, *args)
|
||||
if response == gtk.RESPONSE_CANCEL:
|
||||
self.window.present()
|
||||
|
||||
@@ -7,6 +7,7 @@ from interface import WidgetInterface
|
||||
from tryton.gui.window.win_search import WinSearch
|
||||
from tryton.gui.window.win_form import WinForm
|
||||
from tryton.gui.window.view_form.screen import Screen
|
||||
from tryton.exceptions import TrytonServerError
|
||||
import tryton.rpc as rpc
|
||||
import tryton.common as common
|
||||
from tryton.config import CONFIG
|
||||
@@ -80,7 +81,7 @@ class Reference(WidgetInterface):
|
||||
try:
|
||||
selection = rpc.execute('model',
|
||||
self.model_name, selection, rpc.CONTEXT)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.window)
|
||||
selection = []
|
||||
selection.sort(lambda x, y: cmp(x[1], y[1]))
|
||||
@@ -177,7 +178,7 @@ class Reference(WidgetInterface):
|
||||
dom = domain
|
||||
ids = rpc.execute('model', model, 'search', dom, 0,
|
||||
CONFIG['client.limit'], None, context)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
self.focus_out = True
|
||||
self.changed = True
|
||||
common.process_exception(exception, self.window)
|
||||
@@ -269,7 +270,7 @@ class Reference(WidgetInterface):
|
||||
rpc.CONTEXT)
|
||||
try:
|
||||
name = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
name = common.process_exception(exception, self.window,
|
||||
*args)
|
||||
if not name:
|
||||
|
||||
@@ -5,6 +5,8 @@ import gobject
|
||||
from interface import WidgetInterface
|
||||
import tryton.rpc as rpc
|
||||
import tryton.common as common
|
||||
from tryton.pyson import PYSONDecoder
|
||||
from tryton.exceptions import TrytonServerError
|
||||
|
||||
|
||||
class Selection(WidgetInterface):
|
||||
@@ -41,7 +43,7 @@ class Selection(WidgetInterface):
|
||||
try:
|
||||
selection = rpc.execute('model',
|
||||
self.model_name, selection, rpc.CONTEXT)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.window)
|
||||
selection = []
|
||||
self.selection = selection[:]
|
||||
@@ -63,7 +65,7 @@ class Selection(WidgetInterface):
|
||||
None, ['rec_name'], rpc.CONTEXT)
|
||||
try:
|
||||
result = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
result = common.process_exception(exception, self.window, args)
|
||||
if isinstance(result, list):
|
||||
selection = [(x['id'], x['rec_name']) for x in result]
|
||||
|
||||
@@ -7,7 +7,7 @@ from tryton.config import CONFIG
|
||||
|
||||
try:
|
||||
import gtkspell
|
||||
except Exception:
|
||||
except ImportError:
|
||||
gtkspell = None
|
||||
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ def save(widget, graph, window):
|
||||
CONFIG['client.default_path'] = \
|
||||
os.path.dirname(filepath)
|
||||
CONFIG.save()
|
||||
except Exception:
|
||||
except IOError:
|
||||
pass
|
||||
if response == gtk.RESPONSE_OK:
|
||||
if width and height and filename:
|
||||
|
||||
@@ -18,6 +18,7 @@ from tryton.config import CONFIG
|
||||
from tryton.common.cellrendererbutton import CellRendererButton
|
||||
from tryton.common.cellrenderertoggle import CellRendererToggle
|
||||
from tryton.pyson import PYSONEncoder
|
||||
from tryton.exceptions import TrytonServerError
|
||||
import os
|
||||
|
||||
_ = gettext.gettext
|
||||
@@ -137,7 +138,7 @@ class AdaptModelGroup(gtk.GenericTreeModel):
|
||||
if old_pos != pos:
|
||||
new_order[old_pos] = pos
|
||||
pos += 1
|
||||
except Exception:
|
||||
except KeyError:
|
||||
continue
|
||||
self.group.sort(lambda x, y: \
|
||||
cmp(new_order[ids2pos[x.id]], new_order[ids2pos[y.id]]))
|
||||
@@ -465,7 +466,7 @@ class ViewList(ParserView):
|
||||
try:
|
||||
for field in fields:
|
||||
record.__getitem__(field, True)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
return True
|
||||
iter_ = model.iter_next(iter_)
|
||||
return False
|
||||
@@ -621,7 +622,7 @@ class ViewList(ParserView):
|
||||
path[1].name].attrs['relation'], 0), rpc.CONTEXT)
|
||||
try:
|
||||
relates = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
relates = common.process_exception(exception, self.window,
|
||||
*args)
|
||||
if not relates:
|
||||
@@ -725,7 +726,7 @@ class ViewList(ParserView):
|
||||
try:
|
||||
rpc.execute('model', 'ir.ui.view_tree_width', 'set_width',
|
||||
self.screen.model_name, fields, rpc.CONTEXT)
|
||||
except Exception:
|
||||
except TrytonServerError:
|
||||
pass
|
||||
self.widget_tree.destroy()
|
||||
self.screen = None
|
||||
|
||||
@@ -12,6 +12,7 @@ import tryton.rpc as rpc
|
||||
from tryton.common import DT_FORMAT, DHM_FORMAT, COLORS, node_attributes, \
|
||||
TRYTON_ICON, HM_FORMAT
|
||||
import tryton.common as common
|
||||
from tryton.exceptions import TrytonError
|
||||
from tryton.common.cellrendererbutton import CellRendererButton
|
||||
from tryton.common.cellrendererdate import CellRendererDate
|
||||
from tryton.common.cellrenderertext import CellRendererText
|
||||
@@ -404,7 +405,7 @@ class Date(Char):
|
||||
return False
|
||||
try:
|
||||
date = datetime.date(*time.strptime(text, self.display_format)[:3])
|
||||
except Exception:
|
||||
except ValueError:
|
||||
return False
|
||||
return common.datetime_strftime(date, self.server_format)
|
||||
|
||||
@@ -424,16 +425,7 @@ class Datetime(Date):
|
||||
return ''
|
||||
date = datetime.datetime(*time.strptime(value,
|
||||
self.server_format)[:6])
|
||||
if 'timezone' in rpc.CONTEXT:
|
||||
try:
|
||||
import pytz
|
||||
lzone = pytz.timezone(rpc.CONTEXT['timezone'])
|
||||
szone = pytz.timezone(rpc.TIMEZONE)
|
||||
sdt = szone.localize(date, is_dst=True)
|
||||
ldt = sdt.astimezone(lzone)
|
||||
date = ldt
|
||||
except Exception:
|
||||
pass
|
||||
date = common.timezoned_date(date)
|
||||
return common.datetime_strftime(date, self.display_format)
|
||||
|
||||
def value_from_text(self, record, text):
|
||||
@@ -442,18 +434,9 @@ class Datetime(Date):
|
||||
try:
|
||||
date = datetime.datetime(*time.strptime(text,
|
||||
self.display_format)[:6])
|
||||
except Exception:
|
||||
except ValueError:
|
||||
return False
|
||||
if 'timezone' in rpc.CONTEXT:
|
||||
try:
|
||||
import pytz
|
||||
lzone = pytz.timezone(rpc.CONTEXT['timezone'])
|
||||
szone = pytz.timezone(rpc.TIMEZONE)
|
||||
ldt = lzone.localize(date, is_dst=True)
|
||||
sdt = ldt.astimezone(szone)
|
||||
date = sdt
|
||||
except Exception:
|
||||
pass
|
||||
date = common.timezoned_date(date)
|
||||
return common.datetime_strftime(date, self.server_format)
|
||||
|
||||
|
||||
@@ -486,7 +469,7 @@ class Float(Char):
|
||||
def value_from_text(self, record, text):
|
||||
try:
|
||||
return locale.atof(text)
|
||||
except Exception:
|
||||
except ValueError:
|
||||
return 0.0
|
||||
|
||||
|
||||
@@ -526,7 +509,7 @@ class M2O(Char):
|
||||
context)
|
||||
try:
|
||||
ids = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
ids = common.process_exception(exception, self.window, *args)
|
||||
if not ids:
|
||||
return '???'
|
||||
@@ -553,7 +536,7 @@ class M2O(Char):
|
||||
args = ('model', relation, 'search', dom, 0, None, None, context)
|
||||
try:
|
||||
ids = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
ids = common.process_exception(exception, self.window, *args)
|
||||
if not ids:
|
||||
return False, False
|
||||
@@ -591,7 +574,7 @@ class M2O(Char):
|
||||
context)
|
||||
try:
|
||||
res = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
res = common.process_exception(exception, self.window, *args)
|
||||
if not res:
|
||||
return False, None
|
||||
@@ -664,7 +647,7 @@ class M2M(Char):
|
||||
None, context)
|
||||
try:
|
||||
ids = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
ids = common.process_exception(exception, self.window, *args)
|
||||
if ids is False:
|
||||
return []
|
||||
@@ -684,7 +667,7 @@ class M2M(Char):
|
||||
args = ('model', relation, 'search', domain)
|
||||
try:
|
||||
ids = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
ids = common.process_exception(exception, self.window, *args)
|
||||
if ids is False:
|
||||
return False, None
|
||||
@@ -710,12 +693,12 @@ class Selection(Char):
|
||||
self._domain_cache = {}
|
||||
selection = self.attrs.get('selection', [])[:]
|
||||
if not isinstance(selection, (list, tuple)):
|
||||
args = ('model', self.model_name, selection, rpc.CONTEXT)
|
||||
try:
|
||||
selection = rpc.execute('model',
|
||||
self.model_name, selection, rpc.CONTEXT)
|
||||
selection = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
common.process_exception(exception, self.window)
|
||||
selection = []
|
||||
selection = (common.process_exception(exception, self.window,
|
||||
args) or [])
|
||||
self.selection = selection[:]
|
||||
if self.attrs.get('sort', True):
|
||||
selection.sort(lambda x, y: cmp(x[1], y[1]))
|
||||
@@ -800,7 +783,7 @@ class Reference(Char):
|
||||
try:
|
||||
selection = rpc.execute('model',
|
||||
model_name, selection, rpc.CONTEXT)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.window)
|
||||
selection = []
|
||||
selection.sort(lambda x, y: cmp(x[1], y[1]))
|
||||
@@ -819,7 +802,7 @@ class Reference(Char):
|
||||
rpc.CONTEXT)
|
||||
try:
|
||||
res = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
res = common.process_exception(exception, self.window,
|
||||
*args)
|
||||
if not res:
|
||||
@@ -913,14 +896,14 @@ class Button(object):
|
||||
self.attrs['name'], ctx)
|
||||
try:
|
||||
rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.window, *args)
|
||||
elif button_type == 'object':
|
||||
args = ('model', self.screen.model_name,
|
||||
self.attrs['name'], [obj_id], ctx)
|
||||
try:
|
||||
rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.window, *args)
|
||||
elif button_type == 'action':
|
||||
action_id = None
|
||||
@@ -928,7 +911,7 @@ class Button(object):
|
||||
int(self.attrs['name']), ctx)
|
||||
try:
|
||||
action_id = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
action_id = common.process_exception(exception,
|
||||
self.window, *args)
|
||||
if action_id:
|
||||
@@ -938,7 +921,7 @@ class Button(object):
|
||||
'ids': [obj_id],
|
||||
}, self.window, context=ctx)
|
||||
else:
|
||||
raise Exception('Unallowed button type')
|
||||
raise TrytonError('Unallowed button type')
|
||||
self.screen.reload(written=True)
|
||||
else:
|
||||
self.screen.display()
|
||||
|
||||
@@ -9,6 +9,7 @@ from form import ViewForm
|
||||
from list import ViewList
|
||||
from graph import ViewGraph
|
||||
#from calendar import ViewCalendar
|
||||
from tryton.exceptions import TrytonError
|
||||
|
||||
PARSERS = {
|
||||
'form': form_gtk.ParserForm,
|
||||
@@ -46,5 +47,5 @@ class WidgetParse(ParserInterface):
|
||||
widget = res
|
||||
break
|
||||
else:
|
||||
raise Exception('Unknow view mode: %s' % node.localName)
|
||||
raise TrytonError('Unknow view mode: %s' % node.localName)
|
||||
return widget
|
||||
@@ -103,7 +103,7 @@ class Calendar(Interface):
|
||||
def _date_get(self, value):
|
||||
try:
|
||||
date = datetime.date(*time.strptime(value, self.format)[:3])
|
||||
except Exception:
|
||||
except ValueError:
|
||||
return False
|
||||
if self.attrs.get('type', 'date') == 'datetime':
|
||||
return datetime_strftime(datetime.datetime.combine(date,
|
||||
@@ -143,7 +143,7 @@ class Calendar(Interface):
|
||||
return ''
|
||||
try:
|
||||
return datetime_strftime(value, self.format)
|
||||
except Exception:
|
||||
except ValueError:
|
||||
return ''
|
||||
|
||||
i = self.liststore.get_iter_root()
|
||||
|
||||
@@ -22,11 +22,11 @@ class Float(Integer):
|
||||
def _value_get(self):
|
||||
try:
|
||||
value1 = locale.atof(self.entry1.get_text())
|
||||
except Exception:
|
||||
except ValueError:
|
||||
value1 = False
|
||||
try:
|
||||
value2 = locale.atof(self.entry2.get_text())
|
||||
except Exception:
|
||||
except ValueError:
|
||||
value2 = False
|
||||
return self._get_clause(value1, value2)
|
||||
|
||||
@@ -60,12 +60,12 @@ class Float(Integer):
|
||||
value = widget.get_text()
|
||||
position = widget.get_position()
|
||||
new_value = value[:position] + new_text + value[position:]
|
||||
if new_value == '-':
|
||||
return
|
||||
try:
|
||||
if new_value == '-':
|
||||
return
|
||||
if len(str(int(locale.atof(new_value)))) > self.digits[0]:
|
||||
widget.stop_emission('insert-text')
|
||||
except Exception:
|
||||
except ValueError:
|
||||
widget.stop_emission('insert-text')
|
||||
|
||||
|
||||
@@ -74,11 +74,11 @@ class Numeric(Float):
|
||||
def _value_get(self):
|
||||
try:
|
||||
value1 = Decimal(str(locale.atof(self.entry1.get_text())))
|
||||
except Exception:
|
||||
except ValueError:
|
||||
value1 = False
|
||||
try:
|
||||
value2 = Decimal(str(locale.atof(self.entry2.get_text())))
|
||||
except Exception:
|
||||
except ValueError:
|
||||
value2 = False
|
||||
res = self._get_clause(value1, value2)
|
||||
return res
|
||||
|
||||
@@ -67,11 +67,11 @@ class Integer(Interface):
|
||||
def _value_get(self):
|
||||
try:
|
||||
value1 = locale.atoi(self.entry1.get_text())
|
||||
except Exception:
|
||||
except ValueError:
|
||||
value1 = False
|
||||
try:
|
||||
value2 = locale.atoi(self.entry2.get_text())
|
||||
except Exception:
|
||||
except ValueError:
|
||||
value2 = False
|
||||
return self._get_clause(value1, value2)
|
||||
|
||||
@@ -132,9 +132,9 @@ class Integer(Interface):
|
||||
value = widget.get_text()
|
||||
position = widget.get_position()
|
||||
new_value = value[:position] + new_text + value[position:]
|
||||
if new_value == '-':
|
||||
return
|
||||
try:
|
||||
if new_value == '-':
|
||||
return
|
||||
locale.atoi(new_value)
|
||||
except Exception:
|
||||
except ValueError:
|
||||
widget.stop_emission('insert-text')
|
||||
@@ -6,6 +6,7 @@ from interface import Interface
|
||||
import tryton.rpc as rpc
|
||||
import tryton.common as common
|
||||
import gobject
|
||||
from tryton.exceptions import TrytonServerError
|
||||
|
||||
_ = gettext.gettext
|
||||
|
||||
@@ -47,7 +48,7 @@ class Reference(Interface):
|
||||
self.attrs.get('domain', []),
|
||||
0, None, None, ['rec_name'], rpc.CONTEXT)
|
||||
selection = [(x['id'], x['rec_name']) for x in result]
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, parent)
|
||||
selection = []
|
||||
else:
|
||||
@@ -55,7 +56,7 @@ class Reference(Interface):
|
||||
try:
|
||||
selection = rpc.execute('model',
|
||||
self.attrs['model'], selection, rpc.CONTEXT)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, parent)
|
||||
selection = []
|
||||
selection.sort(lambda x, y: cmp(x[1], y[1]))
|
||||
|
||||
@@ -7,6 +7,7 @@ import tryton.common as common
|
||||
import gobject
|
||||
import gettext
|
||||
from tryton.pyson import PYSONDecoder
|
||||
from tryton.exceptions import TrytonServerError
|
||||
|
||||
_ = gettext.gettext
|
||||
|
||||
@@ -50,7 +51,7 @@ class Selection(Interface):
|
||||
'search_read', domain, 0, None, None,
|
||||
['rec_name'], rpc.CONTEXT)
|
||||
selection = [(x['id'], x['rec_name']) for x in result]
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, parent)
|
||||
selection = []
|
||||
else:
|
||||
@@ -58,7 +59,7 @@ class Selection(Interface):
|
||||
try:
|
||||
selection = rpc.execute('model',
|
||||
self.attrs['model'], selection, rpc.CONTEXT)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, parent)
|
||||
selection = []
|
||||
selection.sort(lambda x, y: cmp(x[1], y[1]))
|
||||
|
||||
@@ -5,6 +5,7 @@ import gobject
|
||||
import gettext
|
||||
import tryton.common as common
|
||||
import tryton.rpc as rpc
|
||||
from tryton.exceptions import TrytonServerError
|
||||
import types
|
||||
from tryton.config import TRYTON_ICON
|
||||
import csv
|
||||
@@ -239,7 +240,7 @@ class WinExport(object):
|
||||
args = ('model', model, 'fields_get', None, rpc.CONTEXT)
|
||||
try:
|
||||
return rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
return common.process_exception(exception, self.parent, *args)
|
||||
|
||||
def on_row_expanded(self, treeview, iter, path):
|
||||
@@ -277,7 +278,7 @@ class WinExport(object):
|
||||
[('resource', '=', self.model)], 0, None, None, rpc.CONTEXT)
|
||||
try:
|
||||
export_ids = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
export_ids = common.process_exception(exception, self.parent,
|
||||
*args)
|
||||
if not export_ids:
|
||||
@@ -285,7 +286,7 @@ class WinExport(object):
|
||||
args = ('model', 'ir.export', 'read', export_ids, None, rpc.CONTEXT)
|
||||
try:
|
||||
exports = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
exports = common.process_exception(exception, self.parent, *args)
|
||||
if not exports:
|
||||
return
|
||||
@@ -294,7 +295,7 @@ class WinExport(object):
|
||||
rpc.CONTEXT)
|
||||
try:
|
||||
lines = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
lines = common.process_exception(exception, self.parent, *args)
|
||||
if not lines:
|
||||
return
|
||||
@@ -327,7 +328,7 @@ class WinExport(object):
|
||||
}, rpc.CONTEXT)
|
||||
try:
|
||||
new_id = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
new_ids = common.process_exception(exception, self.dialog, *args)
|
||||
if not new_id:
|
||||
return
|
||||
@@ -348,7 +349,7 @@ class WinExport(object):
|
||||
args = ('model', 'ir.export', 'delete', export_id, rpc.CONTEXT)
|
||||
try:
|
||||
rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
if not common.process_exception(exception, self.dialog, *args):
|
||||
return
|
||||
for i in range(len(self.predef_model)):
|
||||
@@ -434,7 +435,7 @@ class WinExport(object):
|
||||
common.message(_('%d records saved!') % len(result),
|
||||
self.parent)
|
||||
return True
|
||||
except Exception, exception:
|
||||
except IOError, exception:
|
||||
common.warning(_("Operation failed!\nError message:\n%s") \
|
||||
% (exception[0],), self.parent, _('Error'))
|
||||
return False
|
||||
@@ -447,7 +448,7 @@ class WinExport(object):
|
||||
try:
|
||||
datas = rpc.execute('model', model,
|
||||
'export_data', ids, fields, ctx)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.dialog)
|
||||
return []
|
||||
return datas
|
||||
@@ -6,6 +6,7 @@ from tryton.config import CONFIG
|
||||
import gtk
|
||||
import pango
|
||||
import gettext
|
||||
from tryton.exceptions import TrytonServerError
|
||||
|
||||
_ = gettext.gettext
|
||||
|
||||
@@ -262,7 +263,7 @@ class WinForm(object):
|
||||
dom = domain
|
||||
ids = rpc.execute('model', self.attrs['relation'], 'search', dom,
|
||||
0, CONFIG['client.limit'], None, context)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.window)
|
||||
return False
|
||||
if len(ids) != 1:
|
||||
|
||||
@@ -7,6 +7,7 @@ import tryton.common as common
|
||||
import tryton.rpc as rpc
|
||||
import csv
|
||||
from tryton.config import TRYTON_ICON, CONFIG
|
||||
from tryton.exceptions import TrytonServerError
|
||||
|
||||
_ = gettext.gettext
|
||||
|
||||
@@ -229,7 +230,7 @@ class WinImport(object):
|
||||
args = ('model', model, 'fields_get', None, rpc.CONTEXT)
|
||||
try:
|
||||
return rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
return common.process_exception(exception, self.dialog, *args)
|
||||
|
||||
def on_row_expanded(self, treeview, iter, path):
|
||||
@@ -256,7 +257,7 @@ class WinImport(object):
|
||||
try:
|
||||
data = csv.reader(open(fname, 'rb'), quotechar=csvdel,
|
||||
delimiter=csvsep)
|
||||
except Exception:
|
||||
except IOError:
|
||||
common.warning(_('Error opening CSV file'), self.dialog,
|
||||
_('Error'))
|
||||
return True
|
||||
@@ -354,7 +355,7 @@ class WinImport(object):
|
||||
try:
|
||||
res = rpc.execute('model', model, 'import_data', fields, datas,
|
||||
rpc.CONTEXT)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.dialog)
|
||||
return False
|
||||
if res[0] >= 0:
|
||||
|
||||
@@ -7,6 +7,7 @@ import tryton.rpc as rpc
|
||||
import tryton.common as common
|
||||
from tryton.gui.window.view_form.screen import Screen
|
||||
from tryton.gui import Main
|
||||
from tryton.exceptions import TrytonServerError
|
||||
|
||||
|
||||
class Wizard(SignalEvent):
|
||||
@@ -53,7 +54,7 @@ class Wizard(SignalEvent):
|
||||
args = ('wizard', action, 'create', rpc.CONTEXT)
|
||||
try:
|
||||
self.wiz_id = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
self.wiz_id = common.process_exception(exception, self.window, *args)
|
||||
if not self.wiz_id:
|
||||
return
|
||||
@@ -72,7 +73,7 @@ class Wizard(SignalEvent):
|
||||
self.window)
|
||||
try:
|
||||
res = rpcprogress.run()
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
common.process_exception(exception, self.window)
|
||||
break
|
||||
if not res:
|
||||
@@ -134,7 +135,7 @@ class Wizard(SignalEvent):
|
||||
rpc.CONTEXT)
|
||||
#XXX to remove when company displayed in status bar
|
||||
rpc.context_reload()
|
||||
except Exception:
|
||||
except TrytonServerError:
|
||||
pass
|
||||
Main.get_main()._win_del(self.widget)
|
||||
|
||||
|
||||
+1
-1
@@ -90,7 +90,7 @@ class FileServer(IPCServer):
|
||||
for path in to_remove.copy():
|
||||
try:
|
||||
os.remove(path)
|
||||
except Exception:
|
||||
except OSError:
|
||||
continue
|
||||
to_remove.remove(path)
|
||||
time.sleep(1)
|
||||
|
||||
@@ -23,18 +23,15 @@ if os.path.isdir(PLUGINS_PATH):
|
||||
try:
|
||||
module = imp.load_module(module, *imp.find_module(module, [PLUGINS_PATH]))
|
||||
MODULES.append(module)
|
||||
except Exception, exception:
|
||||
except ImportError, exception:
|
||||
continue
|
||||
|
||||
def execute(datas, parent):
|
||||
result = {}
|
||||
|
||||
for module in MODULES:
|
||||
try:
|
||||
for name, func in module.get_plugins(datas['model']):
|
||||
result[name] = func
|
||||
except Exception, exception:
|
||||
continue
|
||||
for name, func in module.get_plugins(datas['model']):
|
||||
result[name] = func
|
||||
if not result:
|
||||
common.message(_('No available plugin for this resource!'), parent)
|
||||
return False
|
||||
|
||||
+16
-14
@@ -19,6 +19,8 @@ except ImportError:
|
||||
import sha
|
||||
import os
|
||||
|
||||
from tryton.exceptions import TrytonError, TrytonServerError
|
||||
|
||||
DNS_CACHE = {}
|
||||
MAX_SIZE = 999999999
|
||||
MAX_LENGHT = len(str(MAX_SIZE))
|
||||
@@ -68,7 +70,7 @@ class PySocket:
|
||||
socket.SOCK_STREAM)
|
||||
self.sock.settimeout(CONNECT_TIMEOUT)
|
||||
self.sock.connect((host, int(port)))
|
||||
except Exception:
|
||||
except socket.error:
|
||||
self.sock = None
|
||||
if self.sock is None:
|
||||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
@@ -83,7 +85,7 @@ class PySocket:
|
||||
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
|
||||
sock.settimeout(CONNECT_TIMEOUT)
|
||||
sock.connect((host, int(port)))
|
||||
except Exception:
|
||||
except socket.error:
|
||||
sock = None
|
||||
if sock is None:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
@@ -95,7 +97,7 @@ class PySocket:
|
||||
elif hasattr(socket, 'ssl'):
|
||||
ssl_sock = socket.ssl(sock)
|
||||
self.ssl = True
|
||||
except Exception:
|
||||
except socket.error:
|
||||
pass
|
||||
self.sock.settimeout(TIMEOUT)
|
||||
fingerprint = None
|
||||
@@ -108,7 +110,7 @@ class PySocket:
|
||||
self.ssl_sock = socket.ssl(self.sock, certfile=self.ca_certs)
|
||||
try:
|
||||
peercert = self.ssl_sock.getpeercert(True)
|
||||
except Exception:
|
||||
except socket.error:
|
||||
peercert = None
|
||||
def format_hash(value):
|
||||
return reduce(lambda x, (i, y): x + y.upper() +
|
||||
@@ -128,7 +130,7 @@ class PySocket:
|
||||
if key in self.fingerprints:
|
||||
if self.fingerprints[key] != fingerprint:
|
||||
self.disconnect()
|
||||
raise Exception('BadFingerprint')
|
||||
raise TrytonError('BadFingerprint')
|
||||
elif fingerprint:
|
||||
self.fingerprints[key] = fingerprint
|
||||
|
||||
@@ -145,10 +147,10 @@ class PySocket:
|
||||
sock.sock_shutdown(shutdown_value)
|
||||
else:
|
||||
sock.shutdown(shutdown_value)
|
||||
except Exception:
|
||||
except socket.error:
|
||||
pass
|
||||
sock.close()
|
||||
except Exception:
|
||||
except socket.error:
|
||||
pass
|
||||
self.sock = None
|
||||
self.ssl = False
|
||||
@@ -182,7 +184,7 @@ class PySocket:
|
||||
while totalsent < size:
|
||||
sent = self.ssl_sock.write(msg[totalsent:])
|
||||
if sent == 0:
|
||||
raise RuntimeError, "socket connection broken"
|
||||
raise RuntimeError("socket connection broken")
|
||||
totalsent = totalsent + sent
|
||||
else:
|
||||
self.sock.sendall(msg)
|
||||
@@ -198,18 +200,18 @@ class PySocket:
|
||||
else:
|
||||
chunk = self.sock.recv(chunk_size)
|
||||
if chunk == '':
|
||||
raise RuntimeError, "socket connection broken"
|
||||
raise RuntimeError("socket connection broken")
|
||||
L.append(chunk)
|
||||
size_remaining -= len(chunk)
|
||||
if ' ' in chunk:
|
||||
break
|
||||
if size_remaining < 0:
|
||||
raise RuntimeError, "socket connection broken"
|
||||
raise RuntimeError("socket connection broken")
|
||||
buf += ''.join(L)
|
||||
size, msg = buf.split(' ', 1)
|
||||
size = int(size)
|
||||
if size > MAX_SIZE:
|
||||
raise RuntimeError, "socket connection broken"
|
||||
raise RuntimeError("socket connection broken")
|
||||
while len(msg) < 2:
|
||||
chunk_size = min(size + 2, 4096)
|
||||
if self.ssl:
|
||||
@@ -217,7 +219,7 @@ class PySocket:
|
||||
else:
|
||||
msg += self.sock.recv(chunk_size)
|
||||
if msg == '':
|
||||
raise RuntimeError, "socket connection broken"
|
||||
raise RuntimeError("socket connection broken")
|
||||
exception = msg[0] != "0"
|
||||
gzip_p = msg[1] != "0"
|
||||
L = [msg[2:]]
|
||||
@@ -229,7 +231,7 @@ class PySocket:
|
||||
else:
|
||||
chunk = self.sock.recv(chunk_size)
|
||||
if chunk == '':
|
||||
raise RuntimeError, "socket connection broken"
|
||||
raise RuntimeError("socket connection broken")
|
||||
L.append(chunk)
|
||||
size_remaining -= len(chunk)
|
||||
msg = ''.join(L)
|
||||
@@ -248,6 +250,6 @@ class PySocket:
|
||||
unpickler.find_global = checkfunction
|
||||
res = unpickler.load()
|
||||
if exception:
|
||||
raise Exception(*(list(res[0]) + [res[1]]))
|
||||
raise TrytonServerError(*(list(res[0]) + [res[1]]))
|
||||
else:
|
||||
return res[0]
|
||||
+39
-42
@@ -8,6 +8,7 @@ from threading import Semaphore
|
||||
from tryton.fingerprints import Fingerprints
|
||||
from tryton.config import get_config_dir
|
||||
from tryton.ipc import Server as IPCServer
|
||||
from tryton.exceptions import TrytonError, TrytonServerError
|
||||
|
||||
_SOCK = None
|
||||
_USER = None
|
||||
@@ -37,7 +38,7 @@ def db_list(host, port):
|
||||
logging.getLogger('rpc.request').info(repr(args))
|
||||
try:
|
||||
_SOCK.send(args)
|
||||
except Exception, exception:
|
||||
except socket.error, exception:
|
||||
if exception[0] == 32:
|
||||
_SOCK.reconnect()
|
||||
_SOCK.send(args)
|
||||
@@ -49,7 +50,7 @@ def db_list(host, port):
|
||||
_SEMAPHORE.release()
|
||||
logging.getLogger('rpc.result').debug(repr(res))
|
||||
return res
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
if exception[0] == 'AccessDenied':
|
||||
raise
|
||||
else:
|
||||
@@ -60,32 +61,29 @@ def db_exec(host, port, method, *args):
|
||||
global _SOCK, SECURE
|
||||
_SEMAPHORE.acquire()
|
||||
try:
|
||||
if _SOCK and (_SOCK.hostname != host or _SOCK.port != port):
|
||||
_SOCK.disconnect()
|
||||
if _SOCK is None:
|
||||
_SOCK= pysocket.PySocket(fingerprints=Fingerprints(),
|
||||
ca_certs=_CA_CERTS)
|
||||
if not _SOCK.connected:
|
||||
_SOCK.connect(host, port)
|
||||
args = (None, None, None, 'common', 'db', method) + args
|
||||
logging.getLogger('rpc.request').info(repr(args))
|
||||
try:
|
||||
if _SOCK and (_SOCK.hostname != host or _SOCK.port != port):
|
||||
_SOCK.disconnect()
|
||||
if _SOCK is None:
|
||||
_SOCK= pysocket.PySocket(fingerprints=Fingerprints(),
|
||||
ca_certs=_CA_CERTS)
|
||||
if not _SOCK.connected:
|
||||
_SOCK.connect(host, port)
|
||||
args = (None, None, None, 'common', 'db', method) + args
|
||||
logging.getLogger('rpc.request').info(repr(args))
|
||||
try:
|
||||
_SOCK.send(args)
|
||||
except socket.error, exception:
|
||||
if exception[0] == 32:
|
||||
_SOCK.reconnect()
|
||||
_SOCK.send(args)
|
||||
except Exception, exception:
|
||||
if exception[0] == 32:
|
||||
_SOCK.reconnect()
|
||||
_SOCK.send(args)
|
||||
else:
|
||||
raise
|
||||
res = _SOCK.receive()
|
||||
SECURE = _SOCK.ssl
|
||||
finally:
|
||||
_SEMAPHORE.release()
|
||||
logging.getLogger('rpc.result').debug(repr(res))
|
||||
return res
|
||||
except Exception:
|
||||
raise
|
||||
else:
|
||||
raise
|
||||
res = _SOCK.receive()
|
||||
SECURE = _SOCK.ssl
|
||||
finally:
|
||||
_SEMAPHORE.release()
|
||||
logging.getLogger('rpc.result').debug(repr(res))
|
||||
return res
|
||||
|
||||
def server_version(host, port):
|
||||
global _SOCK, SECURE
|
||||
@@ -103,7 +101,7 @@ def server_version(host, port):
|
||||
logging.getLogger('rpc.request').info(repr(args))
|
||||
try:
|
||||
_SOCK.send(args)
|
||||
except Exception, exception:
|
||||
except socket.error, exception:
|
||||
if exception[0] == 32:
|
||||
_SOCK.reconnect()
|
||||
_SOCK.send(args)
|
||||
@@ -115,7 +113,7 @@ def server_version(host, port):
|
||||
_SEMAPHORE.release()
|
||||
logging.getLogger('rpc.result').debug(repr(res))
|
||||
return res
|
||||
except Exception:
|
||||
except TrytonServerError:
|
||||
logging.getLogger('rpc.result').debug(repr(None))
|
||||
return None
|
||||
|
||||
@@ -165,19 +163,18 @@ def logout():
|
||||
if IPCServer.instance:
|
||||
IPCServer.instance.stop()
|
||||
if _SOCK and _USER:
|
||||
_SEMAPHORE.acquire()
|
||||
try:
|
||||
_SEMAPHORE.acquire()
|
||||
try:
|
||||
args = (_DATABASE, _USER, _SESSION, 'common', 'db', 'logout')
|
||||
logging.getLogger('rpc.request').info(repr(args))
|
||||
_SOCK.sock.settimeout(pysocket.CONNECT_TIMEOUT)
|
||||
_SOCK.send(args)
|
||||
res = _SOCK.receive()
|
||||
logging.getLogger('rpc.result').debug(repr(res))
|
||||
finally:
|
||||
_SEMAPHORE.release()
|
||||
except Exception:
|
||||
args = (_DATABASE, _USER, _SESSION, 'common', 'db', 'logout')
|
||||
logging.getLogger('rpc.request').info(repr(args))
|
||||
_SOCK.sock.settimeout(pysocket.CONNECT_TIMEOUT)
|
||||
_SOCK.send(args)
|
||||
res = _SOCK.receive()
|
||||
logging.getLogger('rpc.result').debug(repr(res))
|
||||
except socket.error:
|
||||
pass
|
||||
finally:
|
||||
_SEMAPHORE.release()
|
||||
_SOCK.disconnect()
|
||||
_SOCK = None
|
||||
_USER = None
|
||||
@@ -191,7 +188,7 @@ def context_reload():
|
||||
global CONTEXT, TIMEZONE
|
||||
try:
|
||||
context = execute('model', 'res.user', 'get_preferences', True, {})
|
||||
except Exception:
|
||||
except TrytonServerError:
|
||||
return
|
||||
CONTEXT = {}
|
||||
for i in context:
|
||||
@@ -200,13 +197,13 @@ def context_reload():
|
||||
if i == 'timezone':
|
||||
try:
|
||||
TIMEZONE = execute('common', None, 'timezone_get')
|
||||
except Exception:
|
||||
except TrytonServerError:
|
||||
pass
|
||||
|
||||
def _execute(blocking, *args):
|
||||
global _SOCK, _DATABASE, _USER, _SESSION
|
||||
if not _SOCK or not _SOCK.connected:
|
||||
raise Exception('NotLogged')
|
||||
raise TrytonError('NotLogged')
|
||||
logging.getLogger('rpc.request').info(repr((args)))
|
||||
key = False
|
||||
if len(args) >= 6 and args[1] == 'fields_view_get':
|
||||
|
||||
+1
-1
@@ -177,7 +177,7 @@ def setlang(lang=None, locale_dict=None):
|
||||
os.environ['LC_MESSAGES'] = lang2 + '.' + encoding
|
||||
os.environ['LANG'] = lang + '.' + encoding
|
||||
locale.setlocale(locale.LC_ALL, str(lang2 + '.' + encoding))
|
||||
except Exception:
|
||||
except locale.Error:
|
||||
logging.getLogger('translate').info(
|
||||
_('Unable to set locale %s') % lang2 + '.' + encoding)
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ from tryton.gui.window.view_form.screen import Screen
|
||||
import os
|
||||
import pango
|
||||
from tryton.config import CONFIG
|
||||
from tryton.exceptions import TrytonServerError
|
||||
|
||||
_ = gettext.gettext
|
||||
|
||||
@@ -134,7 +135,7 @@ class Dialog(object):
|
||||
rpc.execute('model', 'ir.action.wizard_size', 'set_size',
|
||||
self.action, self.screen.model_name, width, height,
|
||||
rpc.CONTEXT)
|
||||
except Exception:
|
||||
except TrytonServerError:
|
||||
pass
|
||||
|
||||
if res < len(self.states) and res >= 0:
|
||||
@@ -177,7 +178,7 @@ class Wizard(object):
|
||||
args = ('wizard', action, 'create', rpc.CONTEXT)
|
||||
try:
|
||||
wiz_id = rpc.execute(*args)
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
wiz_id = common.process_exception(exception, parent, *args)
|
||||
if not wiz_id:
|
||||
return
|
||||
@@ -193,7 +194,7 @@ class Wizard(object):
|
||||
try:
|
||||
res = rpcprogress.run()
|
||||
exception = None
|
||||
except Exception, exception:
|
||||
except TrytonServerError, exception:
|
||||
if common.process_exception(exception, parent):
|
||||
continue
|
||||
else:
|
||||
@@ -257,5 +258,5 @@ class Wizard(object):
|
||||
rpc.execute('wizard', action, 'delete', wiz_id, rpc.CONTEXT)
|
||||
#XXX to remove when company displayed in status bar
|
||||
rpc.context_reload()
|
||||
except Exception:
|
||||
except TrytonServerError:
|
||||
pass
|
||||
Reference in new issue
Block a user