Skip to content

Instantly share code, notes, and snippets.

@guettli

guettli/gist:6972365

Created Oct 14, 2013
Embed
What would you like to do?
Switch user in fabric task
'''
with_... docs:
@task
def setup_new_system():
add_user() # executed as root
update_environ_of_user() # executed as user
'''
def with_user():
'''
Uses our custom system object: env.system.user
@task
@with_user()
def update_environ_of_user():
....
'''
def outer(func):
@wraps(func)
def inner(*args, **kwargs):
with settings(user=env.system.user):
return func(*args, **kwargs)
return _wrap_as_new(func, inner)
return outer
def with_root():
'''
@task
@with_root()
def add_user():
...
'''
def outer(func):
@wraps(func)
def inner(*args, **kwargs):
with settings(user='root'):
return func(*args, **kwargs)
return _wrap_as_new(func, inner)
return outer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment