[Checkins] SVN: zc.recipe.deployment/trunk/ Merge andrew-customer-etc-directory branch back to trunk.

Andrew Sung asung at zope.com
Mon Nov 21 20:24:20 UTC 2011


Log message for revision 123468:
  Merge andrew-customer-etc-directory branch back to trunk.
  
  svn merge -r123430:HEAD svn+ssh://svn.zope.org/repos/main/zc.recipe.deployment/branches/andrew-customize-etc-directory
  
  

Changed:
  _U  zc.recipe.deployment/trunk/
  U   zc.recipe.deployment/trunk/CHANGES.txt
  U   zc.recipe.deployment/trunk/setup.py
  U   zc.recipe.deployment/trunk/src/zc/recipe/deployment/README.txt
  U   zc.recipe.deployment/trunk/src/zc/recipe/deployment/__init__.py

-=-

Property changes on: zc.recipe.deployment/trunk
___________________________________________________________________
Modified: svn:ignore
   - build
develop-eggs
dist
bin
parts

   + .installed.cfg
bin
build
develop-eggs
dist
eggs
parts


Modified: zc.recipe.deployment/trunk/CHANGES.txt
===================================================================
--- zc.recipe.deployment/trunk/CHANGES.txt	2011-11-21 18:38:56 UTC (rev 123467)
+++ zc.recipe.deployment/trunk/CHANGES.txt	2011-11-21 20:24:19 UTC (rev 123468)
@@ -1,7 +1,7 @@
 Changes
 *******
 
-0.8.1 (unreleased)
+0.9.0 (unreleased)
 ==================
 
 - Fixed test dependencies.
@@ -9,7 +9,10 @@
 - Using Python's ``doctest`` module instead of deprecated
   ``zope.testing.doctest``.
 
+- Added a directory option for configuration to override default etc
+  directory.
 
+
 0.8.0 (2010-05-18)
 ==================
 

Modified: zc.recipe.deployment/trunk/setup.py
===================================================================
--- zc.recipe.deployment/trunk/setup.py	2011-11-21 18:38:56 UTC (rev 123467)
+++ zc.recipe.deployment/trunk/setup.py	2011-11-21 20:24:19 UTC (rev 123468)
@@ -22,7 +22,7 @@
 
 setup(
     name = name,
-    version = '0.8dev',
+    version = '0.9dev',
     author = 'Jim Fulton',
     author_email = 'jim at zope.com',
     description = 'ZC Buildout recipe for Unix deployments',

Modified: zc.recipe.deployment/trunk/src/zc/recipe/deployment/README.txt
===================================================================
--- zc.recipe.deployment/trunk/src/zc/recipe/deployment/README.txt	2011-11-21 18:38:56 UTC (rev 123467)
+++ zc.recipe.deployment/trunk/src/zc/recipe/deployment/README.txt	2011-11-21 20:24:19 UTC (rev 123468)
@@ -36,7 +36,6 @@
         Creating 'PREFIX/etc/logrotate.d',
         mode 755, user 'USER', group 'GROUP'
 
-
 Note that we are providing a prefix and an etc-user here.  These options
 default to '/' and 'root', respectively.
 
@@ -354,10 +353,13 @@
     ... deployment = foo
     ... ''' % (sample_buildout, user, user))
 
-    >>> print system(join('bin', 'buildout')),
+    >>> print system(join('bin', 'buildout')), # doctest: +NORMALIZE_WHITESPACE
     Uninstalling x.cfg.
     Updating foo.
     Installing x.cfg.
+    zc.recipe.deployment:
+        Updating 'PREFIX/etc/foo',
+        mode 755, user 'USER', group 'GROUP'
 
     >>> os.path.exists(join('parts', 'x.cfg'))
     False
@@ -367,6 +369,82 @@
     yyy
     zzz
 
+If a directory is specified, then the file is placed in the directory.
+
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... parts = foo x.cfg
+    ...
+    ... [foo]
+    ... recipe = zc.recipe.deployment
+    ... prefix = %s
+    ... user = %s
+    ... etc-user = %s
+    ...
+    ... [x.cfg]
+    ... recipe = zc.recipe.deployment:configuration
+    ... text = xxx
+    ...        yyy
+    ...        zzz
+    ... directory = etc/foobar
+    ... deployment = foo
+    ... ''' % (sample_buildout, user, user))
+
+    >>> print system(join('bin', 'buildout')), # doctest: +NORMALIZE_WHITESPACE
+    Uninstalling x.cfg.
+    Updating foo.
+    Installing x.cfg.
+    zc.recipe.deployment:
+        Creating 'PREFIX/etc/foobar',
+        mode 755, user 'USER', group 'GROUP'
+
+    >>> os.path.exists(join('parts', 'x.cfg'))
+    False
+    >>> os.path.exists(join(sample_buildout, 'etc/foo/x.cfg'))
+    False
+
+    >>> cat(os.path.join(sample_buildout, 'etc/foobar/x.cfg'))
+    xxx
+    yyy
+    zzz
+
+A directory option works only with a deployment option.
+
+    >>> write('buildout.cfg',
+    ... '''
+    ... [buildout]
+    ... parts = foo x.cfg
+    ...
+    ... [foo]
+    ... recipe = zc.recipe.deployment
+    ... prefix = %s
+    ... user = %s
+    ... etc-user = %s
+    ...
+    ... [x.cfg]
+    ... recipe = zc.recipe.deployment:configuration
+    ... text = xxx
+    ...        yyy
+    ...        zzz
+    ... directory = etc/foobar
+    ... ''' % (sample_buildout, user, user))
+
+    >>> print system(join('bin', 'buildout')),
+    Uninstalling x.cfg.
+    Updating foo.
+    Installing x.cfg.
+
+    >>> os.path.exists(join('parts', 'x.cfg'))
+    True
+    >>> os.path.exists(join(sample_buildout, 'etc/foobar/x.cfg'))
+    False
+
+    >>> cat('parts', 'x.cfg')
+    xxx
+    yyy
+    zzz
+
 We can read data from a file rather than specifying in the
 configuration:
 
