Check server version compatibility
This commit is contained in:
1 parent
fa77be2752
commit
9623e92bfd
4 files changed
+53
-8
No files matched your search
@@ -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
|
||||
|
||||
+8
-5
@@ -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('<b>' + \
|
||||
_('Could not connect to server!') + '</b>')
|
||||
if res is None or res == -1:
|
||||
if res is None:
|
||||
label.set_label('<b>' + _('Could not connect to server!') +\
|
||||
'</b>')
|
||||
else:
|
||||
label.set_label('<b>' + \
|
||||
_('Incompatible version of the server!') + '</b>')
|
||||
db_widget.hide()
|
||||
label.show()
|
||||
elif res==0:
|
||||
elif res == 0:
|
||||
label.set_label('<b>' + \
|
||||
_('No database found, you must create one!') + '</b>')
|
||||
db_widget.hide()
|
||||
|
||||
@@ -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('<b>'+_('Could not connect to server!')+'</b>')
|
||||
if res is None or res == -1:
|
||||
if res is None:
|
||||
label.set_label('<b>' + _('Could not connect to server!') + \
|
||||
'</b>')
|
||||
else:
|
||||
label.set_label('<b>' + \
|
||||
_('Incompatible version of the server!') + '</b>')
|
||||
db_widget.hide()
|
||||
label.show()
|
||||
if butconnect:
|
||||
butconnect.set_sensitive(False)
|
||||
elif res==0:
|
||||
elif res == 0:
|
||||
label.set_label('<b>' + \
|
||||
_('No database found, you must create one!') + '</b>')
|
||||
db_widget.hide()
|
||||
|
||||
@@ -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 = {}
|
||||
|
||||
Reference in new issue
Block a user