diff --git a/tryton/common/common.py b/tryton/common/common.py
index a8710d8fc6..5d72349a69 100644
--- a/tryton/common/common.py
+++ b/tryton/common/common.py
@@ -17,10 +17,20 @@ import traceback
import tryton.rpc as rpc
import locale
import socket
+from tryton.version import VERSION
_ = gettext.gettext
def refresh_dblist(db_widget, host, port, dbtoload=None):
+ '''
+ Return the number of database available
+ or None if it is impossible to connect
+ or -1 if the server version doesn't macth the client version
+ '''
+ version = rpc.server_version(host, port)
+ if version:
+ if version.split('.')[:2] != VERSION.split('.')[:2]:
+ return -1
if not dbtoload:
dbtoload = CONFIG['login.db']
index = 0
diff --git a/tryton/gui/main.py b/tryton/gui/main.py
index 44b8de1f3c..81fdda23ae 100644
--- a/tryton/gui/main.py
+++ b/tryton/gui/main.py
@@ -8,7 +8,6 @@ from gtk import glade
import tryton.rpc as rpc
from tryton.config import CONFIG, GLADE, TRYTON_ICON, PIXMAPS_DIR, DATA_DIR
import tryton.common as common
-from tryton.version import VERSION
from tryton.action import Action
from tryton.gui.window import Window
from tryton.gui.window.preference import Preference
@@ -773,12 +772,16 @@ class Main(object):
def _choose_db_select(self, title=_("Backup a database")):
def refreshlist(widget, db_widget, label, host, port):
res = common.refresh_dblist(db_widget, host, port)
- if res == -1:
- label.set_label('' + \
- _('Could not connect to server!') + '')
+ if res is None or res == -1:
+ if res is None:
+ label.set_label('' + _('Could not connect to server!') +\
+ '')
+ else:
+ label.set_label('' + \
+ _('Incompatible version of the server!') + '')
db_widget.hide()
label.show()
- elif res==0:
+ elif res == 0:
label.set_label('' + \
_('No database found, you must create one!') + '')
db_widget.hide()
diff --git a/tryton/gui/window/dblogin.py b/tryton/gui/window/dblogin.py
index 779f88babd..ce3c3448c5 100644
--- a/tryton/gui/window/dblogin.py
+++ b/tryton/gui/window/dblogin.py
@@ -99,13 +99,18 @@ class DBLogin(object):
@staticmethod
def refreshlist(widget, db_widget, label, host, port, butconnect=None):
res = common.refresh_dblist(db_widget, host, port)
- if res is None:
- label.set_label(''+_('Could not connect to server!')+'')
+ if res is None or res == -1:
+ if res is None:
+ label.set_label('' + _('Could not connect to server!') + \
+ '')
+ else:
+ label.set_label('' + \
+ _('Incompatible version of the server!') + '')
db_widget.hide()
label.show()
if butconnect:
butconnect.set_sensitive(False)
- elif res==0:
+ elif res == 0:
label.set_label('' + \
_('No database found, you must create one!') + '')
db_widget.hide()
diff --git a/tryton/rpc.py b/tryton/rpc.py
index 9a2b0f198f..eb90bcde14 100644
--- a/tryton/rpc.py
+++ b/tryton/rpc.py
@@ -62,6 +62,33 @@ def db_exec(host, port, method, *args):
except:
raise
+def server_version(host, port):
+ global _SOCK, SECURE
+ _SEMAPHORE.acquire()
+ try:
+ try:
+ if _SOCK and (_SOCK.hostname != host or _SOCK.port != port):
+ _SOCK.disconnect()
+ if _SOCK is None:
+ _SOCK = pysocket.PySocket()
+ if not _SOCK.connected:
+ _SOCK.connect(host, port)
+ try:
+ _SOCK.send(('common', 'version'))
+ except Exception, exception:
+ if exception[0] == 32:
+ _SOCK.reconnect()
+ _SOCK.send(('db', 'list'))
+ else:
+ raise
+ res = _SOCK.receive()
+ SECURE = _SOCK.ssl
+ finally:
+ _SEMAPHORE.release()
+ return res
+ except:
+ return None
+
def login(username, password, host, port, database):
global _SOCK, _USER, _USERNAME, _SESSION, _DATABASE, _VIEW_CACHE, SECURE
_VIEW_CACHE = {}