0

I am writing several task using Fabric 1.8

Since most of them are really similar, I wanted to do the following:

# Decorator for installation task
def install_task(test_task):
    def impl(install):
        def wrapper(*args, **kwargs):
            if not test_task():
                install()
            return test_task()
        return wrapper
    return impl

# Decorator for test task
def test_task(expected):
    def impl(test):
        def wrapper(*args, **kwargs):
            return expected in test()
        return wrapper
    return impl

# JAVA
@test_task('java version "1.7')
def test_java():
    return run('java -version')

@install_task(test_java)
def install_java():
    with sudo('apt-get purge openjdk*'):
        with sudo('apt-get install software-properties-common'):
            with sudo('add-apt-repository ppa:webupd8team/java'):
                with sudo('apt-get update'):
                    sudo('apt-get install oracle-java7-installer')

But when I try to run the task, I get:

Available commands:

    wrapper

Is Fabric compatible with custom parametric decorators?

lucabelluccini
  • 648
  • 6
  • 14

1 Answers1

0

You need to use python functools.wraps to wrap your decorator function. Look at this similar question.

Community
  • 1
  • 1
user931563
  • 94
  • 1
  • 5