Created
May 13, 2011 23:57
-
-
Save brainsik/971526 to your computer and use it in GitHub Desktop.
sudo -H for Fabric
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fabric.api | |
from contextlib import contextmanager | |
@contextmanager | |
def shell(new_shell): | |
old_shell, env.shell = env.shell, new_shell | |
yield | |
env.shell = old_shell | |
def sudo(*args, **kwargs): | |
if not kwargs.get('use_home', True): | |
return fabric.api.sudo(*args, **kwargs) | |
# simulate 'sudo -H' | |
user = kwargs.get('user', 'root') | |
with shell("HOME=~%s %s" % (user, env.shell)): | |
return fabric.api.sudo(*args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment