# -*- coding: iso-8859-1 -*-
#-----------------------------------------------------------------------------
# Modeling Framework: an Object-Relational Bridge for python
#
# Copyright (c) 2001-2004 Sbastien Bigaret <sbigaret@users.sourceforge.net>
# All rights reserved.
#
# This file is part of the Modeling Framework.
#
# This code is distributed under a "3-clause BSD"-style license;
# see the LICENSE file for details.
#-----------------------------------------------------------------------------
"""
MySQL Adaptor Layer's utils
Central point for determining MySQL specifics, like the version of the
mysql server in use.
CVS information
$Id: mysql_utils.py 932 2004-07-20 06:21:57Z sbigaret $
"""
__version__='$Revision: 932 $'[11:-2]
import os
import MySQLdb
def mysql_server_version():
"""
Returns the version of the mysql server currently in use. If the environment
variable MDL_MYSQL_SERVER_VERSION is set, it returns the information it
contains, otherwise it calls MySQLdb.get_client_info().
Acceptable values for ``MDL_MYSQL_SERVER_VERSION`` are e.g: 3.23, 4,
4.0.11a-gamma.
Return value:
A 4-values tuple: (VERSION, PATCH_LEVEL, SUBLEVEL, EXTRA_VERSION)
E.g. (4,0,11,'a-gamma')
Note that the env. is checked before MySQLdb.get_client_info() is called,
because on some installation the latter reports a different version than the
server's one (this happens e.g. when the client python adaptor is linked to
an older mysql-library); in such cases, the env.variable allows the user to
explicitly set the version of the mysql db-server.
"""
s = os.environ.get('MDL_MYSQL_SERVER_VERSION','')
if not s:
s=MySQLdb.get_client_info()
v_list = s.split('.', 3)
if len(v_list)==1: v_list+=['0', '']
if len(v_list)==2: v_list+=['']
version = int(v_list[0])
patch_level = int(v_list[1])
s = v_list[2]
i=0
for i in range(len(s)):
if not s[i].isdigit():
break
if s[i].isdigit(): i+=1
if i == 0:
sublevel = 0
else:
sublevel = int(s[:i])
extra_version = s[i:]
return (version, patch_level, sublevel, extra_version)
|