Commit a1f5b6cf authored by Olivier Sallou's avatar Olivier Sallou
Browse files

Merge pull request #2 from horkko/mysql-connect-py2-3

New MySQL connector for python 2 and 3
parents cc2e2f09 d5befa15
...@@ -8,8 +8,8 @@ import time ...@@ -8,8 +8,8 @@ import time
import logging import logging
import re import re
import fnmatch import fnmatch
import mysql.connector
import MySQLdb from mysql.connector import errorcode
from biomaj.bank import Bank from biomaj.bank import Bank
from biomaj.config import BiomajConfig from biomaj.config import BiomajConfig
...@@ -172,7 +172,7 @@ def main(): ...@@ -172,7 +172,7 @@ def main():
b = Bank(os.path.basename(prop_file).replace('.properties',''),no_log=True) b = Bank(os.path.basename(prop_file).replace('.properties',''),no_log=True)
banks.append(b.name) banks.append(b.name)
#database.url=jdbc\:mysql\://genobdd.genouest.org/biomaj_log # database.url=jdbc\:mysql\://genobdd.genouest.org/biomaj_log
vals = biomajconfig['database.url'].split('/') vals = biomajconfig['database.url'].split('/')
urllen = len(vals) urllen = len(vals)
db_name = vals[urllen-1] db_name = vals[urllen-1]
...@@ -187,17 +187,27 @@ def main(): ...@@ -187,17 +187,27 @@ def main():
db_password = biomajconfig['database.password'] db_password = biomajconfig['database.password']
if args.password: if args.password:
db_password = args.password db_password = args.password
db = MySQLdb.connect(host=db_host, # your host, usually localhost
user=db_user, # your username try:
passwd=db_password, # your password cnx = mysql.connector.connect(host=db_host, database=db_name,
db=db_name) # name of the data base user=db_user, password=db_password)
cur = db.cursor() cur = cnx.cursor()
oldbanks = {} oldbanks = {}
cur.execute("SELECT name,idbank from bank") cur.execute("SELECT name,idbank from bank")
for row in cur.fetchall(): for row in cur.fetchall():
oldbanks[row[0]] = { "dbid": row[1], "name": row[0] } oldbanks[row[0]] = { "dbid": row[1], "name": row[0] }
for bank,value in oldbanks.iteritems(): for bank,value in iter(oldbanks.items()):
migrate_bank(cur, value) migrate_bank(cur, value)
except mysql.connector.Error as error:
if error.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Wrong username or password: %s" % error.msg)
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist: %s" % error.msg)
else:
print("Unknown error: %s" % err)
finally:
cnx.close()
if __name__ == '__main__': if __name__ == '__main__':
main() main()
...@@ -11,8 +11,8 @@ config = { ...@@ -11,8 +11,8 @@ config = {
'author_email': 'olivier.sallou@irisa.fr', 'author_email': 'olivier.sallou@irisa.fr',
'version': '3.0.1', 'version': '3.0.1',
'install_requires': ['nose', 'install_requires': ['nose',
'MySQL-python', 'mysql-connector-python-rf',
'pymongo'], 'pymongo'],
'packages': find_packages(), 'packages': find_packages(),
'include_package_data': True, 'include_package_data': True,
'scripts': ['bin/biomaj-migrate.py'], 'scripts': ['bin/biomaj-migrate.py'],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment