[Checkins]
SVN: zc.recipe.deployment/trunk/src/zc/recipe/deployment/
Added a name option,
which defaults to the part name. This allows the
Jim Fulton
jim at zope.com
Fri Feb 1 09:46:46 EST 2008
Log message for revision 83377:
Added a name option, which defaults to the part name. This allows the
deployment name to be specified as an option, thus taking advantage of
variable substitutions.
Changed:
U zc.recipe.deployment/trunk/src/zc/recipe/deployment/README.txt
U zc.recipe.deployment/trunk/src/zc/recipe/deployment/__init__.py
-=-
Modified: zc.recipe.deployment/trunk/src/zc/recipe/deployment/README.txt
===================================================================
--- zc.recipe.deployment/trunk/src/zc/recipe/deployment/README.txt 2008-02-01 14:42:48 UTC (rev 83376)
+++ zc.recipe.deployment/trunk/src/zc/recipe/deployment/README.txt 2008-02-01 14:46:46 UTC (rev 83377)
@@ -1,4 +1,4 @@
-Using the deployment recipe is pretty simple. Simply specify a
+Using the deployment recipe is pretty simple. Jusr specify a
deployment name, specified via the part name, and a deployment user.
Let's add a deployment to a sample buildout:
@@ -14,7 +14,7 @@
... ''')
>>> print system(join('bin', 'buildout')),
- buildout: Installing foo
+ Installing foo.
zc.recipe.deployment:
Creating '/etc/foo',
mode 755, user 'root', group 'root'
@@ -44,8 +44,7 @@
By looking at .installed.cfg, we can see the options available for use
by other recipes:
- >>> cat('.installed.cfg')
- ... # doctest: +ELLIPSIS
+ >>> cat('.installed.cfg') # doctest: +ELLIPSIS
[buildout]
...
[foo]
@@ -55,6 +54,7 @@
etc-directory = /etc/foo
log-directory = /var/log/foo
logrotate-directory = /etc/logrotate.d
+ name = foo
rc-directory = /etc/init.d
recipe = zc.recipe.deployment
run-directory = /var/run/foo
@@ -63,8 +63,8 @@
If we ininstall, then the directories are removed.
>>> print system(join('bin', 'buildout')+' buildout:parts='),
- buildout: Uninstalling foo
- buildout: Running uninstall recipe
+ Uninstalling foo.
+ Running uninstall recipe.
zc.recipe.deployment: Removing '/etc/foo'
zc.recipe.deployment: Removing '/var/log/foo'.
zc.recipe.deployment: Removing '/var/run/foo'.
@@ -81,7 +81,7 @@
To see that, we'll put a file in each of the directories created:
>>> print system(join('bin', 'buildout')), # doctest: +ELLIPSIS
- buildout: Installing foo
+ Installing foo.
...
>>> write('/etc/foo/x', '')
@@ -91,8 +91,8 @@
And then uninstall:
>>> print system(join('bin', 'buildout')+' buildout:parts='),
- buildout: Uninstalling foo
- buildout: Running uninstall recipe
+ Uninstalling foo.
+ Running uninstall recipe.
zc.recipe.deployment: Removing '/etc/foo'
zc.recipe.deployment: Can't remove non-empty directory '/var/log/foo'.
zc.recipe.deployment: Can't remove non-empty directory '/var/run/foo'.
@@ -114,7 +114,7 @@
are removed:
>>> print system(join('bin', 'buildout')),
- buildout: Installing foo
+ Installing foo.
zc.recipe.deployment:
Creating '/etc/foo',
mode 755, user 'root', group 'root'
@@ -129,8 +129,8 @@
>>> os.remove('/var/run/foo/x')
>>> print system(join('bin', 'buildout')+' buildout:parts='),
- buildout: Uninstalling foo
- buildout: Running uninstall recipe
+ Uninstalling foo.
+ Running uninstall recipe.
zc.recipe.deployment: Removing '/etc/foo'
zc.recipe.deployment: Removing '/var/log/foo'.
zc.recipe.deployment: Removing '/var/run/foo'.
@@ -142,6 +142,67 @@
>>> os.path.exists('/var/run/foo')
False
+Deployment Name
+===============
+
+The deployment name is used for naming generated files and directories.
+The deployment name defaults to the section name, but the deployment
+name can be specified explicitly:
+
+ >>> write('buildout.cfg',
+ ... '''
+ ... [buildout]
+ ... parts = foo
+ ...
+ ... [foo]
+ ... recipe = zc.recipe.deployment
+ ... name = bar
+ ... user = jim
+ ... ''')
+
+ >>> print system(join('bin', 'buildout')),
+ Installing foo.
+ zc.recipe.deployment:
+ Creating '/etc/bar',
+ mode 755, user 'root', group 'root'
+ zc.recipe.deployment:
+ Creating '/var/log/bar',
+ mode 755, user 'jim', group 'jim'
+ zc.recipe.deployment:
+ Creating '/var/run/bar',
+ mode 750, user 'jim', group 'jim'
+
+ >>> print system('ls -ld /etc/bar'),
+ drwxr-xr-x 2 root root 4096 2007-02-06 09:50 /etc/bar
+
+ >>> print system('ls -ld /var/log/bar'),
+ drwxr-xr-x 2 jim jim 4096 2007-02-06 09:50 /var/log/bar
+
+ >>> print system('ls -ld /var/run/bar'),
+ drwxr-x--- 2 jim jim 40 2007-02-06 09:50 /var/run/bar
+
+ >>> cat('.installed.cfg') # doctest: +ELLIPSIS
+ [buildout]
+ installed_develop_eggs =
+ parts = foo
+ <BLANKLINE>
+ [foo]
+ __buildout_installed__ =
+ ...
+ crontab-directory = /etc/cron.d
+ etc-directory = /etc/bar
+ log-directory = /var/log/bar
+ logrotate-directory = /etc/logrotate.d
+ name = bar
+ rc-directory = /etc/init.d
+ recipe = zc.recipe.deployment
+ run-directory = /var/run/bar
+ user = jim
+
+Note (here and earlier) that the options include the name option,
+which defaults to the part name. Other parts that use the deployment
+name should use the name option rather than the part name.
+
Configuration files
===================
@@ -169,7 +230,12 @@
... ''')
>>> print system(join('bin', 'buildout')),
- buildout: Installing foo
+ Uninstalling foo.
+ Running uninstall recipe.
+ zc.recipe.deployment: Removing '/etc/bar'
+ zc.recipe.deployment: Removing '/var/log/bar'.
+ zc.recipe.deployment: Removing '/var/run/bar'.
+ Installing foo.
zc.recipe.deployment:
Creating '/etc/foo',
mode 755, user 'root', group 'root'
@@ -179,7 +245,7 @@
zc.recipe.deployment:
Creating '/var/run/foo',
mode 750, user 'jim', group 'jim'
- buildout: Installing x.cfg
+ Installing x.cfg.
By default, the configuration is installed as a part:
@@ -209,9 +275,9 @@
... ''')
>>> print system(join('bin', 'buildout')),
- buildout: Uninstalling x.cfg
- buildout: Updating foo
- buildout: Installing x.cfg
+ Uninstalling x.cfg.
+ Updating foo.
+ Installing x.cfg.
>>> os.path.exists(join('parts', 'x.cfg'))
False
@@ -242,9 +308,9 @@
... ''')
>>> print system(join('bin', 'buildout')),
- buildout: Uninstalling x.cfg
- buildout: Updating foo
- buildout: Installing x.cfg
+ Uninstalling x.cfg.
+ Updating foo.
+ Installing x.cfg.
>>> cat('/etc/foo/x.cfg')
1
@@ -285,25 +351,68 @@
... ''')
>>> print system(join('bin', 'buildout')),
- buildout: Uninstalling x.cfg
- buildout: Updating foo
- buildout: Installing cron
+ Uninstalling x.cfg.
+ Updating foo.
+ Installing cron.
This example creates /etc/cron.d/foo-cron
>>> open('/etc/cron.d/foo-cron').read()
'30 23 * * *\tjim\techo hello world!\n'
-.. cleanup
+.. make sure cron recipe honors deployment name option:
- >>> print system(join('bin', 'buildout')+' buildout:parts='),
- buildout: Uninstalling cron
- buildout: Uninstalling foo
- buildout: Running uninstall recipe
+
+ >>> write('buildout.cfg',
+ ... '''
+ ... [buildout]
+ ... parts = foo cron
+ ...
+ ... [foo]
+ ... recipe = zc.recipe.deployment
+ ... name = bar
+ ... user = jim
+ ...
+ ... [cron]
+ ... recipe = zc.recipe.deployment:crontab
+ ... times = 30 23 * * *
+ ... command = echo hello world!
+ ... deployment = foo
+ ... ''')
+
+ >>> print system(join('bin', 'buildout')),
+ Uninstalling cron.
+ Uninstalling foo.
+ Running uninstall recipe.
zc.recipe.deployment: Removing '/etc/foo'
zc.recipe.deployment: Removing '/var/log/foo'.
zc.recipe.deployment: Removing '/var/run/foo'.
+ Installing foo.
+ zc.recipe.deployment:
+ Creating '/etc/bar',
+ mode 755, user 'root', group 'root'
+ zc.recipe.deployment:
+ Creating '/var/log/bar',
+ mode 755, user 'jim', group 'jim'
+ zc.recipe.deployment:
+ Creating '/var/run/bar',
+ mode 750, user 'jim', group 'jim'
+ Installing cron.
- >>> os.path.exists('/etc/cron.d/foo-cron')
+ >>> open('/etc/cron.d/bar-cron').read()
+ '30 23 * * *\tjim\techo hello world!\n'
+
+
+.. cleanup
+
+ >>> print system(join('bin', 'buildout')+' buildout:parts='),
+ Uninstalling cron.
+ Uninstalling foo.
+ Running uninstall recipe.
+ zc.recipe.deployment: Removing '/etc/bar'
+ zc.recipe.deployment: Removing '/var/log/bar'.
+ zc.recipe.deployment: Removing '/var/run/bar'.
+
+ >>> os.path.exists('/etc/cron.d/bar-cron')
False
Modified: zc.recipe.deployment/trunk/src/zc/recipe/deployment/__init__.py
===================================================================
--- zc.recipe.deployment/trunk/src/zc/recipe/deployment/__init__.py 2008-02-01 14:42:48 UTC (rev 83376)
+++ zc.recipe.deployment/trunk/src/zc/recipe/deployment/__init__.py 2008-02-01 14:46:46 UTC (rev 83377)
@@ -24,7 +24,12 @@
class Install:
def __init__(self, buildout, name, options):
- self.name, self.options = name, options
+ self.options = options
+ if not options.get('name'):
+ options['name'] = name
+
+ name = options['name']
+
create = []
options['run-directory'] = os.path.join(options.get('run', '/var/run'),
@@ -94,7 +99,7 @@
class Configuration:
def __init__(self, buildout, name, options):
- self.name, self.options = name, options
+ self.options = options
deployment = options.get('deployment')
if deployment:
@@ -124,12 +129,13 @@
class Crontab:
def __init__(self, buildout, name, options):
- self.name, self.options = name, options
+ self.options = options
deployment = options['deployment']
+ deployment_name = buildout[deployment]['name']
options['location'] = os.path.join(
buildout[deployment]['crontab-directory'],
- deployment + '-' + name)
+ deployment_name + '-' + name)
options['entry'] = '%s\t%s\t%s\n' % (
options['times'], buildout[deployment]['user'], options['command'])
More information about the Checkins
mailing list