Created
October 22, 2014 09:16
-
-
Save kszarek/b9e99c6ea7f62a7a97ea to your computer and use it in GitHub Desktop.
fabric decorator
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
__author__ = 'Krzysztof Szarek' | |
from functools import wraps | |
from fabric.decorators import _wrap_as_new | |
from darwin.ec2 import _cloud_hosts | |
def _list_annotating_decorator(attribute, *values): | |
def attach_list(func): | |
@wraps(func) | |
def inner_decorator(*args, **kwargs): | |
return func(*args, **kwargs) | |
_values = values | |
if len(_values) == 1 and not isinstance(_values[0], basestring): | |
_values = _values[0] | |
setattr(inner_decorator, attribute, list(_values)) | |
inner_decorator = _wrap_as_new(func, inner_decorator) | |
return inner_decorator | |
return attach_list | |
def ec2hosts(running=True): | |
""" | |
Wraps the decorated function | |
""" | |
return _list_annotating_decorator('hosts', [_cloud_hosts(running)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment