Commit cfd1a7ae authored by amos's avatar amos

Changed uninstall recipe to be tied more closely with normal recipes.

Both now must use the same name. Thus there is no need for a part 
'uninstall' option.


git-svn-id: http://svn.zope.org/repos/main/zc.buildout/trunk@71423 62d5b8a3-27da-0310-9561-8e5933582275
parent a9026cec
...@@ -250,16 +250,15 @@ class Buildout(UserDict.DictMixin): ...@@ -250,16 +250,15 @@ class Buildout(UserDict.DictMixin):
self._logger.info('Uninstalling %s', part) self._logger.info('Uninstalling %s', part)
# run uinstall recipe # run uinstall recipe
recipe = installed_part_options[part].get('uninstall') recipe, entry = _recipe(installed_part_options[part])
if recipe: try:
if ':' in recipe:
recipe, entry = recipe.split(':')
else:
entry = 'default'
self._logger.info('Running uninstall recipe')
uninstaller = pkg_resources.load_entry_point( uninstaller = pkg_resources.load_entry_point(
recipe, 'zc.buildout.uninstall', entry) recipe, 'zc.buildout.uninstall', entry)
self._logger.info('Running uninstall recipe')
uninstaller(part, installed_part_options[part]) uninstaller(part, installed_part_options[part])
except (ImportError, pkg_resources.DistributionNotFound):
# no uninstall recipe registered
pass
# remove created files and directories # remove created files and directories
self._uninstall( self._uninstall(
......
...@@ -843,7 +843,10 @@ with an uninstall recipe that simulates removing the service. ...@@ -843,7 +843,10 @@ with an uninstall recipe that simulates removing the service.
... print "chkconfig --del %s" % options['script'] ... print "chkconfig --del %s" % options['script']
... """) ... """)
To use these recipes we must register them using entry points. To use these recipes we must register them using entry points. Make
sure to use the same name for the recipe and uninstall recipe. This is
required to let buildout know which uninstall recipe goes with which
recipe.
>>> write(sample_buildout, 'recipes', 'setup.py', >>> write(sample_buildout, 'recipes', 'setup.py',
... """ ... """
...@@ -856,7 +859,7 @@ To use these recipes we must register them using entry points. ...@@ -856,7 +859,7 @@ To use these recipes we must register them using entry points.
... service = service:Service ... service = service:Service
... ...
... [zc.buildout.uninstall] ... [zc.buildout.uninstall]
... uninstall_service = service:uninstall_service ... service = service:uninstall_service
... ''') ... ''')
... setup(name="recipes", entry_points=entry_points) ... setup(name="recipes", entry_points=entry_points)
... """) ... """)
...@@ -872,7 +875,6 @@ Here's how these recipes could be used in a buildout: ...@@ -872,7 +875,6 @@ Here's how these recipes could be used in a buildout:
... [service] ... [service]
... recipe = recipes:service ... recipe = recipes:service
... script = /path/to/script ... script = /path/to/script
... uninstall = recipes:uninstall_service
... """) ... """)
When the buildout is run the service will be installed When the buildout is run the service will be installed
...@@ -884,7 +886,8 @@ When the buildout is run the service will be installed ...@@ -884,7 +886,8 @@ When the buildout is run the service will be installed
chkconfig --add /path/to/script chkconfig --add /path/to/script
<BLANKLINE> <BLANKLINE>
The service has been installed. If the buildout is run again with no changes, the serivce shouldn't be changed. The service has been installed. If the buildout is run again with no
changes, the serivce shouldn't be changed.
>>> print system(buildout) >>> print system(buildout)
buildout: Develop: /sample-buildout/recipes buildout: Develop: /sample-buildout/recipes
...@@ -903,7 +906,6 @@ re-installation. ...@@ -903,7 +906,6 @@ re-installation.
... [service] ... [service]
... recipe = recipes:service ... recipe = recipes:service
... script = /path/to/a/different/script ... script = /path/to/a/different/script
... uninstall = recipes:uninstall_service
... """) ... """)
>>> print system(buildout) >>> print system(buildout)
...@@ -943,7 +945,8 @@ uninstallation recipe can access files and directories created by a ...@@ -943,7 +945,8 @@ uninstallation recipe can access files and directories created by a
recipe before they are deleted. recipe before they are deleted.
For example, here's an uninstallation recipe that simulates backing up For example, here's an uninstallation recipe that simulates backing up
a directory. a directory before it is deleted. It is designed to work with the
mkdir recipe introduced earlier.
>>> write(sample_buildout, 'recipes', 'backup.py', >>> write(sample_buildout, 'recipes', 'backup.py',
... """ ... """
...@@ -954,7 +957,9 @@ a directory. ...@@ -954,7 +957,9 @@ a directory.
... print "backing up directory %s of size %s" % (path, size) ... print "backing up directory %s of size %s" % (path, size)
... """) ... """)
It must be registered with the zc.buildout.uninstall entry point. It must be registered with the zc.buildout.uninstall entry
point. Notice how it is given the name 'mkdir' to associate it with
the mkdir recipe.
>>> write(sample_buildout, 'recipes', 'setup.py', >>> write(sample_buildout, 'recipes', 'setup.py',
... """ ... """
...@@ -968,14 +973,12 @@ It must be registered with the zc.buildout.uninstall entry point. ...@@ -968,14 +973,12 @@ It must be registered with the zc.buildout.uninstall entry point.
... ...
... [zc.buildout.uninstall] ... [zc.buildout.uninstall]
... uninstall_service = service:uninstall_service ... uninstall_service = service:uninstall_service
... backup = backup:backup_directory ... mkdir = backup:backup_directory
... ''') ... ''')
... setup(name="recipes", entry_points=entry_points) ... setup(name="recipes", entry_points=entry_points)
... """) ... """)
Now we can use it with a part. It's necessary to pick a part that Now we can use it with a mkdir part.
defines a 'path' option, since that's what the uninstall recipe
expects.
>>> write(sample_buildout, 'buildout.cfg', >>> write(sample_buildout, 'buildout.cfg',
... """ ... """
...@@ -985,7 +988,6 @@ expects. ...@@ -985,7 +988,6 @@ expects.
... ...
... [dir] ... [dir]
... recipe = recipes:mkdir ... recipe = recipes:mkdir
... uninstall = recipes:backup
... path = my_directory ... path = my_directory
... ...
... [debug] ... [debug]
...@@ -1027,6 +1029,21 @@ is run before the directory is deleted. ...@@ -1027,6 +1029,21 @@ is run before the directory is deleted.
recipe recipes:debug recipe recipes:debug
<BLANKLINE> <BLANKLINE>
Now we will return the registeration to normal for the benefit of the
rest of the examples.
>>> write(sample_buildout, 'recipes', 'setup.py',
... """
... from setuptools import setup
... entry_points = (
... '''
... [zc.buildout]
... mkdir = mkdir:Mkdir
... debug = debug:Debug
... ''')
... setup(name="recipes", entry_points=entry_points)
... """)
Command-line usage Command-line usage
------------------ ------------------
...@@ -1128,7 +1145,8 @@ the buildout in the usual way: ...@@ -1128,7 +1145,8 @@ the buildout in the usual way:
>>> print system(buildout), >>> print system(buildout),
buildout: Develop: /sample-buildout/recipes buildout: Develop: /sample-buildout/recipes
buildout: Updating debug buildout: Uninstalling debug
buildout: Installing debug
recipe recipes:debug recipe recipes:debug
buildout: Installing d1 buildout: Installing d1
d1: Creating directory d1 d1: Creating directory d1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment