[Checkins] SVN: zc.zdaemonrecipe/trunk/ initial version

Jim Fulton jim at zope.com
Thu Jul 5 14:51:45 EDT 2007


Log message for revision 77477:
  initial version

Changed:
  _U  zc.zdaemonrecipe/trunk/
  A   zc.zdaemonrecipe/trunk/buildout.cfg
  A   zc.zdaemonrecipe/trunk/setup.py
  A   zc.zdaemonrecipe/trunk/zc/
  A   zc.zdaemonrecipe/trunk/zc/__init__.py
  A   zc.zdaemonrecipe/trunk/zc/zdaemonrecipe/
  A   zc.zdaemonrecipe/trunk/zc/zdaemonrecipe/README.txt
  A   zc.zdaemonrecipe/trunk/zc/zdaemonrecipe/__init__.py
  A   zc.zdaemonrecipe/trunk/zc/zdaemonrecipe/tests.py

-=-

Property changes on: zc.zdaemonrecipe/trunk
___________________________________________________________________
Name: svn:ignore
   + parts
.installed.cfg
bin
develop-eggs
doc.txt


Added: zc.zdaemonrecipe/trunk/buildout.cfg
===================================================================
--- zc.zdaemonrecipe/trunk/buildout.cfg	                        (rev 0)
+++ zc.zdaemonrecipe/trunk/buildout.cfg	2007-07-05 18:51:45 UTC (rev 77477)
@@ -0,0 +1,8 @@
+[buildout]
+develop = .
+parts = test
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = zc.zdaemonrecipe [test]
+


Property changes on: zc.zdaemonrecipe/trunk/buildout.cfg
___________________________________________________________________
Name: svn:eol-style
   + native

Added: zc.zdaemonrecipe/trunk/setup.py
===================================================================
--- zc.zdaemonrecipe/trunk/setup.py	                        (rev 0)
+++ zc.zdaemonrecipe/trunk/setup.py	2007-07-05 18:51:45 UTC (rev 77477)
@@ -0,0 +1,44 @@
+import os
+from setuptools import setup, find_packages
+
+entry_points = '''
+[zc.buildout]
+default=zc.zdaemonrecipe:Recipe
+'''
+
+def read(*rnames):
+    return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+long_description=(
+        read('README.txt')
+        + '\n' +
+        'Detailed Documentation\n'
+        '**********************\n'
+        + '\n' +
+        read('zc', 'zdaemonrecipe', 'README.txt')
+        + '\n' +
+        'Download\n'
+        '**********************\n'
+        )
+
+open('doc.txt', 'w').write(long_description)
+
+name = 'zc.zdaemonrecipe'
+setup(
+    name = name,
+    version = '0.1',
+    author = 'Jim Fulton',
+    author_email = 'jim at zope.com',
+    description = 'ZC Buildout recipe for zdaemon scripts',
+    long_description=long_description,
+    license = 'ZPL 2.1',
+    
+    entry_points=entry_points,
+    packages = find_packages('.'),
+    namespace_packages = ['zc'],
+    extras_require = dict(test=['zdaemon']),
+    install_requires = ['setuptools',
+                        'zc.buildout', 'zc.recipe.egg',
+                        'ZConfig'],
+    zip_safe = False,
+    )


Property changes on: zc.zdaemonrecipe/trunk/setup.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zc.zdaemonrecipe/trunk/zc/__init__.py
===================================================================
--- zc.zdaemonrecipe/trunk/zc/__init__.py	                        (rev 0)
+++ zc.zdaemonrecipe/trunk/zc/__init__.py	2007-07-05 18:51:45 UTC (rev 77477)
@@ -0,0 +1 @@
+__import__('pkg_resources').declare_namespace(__name__)


Property changes on: zc.zdaemonrecipe/trunk/zc/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zc.zdaemonrecipe/trunk/zc/zdaemonrecipe/README.txt
===================================================================
--- zc.zdaemonrecipe/trunk/zc/zdaemonrecipe/README.txt	                        (rev 0)
+++ zc.zdaemonrecipe/trunk/zc/zdaemonrecipe/README.txt	2007-07-05 18:51:45 UTC (rev 77477)
@@ -0,0 +1,227 @@
+zdaemon recipe
+==============
+
+zc.zdaemonrecipe provides a recipe that can be used to create zdaemon
+run-control scripts. It can be used directly in buildouts and by other
+recipes.
+
+It accepts 2 options:
+
+program 
+   The anme of the program and, optionally, command-line arguments.
+   (Note that, due to limitations in zdaemon, the command-line options
+   cannot have embedded spaces.)
+
+zdaemon.conf
+   Optionally, you can provide extra configuration in ZConfig format.
+   What's provided will be augmented by the zdaemon recipe, as needed.
+
+deployment
+   The name of a zc.recipe.deployment deployment.  If specified, then:
+
+   - The configuration, log, and run-time files will be put in
+     deployment-defined directories.
+
+   - A logrotate configuration will be generated for the zdaemon
+     transacript log.
+
+Let's look at an example:
+
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... parts = run
+    ...
+    ... [run]
+    ... recipe = zc.zdaemonrecipe
+    ... program = sleep 1
+    ... ''')
+
+If we run the buildout, we'll get a run part that contains the zdaemon
+configuration file and a run script in the bin directory:
+
+    >>> print system(buildout),
+    Installing run.
+    Generated script '/sample-buildout/bin/zdaemon'.
+    Generated script '/sample-buildout/bin/run'.
+
+    >>> cat('parts', 'run', 'zdaemon.conf')
+    <runner>
+      daemon on
+      directory /sample-buildout/parts/run
+      program sleep 1
+      socket-name /sample-buildout/parts/run/zdaemon.sock
+      transcript /sample-buildout/parts/run/transcript.log
+    </runner>
+    <BLANKLINE>
+    <eventlog>
+      <logfile>
+        path /sample-buildout/parts/run/transcript.log
+      </logfile>
+    </eventlog>
+
+    >>> cat('bin', 'run')
+    #!/usr/local/bin/python2.4
+    <BLANKLINE>
+    import sys
+    sys.path[0:0] = [
+      '/sample-buildout/eggs/zdaemon-2.0-py2.4.egg',
+      '/sample-buildout/eggs/ZConfig-2.4-py2.4.egg',
+      ]
+    <BLANKLINE>
+    import zdaemon.zdctl
+    <BLANKLINE>
+    if __name__ == '__main__':
+        zdaemon.zdctl.main([
+            '-C', '/sample-buildout/parts/run/zdaemon.conf',
+            ]+sys.argv[1:]
+            )
+
+zdaemon will also be installed:
+
+    >>> ls('eggs')
+    d  ZConfig-2.4-py2.4.egg
+    d  setuptools-0.6-py2.4.egg
+    d  zc.buildout-1.0.0b27-py2.4.egg
+    d  zc.recipe.egg-1.0.0-py2.4.egg
+    d  zdaemon-2.0-py2.4.egg
+    d  zope.testing-3.4-py2.4.egg
+
+You can use an eggs option to specify a zdaemon version.
+
+
+If we specify a deployment, then the files will be placed in
+deployment-defined locations:
+
+    >>> mkdir('etc')
+    >>> mkdir('init.d')
+    >>> mkdir('logrotate')
+
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... parts = run
+    ...
+    ... [run]
+    ... recipe = zc.zdaemonrecipe
+    ... program = sleep 1
+    ... deployment = deploy
+    ...
+    ... [deploy]
+    ... etc-directory = etc
+    ... rc-directory = init.d
+    ... log-directory = logs
+    ... run-directory = run
+    ... logrotate-directory = logrotate
+    ... user = bob
+    ... ''')
+    
+    >>> print system(buildout),
+    Uninstalling run.
+    Installing run.
+    Generated script '/sample-buildout/init.d/deploy-run'.
+
+    >>> import os
+    >>> os.path.exists('parts/run')
+    False
+
+    >>> os.path.exists('bin/run')
+    False
+
+    >>> cat('etc', 'run-zdaemon.conf')
+    <runner>
+      daemon on
+      directory run
+      program sleep 1
+      socket-name run/run-zdaemon.sock
+      transcript logs/run.log
+      user bob
+    </runner>
+    <BLANKLINE>
+    <eventlog>
+      <logfile>
+        path logs/run.log
+      </logfile>
+    </eventlog>
+
+    >>> cat('init.d', 'deploy-run')
+    #!/usr/local/bin/python2.4
+    <BLANKLINE>
+    import sys
+    sys.path[0:0] = [
+      '/sample-buildout/eggs/zdaemon-2.0a6-py2.4.egg',
+      '/sample-buildout/eggs/ZConfig-2.4a6-py2.4.egg',
+      ]
+    <BLANKLINE>
+    import zdaemon.zdctl
+    <BLANKLINE>
+    if __name__ == '__main__':
+        zdaemon.zdctl.main([
+            '-C', 'etc/run-zdaemon.conf',
+            ]+sys.argv[1:]
+            )
+
+    >>> cat('logrotate', 'deploy-run')
+    logs/run.log {
+      rotate 5
+      weekly
+      postrotate
+        init.d/deploy-run -C etc/run-zdaemon.conf reopen_transcript
+      endscript
+    }
+
+
+If you want to override any part of the generated zdaemon configuration,
+simply provide a zdaemon.conf option in your instance section:
+
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... parts = run
+    ...
+    ... [run]
+    ... recipe = zc.zdaemonrecipe
+    ... program = sleep 1
+    ... deployment = deploy
+    ... zdaemon.conf =
+    ...     <runner>
+    ...       daemon off
+    ...       socket-name /sample-buildout/parts/instance/sock
+    ...       transcript /dev/null
+    ...     </runner>
+    ...     <eventlog>
+    ...     </eventlog>
+    ...
+    ... [deploy]
+    ... etc-directory = etc
+    ... rc-directory = init.d
+    ... log-directory = logs
+    ... run-directory = run
+    ... logrotate-directory = logrotate
+    ... user = bob
+    ... ''')
+
+    >>> print system(buildout),
+    Uninstalling run.
+    Installing run.
+    Generated script '/sample-buildout/init.d/deploy-run'.
+
+    >>> cat('etc', 'run-zdaemon.conf')
+    <runner>
+      daemon off
+      directory run
+      program sleep 1
+      socket-name /sample-buildout/parts/instance/sock
+      transcript /dev/null
+      user bob
+    </runner>
+    <BLANKLINE>
+    <eventlog>
+    </eventlog>
+
+Using the zdaemon recipe from other recipes
+-------------------------------------------
+
+To use the daemon recipe from other recipes, simply instantiate an
+instance in your recipe __init__, passing your __init__ arguments, and
+then calling the instance's install in your install method.


Property changes on: zc.zdaemonrecipe/trunk/zc/zdaemonrecipe/README.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: zc.zdaemonrecipe/trunk/zc/zdaemonrecipe/__init__.py
===================================================================
--- zc.zdaemonrecipe/trunk/zc/zdaemonrecipe/__init__.py	                        (rev 0)
+++ zc.zdaemonrecipe/trunk/zc/zdaemonrecipe/__init__.py	2007-07-05 18:51:45 UTC (rev 77477)
@@ -0,0 +1,159 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 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.
+#
+##############################################################################
+"""zdaemon -- a package to manage a daemon application."""
+
+import os, cStringIO
+
+import zc.buildout.easy_install, zc.recipe.egg, ZConfig.schemaless
+
+class Recipe:
+
+    def __init__(self, buildout, name, options):
+        self.name, self.options = name, options
+
+        deployment = self.deployment = options.get('deployment')
+        if deployment:
+            options['rc-directory'] = buildout[deployment]['rc-directory']
+            options['run-directory'] = buildout[deployment]['run-directory']
+            options['log-directory'] = buildout[deployment]['log-directory']
+            options['etc-directory'] = buildout[deployment]['etc-directory']
+            options['logrotate'] = os.path.join(
+                buildout[deployment]['logrotate-directory'],
+                deployment + '-' + name)
+            options['user'] = buildout[deployment]['user']
+        else:
+            options['rc-directory'] = buildout['buildout']['bin-directory']
+            options['run-directory'] = os.path.join(
+                buildout['buildout']['parts-directory'],
+                self.name,
+                )
+
+        options['eggs'] = options.get('eggs', 'zdaemon')
+        self.egg = zc.recipe.egg.Egg(buildout, name, options)
+
+
+    def install(self):
+        options = self.options
+
+        run_directory = options['run-directory']
+        deployment = self.deployment
+        if deployment:
+            zdaemon_conf_path = os.path.join(options['etc-directory'],
+                                             self.name+'-zdaemon.conf')
+            event_log_path = os.path.join(
+                options['log-directory'],
+                self.name+'.log',
+                )
+            socket_path = os.path.join(run_directory,
+                                       self.name+'-zdaemon.sock')
+
+            rc = deployment + '-' + self.name
+            rc=os.path.join(options['rc-directory'], rc)
+
+            logrotate = options['logrotate']
+            options.created(logrotate)
+            open(logrotate, 'w').write(logrotate_template % dict(
+                logfile=event_log_path,
+                rc=rc,
+                conf=zdaemon_conf_path,
+                ))
+
+        else:
+            zdaemon_conf_path = os.path.join(run_directory, 'zdaemon.conf')
+            event_log_path = os.path.join(
+                run_directory,
+                'transcript.log',
+                )
+            socket_path = os.path.join(run_directory, 'zdaemon.sock')
+            rc = self.name
+            rc=os.path.join(options['rc-directory'], rc)
+            options.created(run_directory)
+            if not os.path.exists(run_directory):
+                os.mkdir(run_directory)
+
+        zdaemon_conf = options.get('zdaemon.conf', '')+'\n'
+        zdaemon_conf = ZConfig.schemaless.loadConfigFile(
+            cStringIO.StringIO(zdaemon_conf))
+
+        defaults = {
+            'program': "%s" % options['program'],
+            'daemon': 'on',
+            'transcript': event_log_path,
+            'socket-name': socket_path,
+            'directory' : run_directory,
+            }
+        if deployment:
+            defaults['user'] = options['user']
+        runner = [s for s in zdaemon_conf.sections
+                  if s.type == 'runner']
+        if runner:
+            runner = runner[0]
+        else:
+            runner = ZConfig.schemaless.Section('runner')
+            zdaemon_conf.sections.insert(0, runner)
+        for name, value in defaults.items():
+            if name not in runner:
+                runner[name] = [value]
+
+        if not [s for s in zdaemon_conf.sections
+                if s.type == 'eventlog']:
+            zdaemon_conf.sections.append(event_log(event_log_path))
+
+        options.created(zdaemon_conf_path)
+        open(zdaemon_conf_path, 'w').write(str(zdaemon_conf))
+
+        self.egg.install()
+        requirements, ws = self.egg.working_set()
+
+        rc = os.path.abspath(rc)
+        options.created(rc)
+        zc.buildout.easy_install.scripts(
+            [(rc, 'zdaemon.zdctl', 'main')],
+            ws, options['executable'], options['rc-directory'],
+            arguments = ('['
+                         '\n        %r, %r,'
+                         '\n        ]+sys.argv[1:]'
+                         '\n        '
+                         % ('-C', zdaemon_conf_path,
+                            )
+                         ),
+            )
+
+        return options.created()
+
+
+    update = install
+
+def event_log(path, *data):
+    return ZConfig.schemaless.Section(
+        'eventlog', '', None,
+        [ZConfig.schemaless.Section('logfile', '', dict(path=[path]))])
+
+event_log_template = """
+<eventlog>
+  <logfile>
+    path %s
+    formatter zope.exceptions.log.Formatter
+  </logfile>
+</eventlog>
+"""
+
+logrotate_template = """%(logfile)s {
+  rotate 5
+  weekly
+  postrotate
+    %(rc)s -C %(conf)s reopen_transcript
+  endscript
+}
+"""


Property changes on: zc.zdaemonrecipe/trunk/zc/zdaemonrecipe/__init__.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: zc.zdaemonrecipe/trunk/zc/zdaemonrecipe/tests.py
===================================================================
--- zc.zdaemonrecipe/trunk/zc/zdaemonrecipe/tests.py	                        (rev 0)
+++ zc.zdaemonrecipe/trunk/zc/zdaemonrecipe/tests.py	2007-07-05 18:51:45 UTC (rev 77477)
@@ -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.
+#
+##############################################################################
+
+import os, re, shutil, sys, tempfile
+import pkg_resources
+
+import zc.buildout.testing
+
+import unittest
+import zope.testing
+from zope.testing import doctest, renormalizing
+
+
+def setUp(test):
+    zc.buildout.testing.buildoutSetUp(test)
+    zc.buildout.testing.install_develop('zc.zdaemonrecipe', test)
+    zc.buildout.testing.install('zope.testing', test)
+    zc.buildout.testing.install('zc.recipe.egg', test)
+    zc.buildout.testing.install('zdaemon', test)
+    zc.buildout.testing.install('ZConfig', test)
+
+
+checker = renormalizing.RENormalizing([
+    zc.buildout.testing.normalize_path,
+    (re.compile(
+    "Couldn't find index page for '[a-zA-Z0-9.]+' "
+    "\(maybe misspelled\?\)"
+    "\n"
+    ), ''),
+    (re.compile('#![^\n]+\n'), ''),                
+    (re.compile('-\S+-py\d[.]\d(-\S+)?.egg'),
+     '-pyN.N.egg',
+    ),
+    ])
+
+def test_suite():
+    return unittest.TestSuite((
+        doctest.DocFileSuite(
+            'README.txt',
+            setUp=setUp, tearDown=zc.buildout.testing.buildoutTearDown,
+            checker=checker,
+            ),
+        
+        ))


Property changes on: zc.zdaemonrecipe/trunk/zc/zdaemonrecipe/tests.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the Checkins mailing list