wichert/collective.recipe.modwsgi — pull request #7 by jaap3 (2013-10-07 10:11:39+00:00)
Title: Handle broken symlinks when using the target option

I used to create symbolic links to the wsgi script created by collective.recipe.modwsgi. To avoid this I recently started using the target option. However the recipe fails with an IOError when it tries to open a symlink of which the target does not exist.

I've created a little script that recreates my situation:

```python
import os
from collective.recipe.modwsgi import Recipe

# Fake buildout
buildout = { 'buildout': { 'find-links': [], 'allow-hosts': '', 'eggs-directory': '', 'develop-eggs-directory': '' } }

# Fake options
class Options(dict):
def created(self, *args):
return
options = Options({'config-file': '', 'target': 'bin/test.wsgi', 'recipe': '' })

if not os.path.exists('parts'):
os.mkdir('parts')
if not os.path.exists('bin'):
os.mkdir('bin')
if os.path.lexists('bin/test.wsgi') or os.path.exists('bin/test.wsgi'):
os.unlink('bin/test.wsgi')
os.symlink('./parts/DOESNOTEXIST', './bin/test.wsgi')

r = Recipe(buildout, '', options)
r.install()
```

The attached patch first removes a broken symlink if the target option is used.