From 2f4217964714bb83e88efe6175bc7b0d08de6eb1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com>
Date: Wed, 17 Feb 2010 10:26:04 +0000
Subject: [PATCH]  - use plone.recipe.zope2instance directly instead of
 erp5.recipe.zope2instance

New way of creating instances disallows to delete anything and anyway requires
much fine grained control over process so it is better to override full
erp5.recipe.zope2instance instead of reusing it.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32675 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../erp5.recipe.standaloneinstance/setup.py   |  2 +-
 .../recipe/standaloneinstance/__init__.py     | 76 ++++++++++++++++---
 2 files changed, 68 insertions(+), 10 deletions(-)

diff --git a/buildout/recipes/erp5.recipe.standaloneinstance/setup.py b/buildout/recipes/erp5.recipe.standaloneinstance/setup.py
index b1440ebdeb..e246e3a461 100644
--- a/buildout/recipes/erp5.recipe.standaloneinstance/setup.py
+++ b/buildout/recipes/erp5.recipe.standaloneinstance/setup.py
@@ -31,7 +31,7 @@ setup(
     package_dir = {'':'src'},
     namespace_packages = ['erp5', 'erp5.recipe'],
     install_requires = [
-        'erp5.recipe.zope2instance',
+        'plone.recipe.zope2instance',
         'erp5.recipe.createsite',
     ],
     zip_safe=False,
diff --git a/buildout/recipes/erp5.recipe.standaloneinstance/src/erp5/recipe/standaloneinstance/__init__.py b/buildout/recipes/erp5.recipe.standaloneinstance/src/erp5/recipe/standaloneinstance/__init__.py
index 80a0bde4c4..07124dc251 100644
--- a/buildout/recipes/erp5.recipe.standaloneinstance/src/erp5/recipe/standaloneinstance/__init__.py
+++ b/buildout/recipes/erp5.recipe.standaloneinstance/src/erp5/recipe/standaloneinstance/__init__.py
@@ -13,12 +13,13 @@
 #
 ##############################################################################
 
-import os
+import os, sys
+from string import Template
 import zc.buildout
-import erp5.recipe.zope2instance
+import plone.recipe.zope2instance
 import erp5.recipe.createsite
 
-class Recipe(erp5.recipe.zope2instance.Recipe, erp5.recipe.createsite.Recipe):
+class Recipe(plone.recipe.zope2instance.Recipe, erp5.recipe.createsite.Recipe):
   def __init__(self, buildout, name, options):
     standalone_location = options.get('location')
     if not standalone_location:
@@ -48,8 +49,69 @@ class Recipe(erp5.recipe.zope2instance.Recipe, erp5.recipe.createsite.Recipe):
         assert relative_paths == 'false'
 
   def install(self):
-    # initalise zope instance
-    erp5.recipe.zope2instance.Recipe.install(self)
+    # Override erp5.recipe.zope2instance so as to create several
+    # directories used by ERP5.
+    options = self.options
+    location = options['location']
+
+    requirements, ws = self.egg.working_set()
+    ws_locations = [d.location for d in ws]
+
+    # 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
+    # patch the result. A better approach might be to provide independent
+    # instance-creation logic, but this raises lots of issues that
+    # need to be stored out first.
+    if not self.zope2_location:
+      mkzopeinstance = os.path.join(
+        options['bin-directory'], 'mkzopeinstance')
+      if not mkzopeinstance:
+        # EEE
+        return
+
+    else:
+      mkzopeinstance = os.path.join(
+        self.zope2_location, 'bin', 'mkzopeinstance.py')
+      if not os.path.exists(mkzopeinstance):
+        mkzopeinstance = os.path.join(
+          self.zope2_location, 'utilities', 'mkzopeinstance.py')
+      if sys.platform[:3].lower() == "win":
+        mkzopeinstance = '"%s"' % mkzopeinstance
+
+    if not mkzopeinstance:
+      # EEE
+      return
+
+    assert os.spawnl(
+      os.P_WAIT, os.path.normpath(options['executable']),
+      zc.buildout.easy_install._safe_arg(options['executable']),
+      mkzopeinstance, '-d',
+      zc.buildout.easy_install._safe_arg(location),
+      '-u', options['user'],
+      ) == 0
+
+    # patch begin: create several directories
+    for directory in ('Constraint', 'Document', 'PropertySheet', 'tests'):
+      path = os.path.join(location, directory)
+      if not os.path.exists(path):
+        os.mkdir(path)
+    # patch end: create several directories
+
+    # Save the working set:
+    open(os.path.join(location, 'etc', '.eggs'), 'w').write(
+      '\n'.join(ws_locations))
+
+    # Make a new zope.conf based on options in buildout.cfg
+    self.build_zope_conf()
+
+    # Patch extra paths into binaries
+    self.patch_binaries(ws_locations)
+
+    # Install extra scripts
+    self.install_scripts()
+
+    # Add zcml files to package-includes
+    self.build_package_includes()
 
     # initialise ERP5 part
     erp5.recipe.createsite.Recipe.install(self)
@@ -60,9 +122,5 @@ class Recipe(erp5.recipe.zope2instance.Recipe, erp5.recipe.createsite.Recipe):
     # preparation for further fixing (chroot everything inside instance, etc)
     erp5.recipe.zope2instance.Recipe.build_zope_conf(self)
 
-  def _clean_up(self, location):
-    # in new way nothing is deleted
-    return
-
   def update(self):
     return erp5.recipe.zope2instance.Recipe.update(self)
-- 
2.30.9