[Erp5-report] r36146 nicolas - in /erp5/trunk/utils/erp5.recipe.hotreindex: ./ src/ src/erp...
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Jun 9 11:21:51 CEST 2010
Author: nicolas
Date: Wed Jun 9 11:21:51 2010
New Revision: 36146
URL: http://svn.erp5.org?rev=36146&view=rev
Log:
Add recipe to ease catalog migration smoothly (without clearing current one).
It uses Hot Reindex feature through xml-rpc calls.
Added:
erp5/trunk/utils/erp5.recipe.hotreindex/
erp5/trunk/utils/erp5.recipe.hotreindex/CHANGES.txt (with props)
erp5/trunk/utils/erp5.recipe.hotreindex/README.txt (with props)
erp5/trunk/utils/erp5.recipe.hotreindex/setup.py
erp5/trunk/utils/erp5.recipe.hotreindex/src/
erp5/trunk/utils/erp5.recipe.hotreindex/src/erp5/
erp5/trunk/utils/erp5.recipe.hotreindex/src/erp5/__init__.py
erp5/trunk/utils/erp5.recipe.hotreindex/src/erp5/recipe/
erp5/trunk/utils/erp5.recipe.hotreindex/src/erp5/recipe/__init__.py
erp5/trunk/utils/erp5.recipe.hotreindex/src/erp5/recipe/hotreindex/
erp5/trunk/utils/erp5.recipe.hotreindex/src/erp5/recipe/hotreindex/__init__.py
Added: erp5/trunk/utils/erp5.recipe.hotreindex/CHANGES.txt
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.hotreindex/CHANGES.txt?rev=36146&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.hotreindex/CHANGES.txt (added)
+++ erp5/trunk/utils/erp5.recipe.hotreindex/CHANGES.txt [utf8] Wed Jun 9 11:21:51 2010
@@ -1,0 +1,8 @@
+Changelog
+=========
+
+0.1 (2010-06-07)
+----------------
+
+ - intial version
+ [nicolas]
Propchange: erp5/trunk/utils/erp5.recipe.hotreindex/CHANGES.txt
------------------------------------------------------------------------------
svn:eol-style = native
Added: erp5/trunk/utils/erp5.recipe.hotreindex/README.txt
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.hotreindex/README.txt?rev=36146&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.hotreindex/README.txt (added)
+++ erp5/trunk/utils/erp5.recipe.hotreindex/README.txt [utf8] Wed Jun 9 11:21:51 2010
@@ -1,0 +1,22 @@
+Start hot reindexing
+================================================
+
+TODO: implement update
+
+Easy way to update catalog without clearing it
+
+[start-hot-reindex]
+recipe = erp5.recipe.hotreindex
+erp5_sql_connection_string = ${zope-instance:erp5_sql_connection_string}
+current_database_id = ${zope-instance:mysql_database_name}
+current_sql_catalog_id = erp5_mysql_innodb
+new_sql_catalog_id = erp5_mysql_innodb_ng
+new_database_id = ${create-new-database:mysql_database_name}
+current_erp5_sql_connector_id = erp5_sql_connection
+new_erp5_sql_connector_id = erp5_sql_connection_ng
+current_erp5_sql_deferred_connector_id = erp5_sql_deferred_connection
+new_erp5_sql_deferred_connector_id = erp5_sql_deferred_connection_ng
+user = ${zope-instance:user}
+hostname = ${zope-instance:ip-address}
+port = ${zope-instance:http-address}
+portal_id = ${zope-instance:portal_id}
Propchange: erp5/trunk/utils/erp5.recipe.hotreindex/README.txt
------------------------------------------------------------------------------
svn:eol-style = native
Added: erp5/trunk/utils/erp5.recipe.hotreindex/setup.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.hotreindex/setup.py?rev=36146&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.hotreindex/setup.py (added)
+++ erp5/trunk/utils/erp5.recipe.hotreindex/setup.py [utf8] Wed Jun 9 11:21:51 2010
@@ -1,0 +1,39 @@
+# -*- coding: utf-8 -*-
+from setuptools import setup, find_packages
+
+name = "erp5.recipe.hotreindex"
+version = '0.1'
+
+def read(name):
+ return open(name).read()
+
+long_description=(
+ read('README.txt')
+ + '\n' +
+ read('CHANGES.txt')
+ )
+
+setup(
+ name = name,
+ version = version,
+ author = "Nicolas Delaby",
+ author_email = "nicolas at nexedi.com",
+ description = "ZC Buildout recipe to start hot reindexing",
+ long_description=long_description,
+ license = "ZPL 2.1",
+ keywords = "zope2 buildout",
+ classifiers=[
+ "License :: OSI Approved :: Zope Public License",
+ "Framework :: Buildout",
+ "Framework :: Zope2",
+ ],
+ packages = find_packages('src'),
+ include_package_data = True,
+ package_dir = {'':'src'},
+ namespace_packages = ['erp5', 'erp5.recipe'],
+ #install_requires = [
+ #'infrae.subversion',
+ #],
+ zip_safe=False,
+ entry_points = {'zc.buildout': ['default = %s:Recipe' % name]},
+ )
Added: erp5/trunk/utils/erp5.recipe.hotreindex/src/erp5/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.hotreindex/src/erp5/__init__.py?rev=36146&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.hotreindex/src/erp5/__init__.py (added)
+++ erp5/trunk/utils/erp5.recipe.hotreindex/src/erp5/__init__.py [utf8] Wed Jun 9 11:21:51 2010
@@ -1,0 +1,7 @@
+# -*- coding: utf-8 -*-
+# 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__)
Added: erp5/trunk/utils/erp5.recipe.hotreindex/src/erp5/recipe/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.hotreindex/src/erp5/recipe/__init__.py?rev=36146&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.hotreindex/src/erp5/recipe/__init__.py (added)
+++ erp5/trunk/utils/erp5.recipe.hotreindex/src/erp5/recipe/__init__.py [utf8] Wed Jun 9 11:21:51 2010
@@ -1,0 +1,7 @@
+# -*- coding: utf-8 -*-
+# 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__)
Added: erp5/trunk/utils/erp5.recipe.hotreindex/src/erp5/recipe/hotreindex/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.hotreindex/src/erp5/recipe/hotreindex/__init__.py?rev=36146&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.hotreindex/src/erp5/recipe/hotreindex/__init__.py (added)
+++ erp5/trunk/utils/erp5.recipe.hotreindex/src/erp5/recipe/hotreindex/__init__.py [utf8] Wed Jun 9 11:21:51 2010
@@ -1,0 +1,163 @@
+# -*- coding: utf-8 -*-
+# -*- 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 xmlrpclib
+from xmlrpclib import Fault
+#import zc.buildout
+import zc.buildout.easy_install
+import zc.buildout.download
+import zc.recipe.egg
+import subprocess
+
+class Recipe(object):
+
+
+ def __init__(self, buildout, name, options):
+ self.buildout, self.options, self.name = buildout, options, name
+ self.logger = logging.getLogger(self.name)
+ self.egg = zc.recipe.egg.Egg(buildout, options['recipe'], options)
+
+
+ options.setdefault('location', os.path.join(
+ buildout['buildout']['parts-directory'],
+ self.name,
+ ))
+
+ # XML-RPC connection
+ options.setdefault('protocol', 'http')
+ options.setdefault('user', 'zope:zope')
+ options.setdefault('hostname', 'localhost')
+ options.setdefault('port', '8080')
+ options.setdefault('portal_id', 'erp5')
+
+ def _getConnectionString(self):
+ """Return connection string to connect
+ to instance
+ """
+ options = self.options
+ connection_string = '%(protocol)s://%(user)s@%(hostname)'\
+ 's:%(port)s/%(portal_id)s/' % options
+ return connection_string
+
+ def _getConnection(self, connection_string):
+ """Return XML-RPC connected object
+ """
+ connection = xmlrpclib.ServerProxy(connection_string, allow_none=True)
+ return connection
+
+ def _copyPaste(self, folder, old_id, new_id):
+ """Copy paste persistent object and rename it
+ through xml-rpc connection.
+ """
+ # Check first if object does not exists
+ try:
+ getattr(folder, new_id).getId()
+ except Fault:
+ # object does not exists
+ clipboard = folder.manage_copyObjects([old_id], None, None)
+ paste_result = folder.manage_pasteObjects(clipboard, None)
+ copied_id = paste_result[0]['new_id']
+ folder.manage_renameObjects([copied_id], [new_id])
+ else:
+ print 'New object already exists:%r' % new_id
+
+ def install(self):
+ options = self.options
+ location = options['location']
+ if not os.path.exists(location):
+ os.mkdir(location)
+
+ connection = self._getConnection(self._getConnectionString())
+ source_sql_catalog_id = options['current_sql_catalog_id']
+ destination_sql_catalog_id = options['new_sql_catalog_id']
+
+ if connection.portal_catalog.getProperty('default_sql_catalog_id') ==\
+ destination_sql_catalog_id:
+ print 'Destination catalog already configured'
+ return []
+ current_erp5_sql_connector_id = options['current_erp5_sql_connector_id']
+ new_erp5_sql_connector_id = options['new_erp5_sql_connector_id']
+ current_erp5_sql_deferred_connector_id =\
+ options['current_erp5_sql_deferred_connector_id']
+ new_erp5_sql_deferred_connector_id =\
+ options['new_erp5_sql_deferred_connector_id']
+ # copy/paste catalog and rename it with destination_sql_catalog_id
+ self._copyPaste(connection.portal_catalog, source_sql_catalog_id,
+ destination_sql_catalog_id)
+
+ # copy/paste erp5_sql_connector
+ self._copyPaste(connection, current_erp5_sql_connector_id,
+ new_erp5_sql_connector_id)
+ # copy/paste erp5_sql_deferred_connector_id
+ self._copyPaste(connection, current_erp5_sql_deferred_connector_id,
+ new_erp5_sql_deferred_connector_id)
+
+ # update connection_string property of connectors
+ current_database_id = options['current_database_id']
+ new_database_id = options['new_database_id']
+ connection_string = options['erp5_sql_connection_string']
+ connection_string = connection_string.replace(current_database_id,
+ new_database_id)
+ title = new_erp5_sql_connector_id
+ getattr(connection, new_erp5_sql_connector_id).manage_edit(
+ title,
+ connection_string,
+ True, None)
+
+ title = new_erp5_sql_deferred_connector_id
+ getattr(connection, new_erp5_sql_deferred_connector_id).manage_edit(
+ title,
+ connection_string,
+ True, None)
+
+ archive_path = None
+ source_sql_connection_id_list = [connection_tuple[0] for connection_tuple\
+ in connection.portal_catalog.\
+ SQLConnectionIDs()]
+ destination_sql_connection_id_list = []
+ for source_sql_connection_id in source_sql_connection_id_list:
+ if source_sql_connection_id == current_erp5_sql_connector_id:
+ destination_sql_connection_id_list.append(\
+ new_erp5_sql_connector_id)
+ elif source_sql_connection_id == current_erp5_sql_deferred_connector_id:
+ destination_sql_connection_id_list.append(\
+ new_erp5_sql_deferred_connector_id)
+ else:
+ destination_sql_connection_id_list.append(source_sql_connection_id)
+
+ skin_name_dict = dict(connection.portal_skins.getSkinPaths())
+ skin_name_list = skin_name_dict.keys()
+ skin_selection_list = []
+ for skin_name in skin_name_list:
+ skin_selection_list.append(skin_name_dict[skin_name].split(','))
+
+ update_destination_sql_catalog = True
+ # start hot_reindexing
+ connection.portal_catalog.manage_hotReindexAll(source_sql_catalog_id,
+ destination_sql_catalog_id,
+ archive_path,
+ source_sql_connection_id_list,
+ destination_sql_connection_id_list,
+ skin_name_list,
+ skin_selection_list,
+ update_destination_sql_catalog,
+ None, None)
+
+ return []
+
More information about the Erp5-report
mailing list