Best way to add an environment variable in fabric?

后端 未结 5 1390
执笔经年
执笔经年 2020-12-29 01:38

I would like to pass a few values from fabric into the remote environment, and I\'m not seeing a great way to do it. The best I\'ve come up with so far is:

         


        
5条回答
  •  生来不讨喜
    2020-12-29 02:36

    Try using decorator

    from fabric.context_managers import shell_env
    from functools import wraps
    
    
    def set_env():
        def decorator(func):
            @wraps(func)
            def inner(*args, **kwargs):
                with shell_env(DJANGO_CONFIGURATION=env.config):
                    run("echo $DJANGO_CONFIGURATION")
                    return func(*args, **kwargs)
            return inner
        return decorator
    
    
    @task
    @set_env()
    def testme():
        pass
    

提交回复
热议问题