diff --git a/buildout/local-eggs/erp5.recipe.mysqldatabase/CHANGES.txt b/buildout/local-eggs/erp5.recipe.mysqldatabase/CHANGES.txt new file mode 100644 index 0000000000000000000000000000000000000000..aa585d69143228a4de206dee9f85cef80c9a6af3 --- /dev/null +++ b/buildout/local-eggs/erp5.recipe.mysqldatabase/CHANGES.txt @@ -0,0 +1,9 @@ +Changelog +========= + +1.0 (2010-03-17) +---------------- + +- Initial version + [Rafael Monnerat] + diff --git a/buildout/local-eggs/erp5.recipe.mysqldatabase/README.txt b/buildout/local-eggs/erp5.recipe.mysqldatabase/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..ceb064e2c5c443acb0d8826d4cbbd556c140745e --- /dev/null +++ b/buildout/local-eggs/erp5.recipe.mysqldatabase/README.txt @@ -0,0 +1,46 @@ +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. + diff --git a/buildout/local-eggs/erp5.recipe.mysqldatabase/setup.py b/buildout/local-eggs/erp5.recipe.mysqldatabase/setup.py new file mode 100644 index 0000000000000000000000000000000000000000..45793ddb9f2a2cc8fba521b5b2a023b232a2f5ed --- /dev/null +++ b/buildout/local-eggs/erp5.recipe.mysqldatabase/setup.py @@ -0,0 +1,34 @@ +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]}, + ) diff --git a/buildout/local-eggs/erp5.recipe.mysqldatabase/src/erp5/__init__.py b/buildout/local-eggs/erp5.recipe.mysqldatabase/src/erp5/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..839098485f2a0be21e45d2189d1cca290cfb1d1a --- /dev/null +++ b/buildout/local-eggs/erp5.recipe.mysqldatabase/src/erp5/__init__.py @@ -0,0 +1,6 @@ +# 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__) diff --git a/buildout/local-eggs/erp5.recipe.mysqldatabase/src/erp5/recipe/__init__.py b/buildout/local-eggs/erp5.recipe.mysqldatabase/src/erp5/recipe/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..839098485f2a0be21e45d2189d1cca290cfb1d1a --- /dev/null +++ b/buildout/local-eggs/erp5.recipe.mysqldatabase/src/erp5/recipe/__init__.py @@ -0,0 +1,6 @@ +# 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__) diff --git a/buildout/local-eggs/erp5.recipe.mysqldatabase/src/erp5/recipe/mysqldatabase/__init__.py b/buildout/local-eggs/erp5.recipe.mysqldatabase/src/erp5/recipe/mysqldatabase/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..9bc5d370dade3db9222199a005e6ea5a712e879d --- /dev/null +++ b/buildout/local-eggs/erp5.recipe.mysqldatabase/src/erp5/recipe/mysqldatabase/__init__.py @@ -0,0 +1,83 @@ +# -*- 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 + +