Commit a5221e81 authored by Rafael Monnerat's avatar Rafael Monnerat

Initial import of recipe used to create one mysql database.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33817 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 98f92d7f
Changelog
=========
1.0 (2010-03-17)
----------------
- Initial version
[Rafael Monnerat]
Introduction
============
This recipe generates a new database on a mysql server.
Example
=======
You can use it with a part like this::
[default-database]
recipe = erp5.recipe.mysqldatabase
mysql_database_name = somename
mysql_user = root
mysql_password =
mysql_superuser = root
mysql_superpassword =
Options
=======
mysql_database_name
Mysql Database name.
mysql_host
Hostname which is running your mysql server. By Default uses localhost.
(Optional).
mysql_port
Port Number which is running your mysql server. By Default uses 3306.
(Optional).
mysql_user
User of new database, used to grant privilegies on the new database.
mysql_password
User's Password of new database, used to grant privilegies on the new
database.
mysql_superuser
User of mysql used to connect to mysql server to create the database.
mysql_superpassword
Password of user defined at mysql_superuser.
from setuptools import setup, find_packages
name = "erp5.recipe.mysqldatabase"
version = '1.0'
def read(name):
return open(name).read()
long_description=( read('README.txt')
+ '\n' +
read('CHANGES.txt')
)
setup(
name = name,
version = version,
author = "Nexedi",
author_email = "info@nexedi.com",
description = "ZC Buildout recipe for create a mysql database",
long_description=long_description,
license = "ZPL 2.1",
keywords = "zope2 buildout",
url='http://www.erp5.org/HowToUseBuildout',
classifiers=[
"License :: OSI Approved :: Zope Public License",
"Framework :: Buildout",
"Framework :: Zope2",
],
packages = find_packages('src'),
package_dir = {'': 'src'},
install_requires = ['zc.recipe.egg', ],
namespace_packages = ['erp5', 'erp5.recipe'],
entry_points = {'zc.buildout': ['default = %s:Recipe' % name]},
)
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
# Copyright (c) 2006-2008 Zope Corporation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import os
import logging
import zc.buildout
class Recipe(object):
def __init__(self, buildout, name, options):
self.buildout, self.options, self.name = buildout, options, name
self.logger=logging.getLogger(self.name)
options['location'] = os.path.join(
buildout['buildout']['parts-directory'],
self.name,
)
options.setdefault('mysql_host', 'localhost')
options.setdefault('mysql_port', '3306')
def install(self):
options = self.options
location = options['location']
try:
import MySQLdb
except ImportError:
raise ImportError('To be able to create database MySQLdb is required'
' Install system wide or use software generated python')
database_name, user, password, port, host\
= \
options.get('mysql_database_name'), \
options.get('mysql_user'), \
options.get('mysql_password'), \
options.get('mysql_port'), \
options.get('mysql_host')
if not (database_name and user):
raise zc.buildout.UserError('database_name and 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' % database_name)
privileges = ['GRANT ALL PRIVILEGES ON %s.* TO %s' % (
database_name, user)]
if host:
privileges.append('@%s' % host)
if password:
privileges.append(' IDENTIFIED BY "%s"' % password)
cursor.execute(''.join(privileges))
connection.commit()
connection.close()
return location
update = install
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