Well, I must admit I'm new to fabric and even python but I'm interested in doing it the right way, so... I want to decorate some of my tasks with a prepare
function which adds some vars to env
depending on those already given. Have a look:
from fabric.api import *
import fabstork.project.base as base
import fabstork.utils.drupal as utils
def prepare(task):
""" Decorator to set some additional environment variables """
def prepared(*args, **kwargs):
env.sites_folder = env.sites_folder if 'sites_folder' in env else 'default'
env.settings_file = "%s/www/sites/%s/settings.php" % (env.build_path, env.sites_folder)
# more to come
return task(*args, **kwargs)
return prepared
@task
@prepare
def push(ref='HEAD'):
"""
Deploy a commit to a host
"""
base.push(ref)
utils.settings_php()
utils.link_files()
utils.set_perms()
The above example fails for that push
is no task anymore, its not in the list of available tasks when doing a fab --list
at the command line. Omitting the decorator leads to a perfect task. What am I doing wrong?
from fabric.decorators import task
from functools import wraps
def custom_decorator(func):
@wraps(func)
def decorated(*args, **kwargs):
print "this function is decorated."
return func(*args, **kwargs)
return decorated
@task
@custom_decorator
def some_function():
print "this is function"
result:
# fab -l
>Available commands:
>
> some_function
# fab some_function
>this function is decorated.
>this is function
>
>Done.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With