Created
October 14, 2013 07:59
-
-
Save guettli/6972365 to your computer and use it in GitHub Desktop.
Switch user in fabric task
This file contains 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
''' | |
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