fabric好的写法

fabric好的写法

  • 过滤fabfile中 私有函数 和 不可调用的函数
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    bad:
    cmds = dict([n for n in filter(lambda n: (n[0][0] != '_') and callable(n[1]), locals().items())])
    new:
    COMMANDS = {}
    def load(filename, **kvargs):
    "Load up the given fabfile."
    execfile(filename)
    for name, obj in locals().items():
    if not name.startswith('_') and isinstance(obj, types.FunctionType):
    COMMANDS[name] = obj