[Erp5-report] r31829 jerome - in /erp5/trunk/utils: erp5.recipe.createsite/ erp5.recipe.cre...

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Jan 19 17:39:08 CET 2010


Author: jerome
Date: Tue Jan 19 17:39:07 2010
New Revision: 31829

URL: http://svn.erp5.org?rev=31829&view=rev
Log:
- add packages for erp5.recipe.testrunner, erp5.recipe.genbt5list and erp5.recipe.createsite
- removes erp5.recipe that is now completly splitted in erp5.recipe.*


Added:
    erp5/trunk/utils/erp5.recipe.createsite/
    erp5/trunk/utils/erp5.recipe.createsite/CHANGES.txt   (with props)
    erp5/trunk/utils/erp5.recipe.createsite/README.txt   (with props)
    erp5/trunk/utils/erp5.recipe.createsite/setup.py
    erp5/trunk/utils/erp5.recipe.createsite/src/
    erp5/trunk/utils/erp5.recipe.createsite/src/erp5/
    erp5/trunk/utils/erp5.recipe.createsite/src/erp5/__init__.py
    erp5/trunk/utils/erp5.recipe.createsite/src/erp5/recipe/
    erp5/trunk/utils/erp5.recipe.createsite/src/erp5/recipe/__init__.py
    erp5/trunk/utils/erp5.recipe.createsite/src/erp5/recipe/createsite/
    erp5/trunk/utils/erp5.recipe.createsite/src/erp5/recipe/createsite/__init__.py
    erp5/trunk/utils/erp5.recipe.createsite/src/erp5/recipe/createsite/create_erp5_instance.py
    erp5/trunk/utils/erp5.recipe.genbt5list/CHANGES.txt   (with props)
    erp5/trunk/utils/erp5.recipe.genbt5list/README.txt   (with props)
    erp5/trunk/utils/erp5.recipe.genbt5list/setup.py
    erp5/trunk/utils/erp5.recipe.genbt5list/src/
    erp5/trunk/utils/erp5.recipe.genbt5list/src/erp5/
    erp5/trunk/utils/erp5.recipe.genbt5list/src/erp5/__init__.py
    erp5/trunk/utils/erp5.recipe.genbt5list/src/erp5/recipe/
    erp5/trunk/utils/erp5.recipe.genbt5list/src/erp5/recipe/__init__.py
    erp5/trunk/utils/erp5.recipe.genbt5list/src/erp5/recipe/genbt5list/
    erp5/trunk/utils/erp5.recipe.genbt5list/src/erp5/recipe/genbt5list/__init__.py
    erp5/trunk/utils/erp5.recipe.testrunner/   (props changed)
      - copied from r31828, erp5/trunk/utils/erp5.recipe.run_unit_test/
    erp5/trunk/utils/erp5.recipe.testrunner/CHANGES.txt   (with props)
    erp5/trunk/utils/erp5.recipe.testrunner/README.txt   (with props)
    erp5/trunk/utils/erp5.recipe.testrunner/setup.py
    erp5/trunk/utils/erp5.recipe.testrunner/src/
    erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/
    erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/__init__.py
    erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/recipe/
    erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/recipe/__init__.py
    erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/recipe/testrunner/
    erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/recipe/testrunner/__init__.py
Removed:
    erp5/trunk/utils/erp5.recipe/
    erp5/trunk/utils/erp5.recipe.run_unit_test/

Added: erp5/trunk/utils/erp5.recipe.createsite/CHANGES.txt
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.createsite/CHANGES.txt?rev=31829&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.createsite/CHANGES.txt (added)
+++ erp5/trunk/utils/erp5.recipe.createsite/CHANGES.txt [utf8] Tue Jan 19 17:39:07 2010
@@ -1,0 +1,8 @@
+Changelog
+=========
+
+1.0 (2010-01-19)
+----------------
+
+- Initial version that creates a site and installs business templates
+  [Jérome]

