[Checkins] SVN: z3c.recipe.runscript/trunk/ A recipe that can run a callable in a specified module.

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Jul 31 01:17:29 EDT 2007


Log message for revision 78501:
  A recipe that can run a callable in a specified module.
  

Changed:
  A   z3c.recipe.runscript/trunk/
  A   z3c.recipe.runscript/trunk/AUTHOR.txt
  A   z3c.recipe.runscript/trunk/CHANGES.txt
  A   z3c.recipe.runscript/trunk/README.txt
  A   z3c.recipe.runscript/trunk/bootstrap.py
  A   z3c.recipe.runscript/trunk/buildout.cfg
  A   z3c.recipe.runscript/trunk/setup.py
  A   z3c.recipe.runscript/trunk/src/
  A   z3c.recipe.runscript/trunk/src/z3c/
  A   z3c.recipe.runscript/trunk/src/z3c/__init__.py
  A   z3c.recipe.runscript/trunk/src/z3c/recipe/
  A   z3c.recipe.runscript/trunk/src/z3c/recipe/__init__.py
  A   z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/
  A   z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/README.txt
  A   z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/__init__.py
  A   z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/tests/
  A   z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/tests/__init__.py
  A   z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/tests/fooscripts.py
  A   z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/tests/test_doc.py

-=-
Added: z3c.recipe.runscript/trunk/AUTHOR.txt
===================================================================
--- z3c.recipe.runscript/trunk/AUTHOR.txt	                        (rev 0)
+++ z3c.recipe.runscript/trunk/AUTHOR.txt	2007-07-31 05:17:29 UTC (rev 78501)
@@ -0,0 +1,2 @@
+Stephan Richter (stephan.richter <at> gmail.com)
+


Property changes on: z3c.recipe.runscript/trunk/AUTHOR.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.recipe.runscript/trunk/CHANGES.txt
===================================================================
--- z3c.recipe.runscript/trunk/CHANGES.txt	                        (rev 0)
+++ z3c.recipe.runscript/trunk/CHANGES.txt	2007-07-31 05:17:29 UTC (rev 78501)
@@ -0,0 +1,8 @@
+=======
+CHANGES
+=======
+
+Version 0.1.0 (??/??/2007)
+-------------------------
+
+- Initial Release


Property changes on: z3c.recipe.runscript/trunk/CHANGES.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.recipe.runscript/trunk/README.txt
===================================================================
--- z3c.recipe.runscript/trunk/README.txt	                        (rev 0)
+++ z3c.recipe.runscript/trunk/README.txt	2007-07-31 05:17:29 UTC (rev 78501)
@@ -0,0 +1,2 @@
+This run-script URL allows you to specify an arbitrary script to do the work
+of the recipe.


Property changes on: z3c.recipe.runscript/trunk/README.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.recipe.runscript/trunk/bootstrap.py
===================================================================
--- z3c.recipe.runscript/trunk/bootstrap.py	                        (rev 0)
+++ z3c.recipe.runscript/trunk/bootstrap.py	2007-07-31 05:17:29 UTC (rev 78501)
@@ -0,0 +1,55 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# 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.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id$
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+try:
+    import pkg_resources
+except ImportError:
+    ez = {}
+    exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+                         ).read() in ez
+    ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+    import pkg_resources
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+if sys.platform == 'win32':
+    cmd = '"%s"' % cmd # work around spawn lamosity on windows
+
+ws = pkg_resources.working_set
+assert os.spawnle(
+    os.P_WAIT, sys.executable, sys.executable,
+    '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
+    dict(os.environ,
+         PYTHONPATH=
+         ws.find(pkg_resources.Requirement.parse('setuptools')).location
+         ),
+    ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)


Property changes on: z3c.recipe.runscript/trunk/bootstrap.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: z3c.recipe.runscript/trunk/buildout.cfg
===================================================================
--- z3c.recipe.runscript/trunk/buildout.cfg	                        (rev 0)
+++ z3c.recipe.runscript/trunk/buildout.cfg	2007-07-31 05:17:29 UTC (rev 78501)
@@ -0,0 +1,7 @@
+[buildout]
+develop = .
+parts = test
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = z3c.recipe.runscript

