sebastien/cuisine — pull request #81 by jeethu (2012-06-08 08:56:30+00:00)
Title: Made file_attribs and dir_attribs consistent with the rest of the api

Hi Sebastien,
In pull request #78, I'd added a `run_or_sudo` function inside `file_attribs` which would call `sudo()` if the `run()` call fails. One issue with this approach was that the output would be cluttered with failure messages.

I think I've finally figured out a better solution. It makes to have an optional `use_sudo` argument like in many fabric api functions.cuisine uses a similar optional `sudo=None` argument in such cases. I've added this to both `file_attribs` and `dir_attribs` (which calls `file_attribs`). When called inside a `mode_sudo()` context, `run()` ends up calling `sudo()` anyway, otherwise by calling `file_attribs()` with `sudo=True`, has the same effect. Also, I've changed `file_write()` to pass its `sudo` argument to `file_attribs()`.

What do you think?