Propchange: erp5/trunk/utils/erp5.recipe.createsite/CHANGES.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: erp5/trunk/utils/erp5.recipe.createsite/README.txt
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.createsite/README.txt?rev=31829&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.createsite/README.txt (added)
+++ erp5/trunk/utils/erp5.recipe.createsite/README.txt [utf8] Tue Jan 19 17:39:07 2010
@@ -1,0 +1,41 @@
+Introduction
+============
+
+This recipe creates an ERP5 site and installs business templates.
+
+
+Example
+=======
+
+You can use it with a part like this::
+
+  [createsite]
+  recipe = erp5.recipe.createsite
+  portal_id = erp5
+  control-script = ${erp5_instance:control-script}
+  user = admin:admin
+  bt5-path = ${download_bt5:location}
+  bt5 =
+    erp5_base
+    erp5_pdm
+    erp5_trade
+
+
+Options
+=======
+
+portal_id
+  The ID of the portal
+
+control-script
+  Name of the control script, exported by a part using erp5.recipe.zope2instance
+
+user
+  User to create, in user:password format
+
+bt5-path
+  Path where to search for business templates
+
+bt5
+  List of business templates to install
+

Propchange: erp5/trunk/utils/erp5.recipe.createsite/README.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: erp5/trunk/utils/erp5.recipe.createsite/setup.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.createsite/setup.py?rev=31829&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.createsite/setup.py (added)
+++ erp5/trunk/utils/erp5.recipe.createsite/setup.py [utf8] Tue Jan 19 17:39:07 2010
@@ -1,0 +1,38 @@
+from setuptools import setup, find_packages
+
+name = "erp5.recipe.createsite"
+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 at nexedi.com",
+    description = "ZC Buildout recipe for creating an ERP5 site with"\
+                  " installed business templates",
+    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'),
+    include_package_data = True,
+    zip_safe=False,
+    package_dir = {'': 'src'},
+    install_requires = ['zc.recipe.egg', ],
+    namespace_packages = ['erp5', 'erp5.recipe'],
+    entry_points = {'zc.buildout': ['default = %s:Recipe' % name]},
+    )

Added: erp5/trunk/utils/erp5.recipe.createsite/src/erp5/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.createsite/src/erp5/__init__.py?rev=31829&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.createsite/src/erp5/__init__.py (added)
+++ erp5/trunk/utils/erp5.recipe.createsite/src/erp5/__init__.py [utf8] Tue Jan 19 17:39:07 2010
@@ -1,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__)

Added: erp5/trunk/utils/erp5.recipe.createsite/src/erp5/recipe/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.createsite/src/erp5/recipe/__init__.py?rev=31829&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.createsite/src/erp5/recipe/__init__.py (added)
+++ erp5/trunk/utils/erp5.recipe.createsite/src/erp5/recipe/__init__.py [utf8] Tue Jan 19 17:39:07 2010
@@ -1,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__)

Added: erp5/trunk/utils/erp5.recipe.createsite/src/erp5/recipe/createsite/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.createsite/src/erp5/recipe/createsite/__init__.py?rev=31829&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.createsite/src/erp5/recipe/createsite/__init__.py (added)
+++ erp5/trunk/utils/erp5.recipe.createsite/src/erp5/recipe/createsite/__init__.py [utf8] Tue Jan 19 17:39:07 2010
@@ -1,0 +1,79 @@
+# -*- 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, re, shutil, tempfile, urllib2, urlparse
+import setuptools.archive_util
+
+class Recipe:
+    '''Recipe to create an ERP5 site using zopectl run
+    '''
+
+    def __init__(self, buildout, name, options):
+        self.buildout, self.name, self.options = buildout, name, options
+        if not options.get('control-script'):
+            # Guess the name of the zope control script by looking at the section using
+            # zope2instance recipe
+            for k, v in self.buildout.items():
+                if v.get('recipe') in ('plone.recipe.zope2instance',
+                                       'erp5.recipe.zope2instance'):
+                    instance_script = v.get('control-script')
+                    options['control-script'] = instance_script or k
+                    options['instance-location'] = v['location']
+            assert 'control-script' in options, 'Unable to find a zope2 instance'
+
+        options['bin-directory'] = buildout['buildout']['bin-directory']
+
+    def install(self):
+        options = self.options
+        zeo_ctl = options.get('zeo-control-script', None)
+        if zeo_ctl:
+          zeo_ctl_path = os.path.join(options['bin-directory'], zeo_ctl)
+          assert os.spawnl(
+              os.P_WAIT, zeo_ctl_path, *[zeo_ctl_path, 'start']) == 0
+        zopectl_path = os.path.join(options['bin-directory'],
+                                    options['control-script'])
+        script_name = os.path.join(os.path.dirname(__file__),
+                                  'create_erp5_instance.py')
+        argv = [zopectl_path, 'run', script_name]
+
+        if options.get('portal_id'):
+            argv.extend(['--portal_id', options['portal_id']])
+        if options.get('erp5_sql_connection_string'):
+            argv.extend(['--erp5_sql_connection_string',
+                        options['erp5_sql_connection_string']])
+
+        if options.get('cmf_activity_sql_connection_string'):
+            argv.extend(['--cmf_activity_sql_connection_string',
+                 options['cmf_activity_sql_connection_string']])
+        if options.get('erp5_catalog_storage'):
+            argv.extend(['--erp5_catalog_storage',
+                        options['erp5_catalog_storage']])
+        if options.get('user'):
+            # XXX read rom zope2instance section ?
+            argv.extend(['--initial-user',
+                        options['user']])
+
+        argv.extend(['--bt5-path',
+                    os.path.join(options['bt5-path'])])
+        argv.extend([bt for bt in options.get('bt5', '').split('\n') if bt])
+
+        assert os.spawnl(
+              os.P_WAIT, zopectl_path, *argv ) == 0
+        
+        return []
+
+    def update(self):
+        pass
+    

Added: erp5/trunk/utils/erp5.recipe.createsite/src/erp5/recipe/createsite/create_erp5_instance.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.createsite/src/erp5/recipe/createsite/create_erp5_instance.py?rev=31829&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.createsite/src/erp5/recipe/createsite/create_erp5_instance.py (added)
+++ erp5/trunk/utils/erp5.recipe.createsite/src/erp5/recipe/createsite/create_erp5_instance.py [utf8] Tue Jan 19 17:39:07 2010
@@ -1,0 +1,113 @@
+# Create an ERP5 instance 
+# usage: zopectl run create_erp5_instance [options] [business templates]
+
+import os
+from optparse import OptionParser
+from urllib import unquote
+
+from Testing.makerequest import makerequest
+from AccessControl.SecurityManagement import newSecurityManager
+
+parser = OptionParser()
+parser.add_option("-p", "--portal_id", dest="portal_id",
+                  help="The ID of the Portal", default="erp5")
+parser.add_option("--erp5_sql_connection_string",
+                  dest="erp5_sql_connection_string",
+                  help="Connection String used for ZSQLCatalog "
+                       "(use %20 for space)",
+                  default="test test")
+parser.add_option("--cmf_activity_sql_connection_string",
+                  dest="cmf_activity_sql_connection_string",
+                  help="Connection String used for CMFActivity")
+parser.add_option("--erp5_catalog_storage",
+                  dest="erp5_catalog_storage",
+                  help="Business Template for Catalog Storage")
+parser.add_option("-u", "--initial-user",
+                  dest="user_and_pass",
+                  help="User and Password, separated by :",
+                  default="zope:zope")
+parser.add_option("--bt5-path",
+                  dest="bt5_path",
+                  help="Path to folder containing business templates",
+                  default="bt5")
+
+(options, args) = parser.parse_args()
+
+# cmf activity connection string defaults to zsqlcatalog's one
+if not options.cmf_activity_sql_connection_string:
+  options.cmf_activity_sql_connection_string = \
+            options.erp5_sql_connection_string
+
+# connection strings have to contain a space, for conveniance, this space can
+# be replaced by %20 character.
+options.erp5_sql_connection_string =\
+      unquote(options.erp5_sql_connection_string)
+options.cmf_activity_sql_connection_string =\
+      unquote(options.cmf_activity_sql_connection_string)
+
+username, password = options.user_and_pass.split(':')
+
+try:
+  import transaction
+except ImportError:
+  class Transaction:
+    def commit(self):
+      return get_transaction().commit()
+  transaction = Transaction()
+
+app = makerequest(app)
+
+user = app.acl_users.getUserById(username)
+if user is None:
+  uf = app.acl_users
+  uf._doAddUser(username, password, ['Manager', 'Member', 'Assignee',
+                                     'Assignor', 'Author'], [])
+  user = uf.getUserById(username)
+
+newSecurityManager(None, user.__of__(app.acl_users))
+
+portal = getattr(app, options.portal_id, None)
+if portal is None:
+  print 'Adding ERP5 site %s' % options.portal_id
+  app.manage_addProduct['ERP5'].manage_addERP5Site(
+              id=options.portal_id,
+              erp5_sql_connection_string=options.erp5_sql_connection_string,
+              cmf_activity_sql_connection_string=\
+                        options.cmf_activity_sql_connection_string,
+              erp5_catalog_storage='erp5_mysql_innodb_catalog')
+
+  transaction.commit()
+  portal = app._getOb(options.portal_id)
+
+# set preference for erp5_subversion
+from App.config import getConfiguration
+default_site_preference = portal.portal_preferences.default_site_preference
+instance_home = getConfiguration().instancehome
+default_site_preference.edit(
+  preferred_subversion_working_copy_list=['%s/bt5/' % instance_home])
+if default_site_preference.getPreferenceState() == 'disabled':
+  default_site_preference.enable()
+
+# install our business templates
+bt5_list = []
+for arg in args:
+  bt_path = os.path.join(options.bt5_path, arg)
+  installed_bt = portal.portal_templates.getInstalledBusinessTemplate(arg)
+  if installed_bt is not None:
+    # XXX this way works only for extracted business template, not for
+    # *.bt5 packed business template.
+    version = file('%s/bt/version' % bt_path).read().strip()
+    revision = file('%s/bt/revision' % bt_path).read().strip()
+    if version == installed_bt.getVersion() and \
+       revision == installed_bt.getRevision():
+      print 'Skipping bt %s' % bt_path
+      continue
+    else:
+      print 'Updating bt %s' % bt_path
+  else:
+    print 'Installing bt %s' % bt_path
+  bt = portal.portal_templates.download(bt_path)
+  bt.install(force=True)
+  transaction.commit()
+
+transaction.commit()

Added: erp5/trunk/utils/erp5.recipe.genbt5list/CHANGES.txt
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.genbt5list/CHANGES.txt?rev=31829&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.genbt5list/CHANGES.txt (added)
+++ erp5/trunk/utils/erp5.recipe.genbt5list/CHANGES.txt [utf8] Tue Jan 19 17:39:07 2010
@@ -1,0 +1,8 @@
+Changelog
+=========
+
+1.0 (2010-01-19)
+----------------
+
+- Initial version that generates a bt5 repository
+  [Jérome]

Propchange: erp5/trunk/utils/erp5.recipe.genbt5list/CHANGES.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: erp5/trunk/utils/erp5.recipe.genbt5list/README.txt
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.genbt5list/README.txt?rev=31829&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.genbt5list/README.txt (added)
+++ erp5/trunk/utils/erp5.recipe.genbt5list/README.txt [utf8] Tue Jan 19 17:39:07 2010
@@ -1,0 +1,35 @@
+Introduction
+============
+
+This recipe generates a business template repository, that you can access from
+your ERP5 site using file:// scheme.
+This is handy to update your site with different business templates than the
+one from http://www.erp5.org/dists/
+
+
+Example
+=======
+
+You can use it with a part like this::
+
+  [bt5list]
+  recipe = erp5.recipe.genbt5list
+  bt5_base = ${download_bt5:location}
+  bt5_urls = ${download_bt5:urls}
+  genbt5list = ${products-erp5:location}/ERP5/bin/genbt5list
+
+
+Options
+=======
+
+bt5_base
+  Path of a folder containing business templates in extended format.
+
+bt5_urls
+  List of URLs of business template. From this list of URLs only the names of
+  the business template will be used, this recipe assumes that another recipe
+  (typically infrae.subversion) gets the business templates from svn.
+
+genbt5list
+  Path of the genbt5list, under bin folder in ERP5 product
+

Propchange: erp5/trunk/utils/erp5.recipe.genbt5list/README.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: erp5/trunk/utils/erp5.recipe.genbt5list/setup.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.genbt5list/setup.py?rev=31829&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.genbt5list/setup.py (added)
+++ erp5/trunk/utils/erp5.recipe.genbt5list/setup.py [utf8] Tue Jan 19 17:39:07 2010
@@ -1,0 +1,35 @@
+from setuptools import setup, find_packages
+
+name = "erp5.recipe.genbt5list"
+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 at nexedi.com",
+    description = "ZC Buildout recipe for creating a repository of business"\
+                  " templates",
+    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'},
+    namespace_packages = ['erp5', 'erp5.recipe'],
+    entry_points = {'zc.buildout': ['default = %s:Recipe' % name]},
+    )

Added: erp5/trunk/utils/erp5.recipe.genbt5list/src/erp5/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.genbt5list/src/erp5/__init__.py?rev=31829&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.genbt5list/src/erp5/__init__.py (added)
+++ erp5/trunk/utils/erp5.recipe.genbt5list/src/erp5/__init__.py [utf8] Tue Jan 19 17:39:07 2010
@@ -1,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__)

Added: erp5/trunk/utils/erp5.recipe.genbt5list/src/erp5/recipe/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.genbt5list/src/erp5/recipe/__init__.py?rev=31829&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.genbt5list/src/erp5/recipe/__init__.py (added)
+++ erp5/trunk/utils/erp5.recipe.genbt5list/src/erp5/recipe/__init__.py [utf8] Tue Jan 19 17:39:07 2010
@@ -1,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__)

Added: erp5/trunk/utils/erp5.recipe.genbt5list/src/erp5/recipe/genbt5list/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.genbt5list/src/erp5/recipe/genbt5list/__init__.py?rev=31829&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.genbt5list/src/erp5/recipe/genbt5list/__init__.py (added)
+++ erp5/trunk/utils/erp5.recipe.genbt5list/src/erp5/recipe/genbt5list/__init__.py [utf8] Tue Jan 19 17:39:07 2010
@@ -1,0 +1,71 @@
+# -*- 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 shutil
+
+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.setdefault('executable',
+            self.buildout['buildout']['executable'])
+
+        options['location'] = os.path.join(
+            buildout['buildout']['parts-directory'],
+            self.name,
+            )
+
+
+    def install(self):
+        options = self.options
+        location = options['location']
+
+        if os.path.exists(location):
+            shutil.rmtree(location)
+        os.mkdir(location)
+
+        base = options['bt5_base']
+        os.chdir(base)
+        for url in options.get('bt5_urls', '').splitlines():
+            if not url:
+                continue
+            url_base, bt5 = url.split()
+            if bt5[-1] == '/':
+                bt5 = bt5[:-1]
+            self.logger.info("Creating bt5 %s" % bt5)
+            # TODO: use python tarfile module
+            assert os.spawnlp(
+                      os.P_WAIT, 'tar', 'tar',
+                      '--exclude=.svn', '-czf',
+                      os.path.join(location, '%s.bt5' % bt5), bt5) == 0
+
+        os.chdir(location)
+        self.logger.info("Generating bt5list")
+        assert os.spawnl(
+                  os.P_WAIT, os.path.normpath(options['executable']),
+                  zc.buildout.easy_install._safe_arg(options['executable']),
+                  zc.buildout.easy_install._safe_arg(options['genbt5list']),
+                ) == 0
+        
+        return location
+
+    update = install
+

Propchange: erp5/trunk/utils/erp5.recipe.testrunner/
------------------------------------------------------------------------------
    svn:mergeinfo = 

Added: erp5/trunk/utils/erp5.recipe.testrunner/CHANGES.txt
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.testrunner/CHANGES.txt?rev=31829&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.testrunner/CHANGES.txt (added)
+++ erp5/trunk/utils/erp5.recipe.testrunner/CHANGES.txt [utf8] Tue Jan 19 17:39:07 2010
@@ -1,0 +1,8 @@
+Changelog
+=========
+
+1.0 (2010-01-19)
+----------------
+
+- Initial version that generates a test runner
+  [Jérome]

Propchange: erp5/trunk/utils/erp5.recipe.testrunner/CHANGES.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: erp5/trunk/utils/erp5.recipe.testrunner/README.txt
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.testrunner/README.txt?rev=31829&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.testrunner/README.txt (added)
+++ erp5/trunk/utils/erp5.recipe.testrunner/README.txt [utf8] Tue Jan 19 17:39:07 2010
@@ -1,0 +1,36 @@
+Introduction
+============
+
+This recipe generates a test runner for ERP5
+
+
+Example
+=======
+
+You can use it with a part like this::
+
+  [bt5list]
+  recipe = erp5.recipe.testrunner
+  zope2-location = ${zope2:location}
+  products = ${erp5_instance:products}
+             ${zope2:location}/lib/python/Products/
+  eggs = ${erp5_instance:eggs}
+  bt5_path = ${download_bt5:location}
+
+
+Options
+=======
+
+zope2-location
+  Location of a zope2 installation, similar to this option in zope2instance
+  recipe.
+
+products
+  Products to use in the generated scripts
+
+eggs
+  Eggs to use in the generated scripts
+  
+bt5_path
+  Paths containing business templates to be installed
+

Propchange: erp5/trunk/utils/erp5.recipe.testrunner/README.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: erp5/trunk/utils/erp5.recipe.testrunner/setup.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.testrunner/setup.py?rev=31829&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.testrunner/setup.py (added)
+++ erp5/trunk/utils/erp5.recipe.testrunner/setup.py [utf8] Tue Jan 19 17:39:07 2010
@@ -1,0 +1,36 @@
+from setuptools import setup, find_packages
+
+name = "erp5.recipe.testrunner"
+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 at nexedi.com",
+    description = "ZC Buildout recipe for creating a test runner compatible"\
+                  " with ERP5 buildout",
+    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]},
+    )

Added: erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/__init__.py?rev=31829&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/__init__.py (added)
+++ erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/__init__.py [utf8] Tue Jan 19 17:39:07 2010
@@ -1,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__)

Added: erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/recipe/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/recipe/__init__.py?rev=31829&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/recipe/__init__.py (added)
+++ erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/recipe/__init__.py [utf8] Tue Jan 19 17:39:07 2010
@@ -1,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__)