Added: z3c.recipe.runscript/trunk/setup.py
===================================================================
--- z3c.recipe.runscript/trunk/setup.py	                        (rev 0)
+++ z3c.recipe.runscript/trunk/setup.py	2007-07-31 05:17:29 UTC (rev 78501)
@@ -0,0 +1,63 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# 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.
+#
+##############################################################################
+"""Setup
+
+$Id$
+"""
+import os
+from setuptools import setup, find_packages
+
+def read(*rnames):
+    return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+setup (
+    name='z3c.recipe.runscript',
+    version='0.1.0',
+    author = "Stephan Richter and the Zope Community",
+    author_email = "zope3-dev at zope.org",
+    description = "A recipe that runs any script to install a part.",
+    long_description=(
+        read('README.txt')
+        + '\n\n' +
+        'Detailed Documentation\n'
+        '**********************'
+        + '\n\n' +
+        read('CHANGES.txt')
+        ),
+    license = "ZPL 2.1",
+    keywords = "buildout recipe",
+    classifiers = [
+        'Development Status :: 4 - Beta',
+        'Environment :: Web Environment',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: Zope Public License',
+        'Programming Language :: Python',
+        'Natural Language :: English',
+        'Operating System :: OS Independent',
+        'Topic :: Internet :: WWW/HTTP',
+        'Framework :: Zope3'],
+    url = 'http://cheeseshop.python.org/pypi/z3c.recipe.runscript',
+    packages = find_packages('src'),
+    include_package_data = True,
+    package_dir = {'':'src'},
+    namespace_packages = ['z3c', 'z3c.recipe'],
+    install_requires = [
+        'setuptools',
+        'zc.buildout'
+        ],
+    entry_points = {'zc.buildout':
+                    ['default = z3c.recipe.runscript:Recipe']},
+    dependency_links = ['http://download.zope.org/distribution'],
+    zip_safe = False,
+    )


Property changes on: z3c.recipe.runscript/trunk/setup.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: z3c.recipe.runscript/trunk/src/z3c/__init__.py
===================================================================
--- z3c.recipe.runscript/trunk/src/z3c/__init__.py	                        (rev 0)
+++ z3c.recipe.runscript/trunk/src/z3c/__init__.py	2007-07-31 05:17:29 UTC (rev 78501)
@@ -0,0 +1,7 @@
+try:
+    # Declare this a namespace package if pkg_resources is available.
+    import pkg_resources
+    pkg_resources.declare_namespace('z3c')
+except ImportError:
+    pass
+


Property changes on: z3c.recipe.runscript/trunk/src/z3c/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: z3c.recipe.runscript/trunk/src/z3c/recipe/__init__.py
===================================================================
--- z3c.recipe.runscript/trunk/src/z3c/recipe/__init__.py	                        (rev 0)
+++ z3c.recipe.runscript/trunk/src/z3c/recipe/__init__.py	2007-07-31 05:17:29 UTC (rev 78501)
@@ -0,0 +1,7 @@
+try:
+    # Declare this a namespace package if pkg_resources is available.
+    import pkg_resources
+    pkg_resources.declare_namespace('recipe')
+except ImportError:
+    pass
+


Property changes on: z3c.recipe.runscript/trunk/src/z3c/recipe/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/README.txt
===================================================================
--- z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/README.txt	                        (rev 0)
+++ z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/README.txt	2007-07-31 05:17:29 UTC (rev 78501)
@@ -0,0 +1,71 @@
+=================================
+The ``runscript`` Buildout Recipe
+=================================
+
+Some software is not easily installed using established build patterns, such
+as "configure, make, make install". In those cases you want to be able to use
+arbitrary scripts to build a particular part. This recipe provides a simple
+implementation to run a Python callable for each installing and updating a
+part.
+
+  >>> import os
+  >>> import z3c.recipe.runscript.tests
+  >>> scriptFilename = os.path.join(
+  ...     os.path.dirname(z3c.recipe.runscript.tests.__file__), 'fooscripts.py')
+
+Let's create a sample buildout to install it:
+
+    >>> write('buildout.cfg',
+    ... """
+    ... [buildout]
+    ... parts = foo
+    ...
+    ... [foo]
+    ... recipe = z3c.recipe.runscript
+    ... install-script = %s:installFoo
+    ... """ %scriptFilename)
+
+The ``install-script`` option specifies the module and the function to call
+during the part installation. The function takes the local and buildout
+options as arguments. See ``tests/fooscripts.py`` for details.
+
+When running buildout, the ``installFoo()`` function is called:
+
+    >>> print system('bin/buildout')
+    Installing foo.
+    Now executing ``installFoo()``
+
+If we run the buildout again, the update method will be called, but since we
+did not specify any, ntohing happens:
+
+    >>> print system('bin/buildout')
+    Updating foo.
+
+Let's now specify the update script as well, causing the ``updateFoo()``
+function to be called:
+
+    >>> write('buildout.cfg',
+    ... """
+    ... [buildout]
+    ... parts = foo
+    ...
+    ... [foo]
+    ... recipe = z3c.recipe.runscript
+    ... install-script = %s:installFoo
+    ... update-script = %s:updateFoo
+    ... """ %(scriptFilename, scriptFilename))
+
+But after a change like that, parts will be uninstalled and reinstalled:
+
+    >>> print system('bin/buildout')
+    Uninstalling foo.
+    Installing foo.
+    Now executing ``installFoo()``
+
+Only now we can update the part:
+
+    >>> print system('bin/buildout')
+    Updating foo.
+    Now executing ``updateFoo()``
+
+And that's it.


