[Checkins] SVN: zc.recipe.deployment/branches/andrew-customize-etc-directory/src/zc/recipe/deployment/ A directory option will override a default etc directory.

Andrew Sung asung at zope.com
Mon Nov 21 16:19:13 UTC 2011


Log message for revision 123462:
  A directory option will override a default etc directory.
  

Changed:
  U   zc.recipe.deployment/branches/andrew-customize-etc-directory/src/zc/recipe/deployment/README.txt
  U   zc.recipe.deployment/branches/andrew-customize-etc-directory/src/zc/recipe/deployment/__init__.py

-=-
Modified: zc.recipe.deployment/branches/andrew-customize-etc-directory/src/zc/recipe/deployment/README.txt
===================================================================
--- zc.recipe.deployment/branches/andrew-customize-etc-directory/src/zc/recipe/deployment/README.txt	2011-11-21 14:46:55 UTC (rev 123461)
+++ zc.recipe.deployment/branches/andrew-customize-etc-directory/src/zc/recipe/deployment/README.txt	2011-11-21 16:19:12 UTC (rev 123462)
@@ -354,10 +354,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 +370,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 +468,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/branches/andrew-customize-etc-directory/src/zc/recipe/deployment/__init__.py
===================================================================
--- zc.recipe.deployment/branches/andrew-customize-etc-directory/src/zc/recipe/deployment/__init__.py	2011-11-21 14:46:55 UTC (rev 123461)
+++ zc.recipe.deployment/branches/andrew-customize-etc-directory/src/zc/recipe/deployment/__init__.py	2011-11-21 16:19:12 UTC (rev 123462)
@@ -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