Skip to content

Instantly share code, notes, and snippets.

@ohtomi
Created July 5, 2018 17:30
Show Gist options
  • Save ohtomi/21b60ea7d302c9e350878246ca1d3fa7 to your computer and use it in GitHub Desktop.
Save ohtomi/21b60ea7d302c9e350878246ca1d3fa7 to your computer and use it in GitHub Desktop.
Fabric task function is wrapped by decorator.decorator
from invoke import task, context
from decorator import decorator
def ctask(f, *args, **kwds):
print('wraps')
if len(args) >= 1 and isinstance(args[0], context.Context):
print('context!')
print(args[0])
return
return f(*args, **kwds)
@task
@decorator(ctask)
def hello(c, name='tommy'):
"""this is hello"""
print(f'hello({name})')
fab hello
# wraps
# context!
# <Context: <Config: {'run': {'warn': False, 'hide': None, 'shell': '/bin/bash', 'pty': False, 'fallback': True, 'env': {}, 'replace_env': True, 'echo': False, 'encoding': None, 'out_stream': None, 'err_stream': None, 'in_stream': None, 'watchers': [], 'echo_stdin': None}, 'runners': {'local': <class 'invoke.runners.Local'>, 'remote': <class 'fabric.runners.Remote'>}, 'sudo': {'prompt': '[sudo] password: ', 'password': None, 'user': None}, 'tasks': {'dedupe': True, 'auto_dash_names': True, 'collection_name': 'fabfile', 'search_root': None}, 'connect_kwargs': {'key_filename': []}, 'forward_agent': False, 'gateway': None, 'load_ssh_configs': True, 'port': 22, 'ssh_config_path': None, 'timeouts': {'connect': None}, 'user': 'ohtomi'}>>
fab -l
# Available tasks:
#
# hello this is hello
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment