Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import distutils.util
- import functools
- import inspect
- from fabric.decorators import task
- class bool_args(object):
- def __init__(self, *bool_arg_names):
- self.bool_arg_names = bool_arg_names
- def __call__(self, f):
- @functools.wraps(f)
- def wrapper(*args, **kwargs):
- callargs = inspect.getcallargs(f, *args, **kwargs)
- for k, v in callargs.viewitems():
- if k in self.bool_arg_names and not isinstance(v, bool):
- callargs[k] = bool(distutils.util.strtobool(v))
- return f(**callargs)
- return wrapper
- @task
- @bool_args('my_bool_arg')
- def do_something(my_bool_arg=True):
- assert isinstance(my_bool_arg, bool)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement