Skip to content

Commit

Permalink
Merge pull request #2 from horkko/mysql-connect-py2-3
Browse files Browse the repository at this point in the history
New MySQL connector for python 2 and 3
  • Loading branch information
osallou committed Aug 26, 2015
2 parents cc2e2f0 + d5befa1 commit a1f5b6c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
38 changes: 24 additions & 14 deletions bin/biomaj-migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import logging
import re
import fnmatch

import MySQLdb
import mysql.connector
from mysql.connector import errorcode

from biomaj.bank import Bank
from biomaj.config import BiomajConfig
Expand Down Expand Up @@ -172,7 +172,7 @@ def main():
b = Bank(os.path.basename(prop_file).replace('.properties',''),no_log=True)
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('/')
urllen = len(vals)
db_name = vals[urllen-1]
Expand All @@ -187,17 +187,27 @@ def main():
db_password = biomajconfig['database.password']
if args.password:
db_password = args.password
db = MySQLdb.connect(host=db_host, # your host, usually localhost
user=db_user, # your username
passwd=db_password, # your password
db=db_name) # name of the data base
cur = db.cursor()
oldbanks = {}
cur.execute("SELECT name,idbank from bank")
for row in cur.fetchall():
oldbanks[row[0]] = { "dbid": row[1], "name": row[0] }
for bank,value in oldbanks.iteritems():
migrate_bank(cur, value)

try:
cnx = mysql.connector.connect(host=db_host, database=db_name,
user=db_user, password=db_password)
cur = cnx.cursor()
oldbanks = {}
cur.execute("SELECT name,idbank from bank")
for row in cur.fetchall():
oldbanks[row[0]] = { "dbid": row[1], "name": row[0] }
for bank,value in iter(oldbanks.items()):
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__':
main()
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
'author_email': 'olivier.sallou@irisa.fr',
'version': '3.0.1',
'install_requires': ['nose',
'MySQL-python',
'pymongo'],
'mysql-connector-python-rf',
'pymongo'],
'packages': find_packages(),
'include_package_data': True,
'scripts': ['bin/biomaj-migrate.py'],
Expand Down

0 comments on commit a1f5b6c

Please sign in to comment.