[Erp5-report] r33357 rafael - /erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/recipe/test...

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Mar 4 06:34:50 CET 2010


Author: rafael
Date: Thu Mar  4 06:34:50 2010
New Revision: 33357

URL: http://svn.erp5.org?rev=33357&view=rev
Log:
Import the idea of standalone recipe and make possible testrunner create his own database if needed.

Modified:
    erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/recipe/testrunner/__init__.py

Modified: erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/recipe/testrunner/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/recipe/testrunner/__init__.py?rev=33357&r1=33356&r2=33357&view=diff
==============================================================================
--- erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/recipe/testrunner/__init__.py [utf8] (original)
+++ erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/recipe/testrunner/__init__.py [utf8] Thu Mar  4 06:34:50 2010
@@ -125,6 +125,46 @@
         # generate the script according to our configuration
         self.egg.install()
 
+        # This was copied from erp5.recipe.standalone
+        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()
+    
         return [location]
 
     update = install




More information about the Erp5-report mailing list