Added: 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=31829&view=auto
==============================================================================
--- erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/recipe/testrunner/__init__.py (added)
+++ erp5/trunk/utils/erp5.recipe.testrunner/src/erp5/recipe/testrunner/__init__.py [utf8] Tue Jan 19 17:39:07 2010
@@ -1,0 +1,176 @@
+# -*- 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, re, shutil, sys, glob
+import zc.buildout
+import zc.recipe.egg
+
+class Recipe:
+    '''Creates a runUnitTest aware of eggs and custom paths used in this
+    buildout.
+    '''
+    name = 'runUnitTest'
+
+    def __init__(self, buildout, name, options):
+        self.buildout, self.options, self.name = buildout, options, name
+        
+        self.location = options['location'] = os.path.join(
+            buildout['buildout']['parts-directory'],
+            self.name,
+            )
+        try:
+            self.instance_home = (options.get('instance-home') or
+                                  # backward compatibility...
+                                  self.buildout['erp5_instance']['location'])
+        except KeyError:
+            raise RuntimeError('please specify location of ERP5 instance '
+                               '(e.g.: "instance-home = '
+                               '${erp5_instance:location}")')
+        # force the generation of a single script...
+        scriptName = options.get('control-script', name).strip()
+        options['scripts'] = 'runUnitTest=' + scriptName
+        # ...manually defined by our entry point
+        options['entry-points'] = '''
+          runUnitTest=Products.ERP5Type.tests.runUnitTest:main
+        '''
+        # initialize the recipe that will actually generate the script
+        self.egg = zc.recipe.egg.Egg(buildout, 'recipes', options)
+
+    def install(self):
+        options = self.options
+        location = self.location
+
+        extra_paths = self.egg.extra_paths
+        # insert software-home into extra_paths, calculating from
+        # zope2-location if necessary
+        software_home = options.get('software-home')
+        zope2_location = options.get('zope2-location')
+        if zope2_location and not software_home:
+            software_home = os.path.join(zope2_location, 'lib', 'python')
+        if software_home:
+            extra_paths.insert(0, software_home)
+            zope_scripts = None
+        else:
+            # if no software_home can be found, assume software_home is already
+            # reachable by eggs or extra-paths (the generated script will check
+            # if that is the case), but then the skeletons on
+            # ERP5Type/tests/skel2.12 will need to find the Zope startup
+            # scripts (zopectl, runzope), which will likely be in this buildout
+            # bin directory.
+            zope_scripts = options.get('zope2-scripts', 
+                                       options['bin-directory'])
+
+        init = init_template % dict(name=self.name,
+                                    zope_scripts=zope_scripts)
+
+        products = options.get('products', '')
+        test_products = options.get('test-products', products)
+        # Add Products to sys.path under the Products namespace
+        for product in products.splitlines():
+          if product:
+            init += add_product_path_template % dict(product_path=product)
+        # add test directories of selected products (defaulting to all 
+        # products) to sys.path since that's where runUnitTest actually looks
+        # for them
+        for product in test_products.splitlines():
+          if product:
+            extra_paths.extend(
+                product_test_path for product_test_path in
+                glob.glob(os.path.join(product, '*', 'tests'))
+            )
+            #for product_test_path in glob.glob(
+            #                            os.path.join(product, '*', 'tests')):
+            #  init += add_sys_path_template % dict(
+            #                            sys_path=product_test_path)
+              
+        for bt5_path in options.get('bt5_path', '').splitlines():
+          bt5_path = bt5_path.strip()
+          if bt5_path:
+            init += add_bt5_path_template % dict(bt5_path=bt5_path)
+
+        # add parts/<instance>/tests to path because runUnitTest will
+        # guess it wrong
+        local_tests_path = os.path.join(self.instance_home, 'tests')
+        init += add_sys_path_template % dict(sys_path=local_tests_path)
+
+        # runUnitTest works in our parts directory, which will contain
+        # custom_zodb.py
+        if not os.path.exists(location):
+          os.mkdir(location)
+        init += set_env_and_chdir_template % dict(location=location)
+
+        # framework.py requires a Products directory, so create it here
+        # This is temporary, as we're getting rid of "framework.py"
+        products_dir = os.path.join(location, 'Products')
+        if not os.path.exists(products_dir):
+           os.mkdir(products_dir)
+
+        self.options['initialization'] = init
+        # reassign just to be on the safe side...
+        self.egg.extra_paths = extra_paths
+
+        # generate the script according to our configuration
+        self.egg.install()
+
+        return [location]
+
+    update = install
+
+init_template = '''
+import os
+from os.path import dirname, abspath
+
+# derive SOFTWARE_HOME from import location of Zope2
+try:
+  import Zope2
+except ImportError:
+  print >> sys.stderr, ("Zope2 could not be found. In the %(name)r part of the "
+                        "buildout configuration, please specify either "
+                        "software-home or zope2-location, or add Zope2 to the "
+                        "list of eggs.")
+  raise
+else:
+  os.environ['SOFTWARE_HOME'] = abspath(dirname(dirname(Zope2.__file__)))
+
+# if under Zope 2.12, we need the location of the Zope2 startup scripts for the
+# substitutions in the skel2.12 directory
+ZOPE_SCRIPTS = %(zope_scripts)r
+if ZOPE_SCRIPTS is not None:
+  os.environ['ZOPE_SCRIPTS'] = ZOPE_SCRIPTS 
+
+import Products
+
+# Testing needs to be imported, otherwise framework.py will guess it from
+# sys.path, which can be a zipped egg
+import Testing
+'''
+
+add_product_path_template = '''
+Products.__path__.append(%(product_path)r)'''
+
+add_sys_path_template = '''
+sys.path.append(%(sys_path)r)'''
+
+add_bt5_path_template = '''
+sys.argv.insert(1, %(bt5_path)r)
+sys.argv.insert(1, '--bt5_path')'''
+
+set_env_and_chdir_template = '''
+
+# execute framework.py, like in zope testcase
+os.environ['INSTANCE_HOME'] = %(location)r
+os.chdir(%(location)r)
+'''
+




More information about the Erp5-report mailing list