paver-fabric integration

36 views
Skip to first unread message

Aureliano Calvo

unread,
Jun 17, 2011, 10:40:45 AM6/17/11
to pa...@googlegroups.com
I did a small hack and now I can run paver tasks for a list of hosts using all the fabric API.

from fabric import state, network
def multi_host(f):
    """\
Run the decorated function for each host in options.get("host_strings").

Will use the private key set in options.pk if set.
"""
    def decoratee(options):
        for host_string in options.get("host_strings"):
            network.interpret_host_string(host_string)
            pk = options.get("pk", None)
            state.env.key_filename = [pk] if pk else None
            f(options)
           
    decoratee.func_name = f.func_name
           
    return cmdopts((
        ("pk=", None, "Private key file"),
    ))(decoratee)

This decorator runs the decorated function to run in all the host strings (as defined in fabric) in the array at options.get("host_strings"), enabling multi-host paver tasks.

Maybe someone finds this useful, I've published the details in my blog (link: http://aurelianito.blogspot.com/2011/06/integracion-paver-fabric.html). Feel free to use it.

This code (or variations of it) can also be included in future versions of paver if the maintainer(s) feel that is a good idea.


Happy hacking,
Aureliano.

Almad

unread,
Jun 18, 2011, 12:15:12 PM6/18/11
to pa...@googlegroups.com
Hi,

2011/6/17 Aureliano Calvo <aurelia...@gmail.com>:


> This decorator runs the decorated function to run in all the host strings
> (as defined in fabric) in the array at options.get("host_strings"), enabling
> multi-host paver tasks.
>
> Maybe someone finds this useful, I've published the details in my blog
> (link:
> http://aurelianito.blogspot.com/2011/06/integracion-paver-fabric.html). Feel
> free to use it.
>
> This code (or variations of it) can also be included in future versions of
> paver if the maintainer(s) feel that is a good idea.

when I thought about fabric integration, I was thinking more about
extracting paver tasks from fabric fabfiles.

However, this is neat idea and I think we should definitely add it into 1.1.

Opened #18 for it, I'll take a look on it next week.

> Happy hacking,
> Aureliano.

Thanks,

Almad

Aureliano Calvo

unread,
Jun 18, 2011, 1:16:39 PM6/18/11
to pa...@googlegroups.com
Great! :D 

Aureliano Calvo

unread,
Jun 18, 2011, 2:28:33 PM6/18/11
to pa...@googlegroups.com
I ve been thinking that you can just import the fabfile and then, use multihost to generate a paver task:

from fabfile import my_fab_task
my_fab_task = multihost(my_fab_task)

This should be good enough for lots of uses.


Reply all
Reply to author
Forward
0 new messages