3

您如何控制自定义 Fabric 命令的公开方式?

我将命令组织在各种包中,例如:

mydomain
    __init__.py
    db.py
        @task
        def create()...

        @task()
        def dump()...

        @task
        def shell()...

当我运行时fab --list,我看到 Fabric 公开了我的命令,前缀为mydomain

mydomain.db.create
mydomain.db.dump
mydomain.db.shell

如何让 Fabric 删除mydomain前缀,同时仍将任务组织在我的自定义命名空间中?我尝试在 中指定名称@task(name=...),但这对命名空间没有影响。

4

1 回答 1

1

我有以下结构,它不以包名称为前缀。

fab --version
Fabric 1.8.0
Paramiko 1.12.0

rootdir/
     fabfile.py
     mydomain/
             __init__.py
             db.py
             other.py

工厂文件.py

from fabric.api import task
from mydomain import db, other

@task
def boom():
    print "boom"

数据库.py

from fabric.api import task

@task
def create():
    print "create"

@task()
def dump():
    print "dump"

其他.py

from fabric.api import task

@task
def do_stuff():
    print "doing stuff"

fab --list 输出

fab --list
Available commands:

    boom
    db.create
    db.dump
    other.do_stuff

我注意到,如果我用

import mydomain.db
import mydomain.other

那么输出是:

fab --list
Available commands:

    boom
    mydomain.db.create
    mydomain.db.dump
    mydomain.other.do_stuff

所以看看你是如何导入你的包的,这似乎是导致它的原因

于 2013-10-29T19:43:37.083 回答