Commit 42c9fd6c authored by Rafael Monnerat's avatar Rafael Monnerat

Use erp5.recipe.mysqldatabase to create the database.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33821 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6c96e8de
......@@ -32,6 +32,7 @@ setup(
namespace_packages = ['erp5', 'erp5.recipe'],
install_requires = [
'plone.recipe.zope2instance',
'erp5.recipe.mysqldatabase',
],
zip_safe=False,
entry_points = {'zc.buildout': ['default = %s:Recipe' % name]},
......
......@@ -17,6 +17,7 @@ import os, sys
from string import Template
import zc.buildout
import plone.recipe.zope2instance
from erp5.recipe.mysqldatabase import Recipe as mysqlrecipe
class WithMinusTemplate(Template):
idpattern = '[_a-z][-_a-z0-9]*'
......@@ -58,43 +59,9 @@ class Recipe(plone.recipe.zope2instance.Recipe):
ws_locations = [d.location for d in ws]
if options.get('mysql_create_database', 'false').lower() == 'true':
try:
import MySQLdb
except ImportError:
raise ImportError('To be able to create database MySQLdb is required'
' Install system wide or use software generated python')
mysql_database_name, mysql_user, mysql_password, mysql_port, mysql_host\
= \
options.get('mysql_database_name'), \
options.get('mysql_user'), \
options.get('mysql_password'), \
options.get('mysql_port'), \
options.get('mysql_host')
if not (mysql_database_name and mysql_user):
raise zc.buildout.UserError('mysql_database_name and mysql_user are '
'required to create database and grant privileges')
connection = MySQLdb.connect(
host = self.options.get('mysql_host'),
port = int(self.options.get('mysql_port')),
user = self.options.get('mysql_superuser'),
passwd = self.options.get('mysql_superpassword'),
)
connection.autocommit(0)
cursor = connection.cursor()
cursor.execute(
'CREATE DATABASE IF NOT EXISTS %s DEFAULT CHARACTER SET utf8 COLLATE '
'utf8_unicode_ci' % mysql_database_name)
privileges = ['GRANT ALL PRIVILEGES ON %s.* TO %s' % (
mysql_database_name, mysql_user)]
if mysql_host:
privileges.append('@%s' % mysql_host)
if mysql_password:
privileges.append(' IDENTIFIED BY "%s"' % mysql_password)
cursor.execute(''.join(privileges))
connection.commit()
connection.close()
# Use mysqldatabase recipe for Create the mysql database.
mysqlrecipe(self.buildout, self.name, self.options).install()
# What follows is a bit of a hack because the instance-setup mechanism
# is a bit monolithic. We'll run mkzopeinstance and then we'll
......
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