@@ -389,10 +467,13 @@
     ... deployment = foo
     ... ''' % (sample_buildout, user, user))
 
-    >>> print system(join('bin', 'buildout')),
+    >>> print system(join('bin', 'buildout')), # doctest: +NORMALIZE_WHITESPACE
     Uninstalling x.cfg.
     Updating foo.
     Installing x.cfg.
+    zc.recipe.deployment:
+        Updating 'PREFIX/etc/foo',
+        mode 755, user 'USER', group 'GROUP'
 
     >>> cat(os.path.join(sample_buildout, 'etc/foo/x.cfg'))
     1

Modified: zc.recipe.deployment/trunk/src/zc/recipe/deployment/__init__.py
===================================================================
--- zc.recipe.deployment/trunk/src/zc/recipe/deployment/__init__.py	2011-11-21 18:38:56 UTC (rev 123467)
+++ zc.recipe.deployment/trunk/src/zc/recipe/deployment/__init__.py	2011-11-21 20:24:19 UTC (rev 123468)
@@ -118,13 +118,19 @@
 
         deployment = options.get('deployment')
         if deployment:
-            options['location'] = os.path.join(
-                buildout[deployment]['etc-directory'],
-                name)
+            options['etc-user'] = buildout[deployment].get('etc-user', 'root')
+            options['prefix'] = buildout[deployment].get('prefix', '/')
+            directory = options.get("directory")
+            if directory:
+                directory = os.path.join(options['prefix'], directory)
+            else:
+                directory = os.path.join(
+                    buildout[deployment]['etc-directory'])
         else:
-            options['location'] = os.path.join(
-                buildout['buildout']['parts-directory'],
-                name)
+            directory = os.path.join(
+                buildout['buildout']['parts-directory'])
+        options["directory"] = directory
+        options["location"] = os.path.join(directory, name)
 
     def install(self):
         options = self.options
@@ -136,6 +142,21 @@
             text = open(options['file'], 'r'+mode).read()
         else:
             text = options['text']
+        deployment = options.get('deployment')
+        if deployment:
+            etc_user = options['etc-user']
+            etc_uid, etc_gid = pwd.getpwnam(etc_user)[2:4]
+            created = []
+            try:
+                make_dir(options['directory'], etc_uid, etc_gid, 0755, created)
+            except Exception:
+                for d in created:
+                    try:
+                        shutil.rmtree(d)
+                    except OSError:
+                        # parent directory may have already been removed
+                        pass
+                raise
         open(options['location'], 'w'+mode).write(text)
         return options['location']
 



More information about the checkins mailing list