[Distutils] [zc.buildout] running in safe mode

Ian Bicking ianb at colorstudy.com
Fri Oct 3 00:37:05 CEST 2008


Jim Fulton wrote:
> 
> On Oct 2, 2008, at 6:15 PM, Ian Bicking wrote:
> 
>> Jim Fulton wrote:
>>>> I know it is a bad practice for a recipe to return some paths that
>>>> contains important data in the install() method,
>>>> because zc.buildout might remove them.
>>>>
>>>> Nevertheless, it happens from time to time that a developer lose some
>>>> content because of a misconfiguration,
>>>> or a zealous recipe. That is his responsability, and backups are 
>>>> done for that.
>>> I don't think backups are the right approach.  It's a mistake to have 
>>> recipes manage precious data.  If you really really really think 
>>> that's a good idea, then the recipe should at least manage uninstall 
>>> and move precious data aside, rather than remove it.
>>> I don't think it is really the user's problem is a recipe misbehaves 
>>> by allowing precious data to be removed.
>>
>> I'll note fassembler uses a file abstraction layer so that its recipes 
>> are safe by default: 
>> https://svn.openplans.org/svn/fassembler/trunk/fassembler/filemaker.py
>>
>> I think buildout would be a lot more humane if it took the same approach.
> 
> 
> I'd be interested to know what you mean by this, but I'm not willing to 
> read that source to find out.
> 
> Can you be a little more specific?

Instead of using open(), etc, to write files, there's an instance of 
Maker which holds some of the settings (--interactive, --simulate, a 
base directory).  Then you do all your file operations like:

   maker.ensure_file('path/to/file.txt', content)

If that file exists with different content then the user gets asked 
about what to do.  It also logs all the writing, shows diffs, can make 
backups, etc.  You can force overwriting, but that's a keyword argument 
that defaults to False, so only if you actually have good reason to 
overwrite files (without asking) then that's fine, but you will start 
developing the easy way, which is to be safe about this stuff.

-- 
Ian Bicking : ianb at colorstudy.com : http://blog.ianbicking.org


More information about the Distutils-SIG mailing list