2015-12-28 58 views
4

當我使用hide("everything")上下文管理器,並且結構任務失敗時,我仍然收到一條消息。該docs讀:Fabric的hide(「everything」)`實際上隱藏了什麼?

一切:包括警告,運行用戶和輸出(見上文)。因此,關閉一切時,你只會看到的輸出(只是狀態和調試最低限度,如果是on)以及您自己的打印語句。

但是,這不是嚴格對,對吧? - 我看到狀態,調試和中止消息。

如果我真的想隱藏一切,難道還有比一個更好的辦法:

with hide("aborts"), hide("everything"): 
    ... 

回答

4

有疑問時,看看源:

https://github.com/fabric/fabric/blob/master/fabric/context_managers.py#L98

這裏是實際申報。 everything是幾乎一切:warnings, running, user, output, exceptions

https://github.com/fabric/fabric/blob/master/fabric/state.py#L411

這只是圍繞output一個很好的包裝。坦率地說,我會堅持自己的內置的裝飾,因爲有改變的機會少,再加上你的更Python可讀碼的附加價值:

@task 
def task1(): 
    with hide('running', 'stdout', 'stderr'): 
     run('ls /var/www') 
     .... 

@task 
def task1(): 
    output['running'] = False 
    output['stdout'] = False 
    output['stderr'] = False 
    # or just output['everything'] = False 
    run('ls /var/www') 
    .... 

,但在一天結束時它是一樣的事情。

0

這是我一直使用:

from fabric.state import output 

output['everything'] = False 
相關問題