[Modeling-cvs] ProjectModeling/Modeling/DatabaseAdaptors/MySQLAdaptorLayer mysql_utils.py,NONE,1.1
Status: Abandoned
Brought to you by:
sbigaret
From: <sbi...@us...> - 2004-01-20 20:26:45
|
Update of /cvsroot/modeling/ProjectModeling/Modeling/DatabaseAdaptors/MySQLAdaptorLayer In directory sc8-pr-cvs1:/tmp/cvs-serv25998/Modeling/DatabaseAdaptors/MySQLAdaptorLayer Added Files: mysql_utils.py Log Message: Forgot to add this file when the fix for bug #857803 was submitted --- NEW FILE: mysql_utils.py --- #----------------------------------------------------------------------------- # # Modeling Framework: an Object-Relational Bridge for python # (c) 2001, 2002, 2003 Sebastien Bigaret # # This file is part of the Modeling Framework. # # The Modeling Framework is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as published # by the Free Software Foundation; either version 2 of the License, or (at # your option) any later version. # # The Modeling Framework is distributed in the hope that it will be # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License along # with the Modeling Framework; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # #----------------------------------------------------------------------------- """ 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,v 1.1 2004/01/20 20:26:42 sbigaret Exp $ """ __version__='$Revision: 1.1 $'[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) |