Property changes on: z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/README.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/__init__.py
===================================================================
--- z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/__init__.py	                        (rev 0)
+++ z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/__init__.py	2007-07-31 05:17:29 UTC (rev 78501)
@@ -0,0 +1,49 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# 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 imp
+import os
+
+class Recipe:
+
+    def __init__(self, buildout, name, options):
+        self.name, self.options, self.buildout = name, options, buildout
+        options['location'] = options['prefix'] = os.path.join(
+            buildout['buildout']['parts-directory'],
+            name)
+
+    def callScript(self, script):
+        filename, callable = script.split(':')
+        filename = os.path.abspath(filename)
+        module = imp.load_source('script', filename)
+        # Run the script with all options
+        getattr(module, callable)(self.options, self.buildout)
+
+    def install(self):
+        # Create directory
+        dest = self.options['location']
+        if not os.path.exists(dest):
+            os.mkdir(dest)
+        # Retrieve ans run the script with all options
+        script = self.options['install-script']
+        self.callScript(script)
+        return dest
+
+    def update(self):
+        if 'update-script' not in self.options:
+            return
+        # Retrieve ans run the script with all options
+        script = self.options['update-script']
+        self.callScript(script)
+
+


Property changes on: z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/tests/__init__.py
===================================================================
--- z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/tests/__init__.py	                        (rev 0)
+++ z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/tests/__init__.py	2007-07-31 05:17:29 UTC (rev 78501)
@@ -0,0 +1 @@
+# Make a package


Property changes on: z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/tests/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/tests/fooscripts.py
===================================================================
--- z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/tests/fooscripts.py	                        (rev 0)
+++ z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/tests/fooscripts.py	2007-07-31 05:17:29 UTC (rev 78501)
@@ -0,0 +1,7 @@
+
+
+def installFoo(options, buildout):
+    print 'Now executing ``installFoo()``'
+
+def updateFoo(options, buildout):
+    print 'Now executing ``updateFoo()``'


Property changes on: z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/tests/fooscripts.py
___________________________________________________________________
Name: svn:keywords
   + Id

Added: z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/tests/test_doc.py
===================================================================
--- z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/tests/test_doc.py	                        (rev 0)
+++ z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/tests/test_doc.py	2007-07-31 05:17:29 UTC (rev 78501)
@@ -0,0 +1,30 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# 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.
+#
+##############################################################################
+"""z3c.recipe.runscript test setup."""
+import unittest
+import zc.buildout.testing
+from zope.testing import doctest
+
+def setUp(test):
+    zc.buildout.testing.buildoutSetUp(test)
+    zc.buildout.testing.install_develop('z3c.recipe.runscript', test)
+
+def test_suite():
+    return unittest.TestSuite((
+        doctest.DocFileSuite(
+            '../README.txt',
+            setUp=setUp, tearDown=zc.buildout.testing.buildoutTearDown,
+            optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+            ),
+        ))


Property changes on: z3c.recipe.runscript/trunk/src/z3c/recipe/runscript/tests/test_doc.py
___________________________________________________________________
Name: svn:keywords
   + Id



More information about the Checkins mailing list