¿Una manera fácil de suprimir la salida de la ejecución de la tela?
Estoy ejecutando un comando en la máquina remota:
remote_output = run('mysqldump --no-data --user=username --password={0} database'.format(password))
Me gustaría capturar la salida, pero no tener todo impreso en la pantalla. ¿Cuál es la forma más fácil de hacer esto?
25
2 answers
Suena como Administrar la sección de salida es lo que estás buscando.
Para ocultar la salida de la consola, intente algo como esto:
from __future__ import with_statement
from fabric.api import hide, run, get
with hide('output'):
run('mysqldump --no-data test | tee test.create_table')
get('~/test.create_table', '~/test.create_table')
A continuación se muestran los resultados de la muestra:
No hosts found. Please specify (single) host string for connection: 192.168.6.142
[192.168.6.142] run: mysqldump --no-data test | tee test.create_table
[192.168.6.142] download: /home/quanta/test.create_table <- /home/quanta/test.create_table
31
Author: quanta,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-03-08 17:20:21
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-03-08 17:20:21
Pruebe esto si desea ocultar todo del registro y evitar excepciones de lanzamiento de tela cuando falla el comando:
from __future__ import with_statement
from fabric.api import env,run,hide,settings
env.host_string = 'username@servernameorip'
env.key_filename = '/path/to/key.pem'
def exec_remote_cmd(cmd):
with hide('output','running','warnings'), settings(warn_only=True):
return run(cmd)
Después de eso, puede comprobar el resultado de los comandos como se muestra en este ejemplo:
cmd_list = ['ls', 'lss']
for cmd in cmd_list:
result = exec_remote_cmd(cmd)
if result.succeeded:
sys.stdout.write('\n* Command succeeded: '+cmd+'\n')
sys.stdout.write(result+"\n")
else:
sys.stdout.write('\n* Command failed: '+cmd+'\n')
sys.stdout.write(result+"\n")
Esta será la salida de consola del programa (observe que no hay mensajes de registro de fabric):
* Command succeeded: ls Desktop espaiorgcats.sql Pictures Public Videos Documents examples.desktop projectes scripts Downloads Music prueba Templates * Command failed: lss /bin/bash: lss: command not found
17
Author: cfillol,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-06-22 11:42:36
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-06-22 11:42:36