Page MenuHomec4science

dbtest.in
No OneTemporary

File Metadata

Created
Tue, Aug 20, 15:14

dbtest.in

#!@PYTHON@
## -*- mode: python; coding: utf-8; -*-
##
## $Id$
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006 CERN.
##
## CDS Invenio 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.
##
## CDS Invenio 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 CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## fill config variables:
dbhost = "@DBHOST@"
dbname = "@DBNAME@"
dbuser = "@DBUSER@"
dbpass = "@DBPASS@"
## import modules:
try:
import MySQLdb
import sys
import os
except ImportError, e:
print "Error: %s" % e
import sys
sys.exit(1)
## try to connect to the DB server:
try:
db = MySQLdb.connect(host=dbhost, db=dbname, user=dbuser, passwd=dbpass)
except MySQLdb.Error, e:
print """
******************************************************
** DATABASE CONNECTIVITY ERROR %(errcode)d: %(errmsg)s.
******************************************************
** Perhaps you need to set up connection rights? **
** **
** If yes, then please login as MySQL admin (root) **
** user and run the following commands now: **
**
** $ mysql -h %(dbhost)s -u root -p mysql
** mysql> CREATE DATABASE %(dbname)s;
** mysql> GRANT ALL PRIVILEGES ON %(dbname)s.* TO %(dbuser)s@%(webhost)s IDENTIFIED BY '%(dbpass)s';
** mysql> QUIT
**
** After this continue with 'make install' again. **
** **
** (If the problem is not the connection rights, **
** then please inspect the above error message and **
** fix the problem before continuing.) **
******************************************************
""" % {'errcode': e.args[0],
'errmsg': e.args[1],
'dbname': dbname,
'dbhost': dbhost,
'dbuser': dbuser,
'dbpass': dbpass,
'webhost': dbhost == 'localhost' and 'localhost' or os.popen('hostname -f', 'r').read().strip(),
}
sys.exit(1)
## execute test query:
try:
cursor = db.cursor()
cursor.execute("SELECT * FROM collection")
row = cursor.fetchone()
except MySQLdb.Error, e:
print """
******************************************************
** DATABASE QUERY ERROR %(errcode)d: %(errmsg)s.
******************************************************
** Perhaps you need to create the tables? **
** **
** If yes, then please run 'make create-tables' now **
** and continue with the 'make install' afterwards. **
** **
** If not, then please inspect the above error **
** message and fix the problem before continuing. **
******************************************************
""" % {'errcode': e.args[0],
'errmsg': e.args[1],
}
sys.exit(1)
## close connection:
cursor.close()
db.close()

Event Timeline