天天看點

fabric帶顔色的輸出類(color)

1.調用方法:

from fabric import colors

2.方法:

    print colors.blue(string) #藍

    print colors.red(string)  #紅

    print colors.cyan(string) #淺藍

    print colors.green(string)#綠

    print colors.magenta(string)#紫

    print colors.white(string)#白

    print colors.yellow(string)    #黃

3.練習:

#!/bin/env python2.7

#-*-coding:utf-8-*-

def color(color_type='blue',string='nimei'):

  if color_type=='blue':

    print colors.blue(string)

    return colors.blue(string)

  elif color_type=='red':

    print colors.red(string)

    return colors.red(string)

  elif color_type=='cyan':

    print colors.cyan(string)

    return colors.cyan(string)

  elif color_type=='green':

    print colors.green(string)

    return colors.green(string)

  elif color_type=='magenta':

    print colors.magenta(string)

    return colors.magenta(string)

  elif color_type=='white':

    print colors.white(string)

    return colors.white(string)

  elif color_type=='yellow':

    print colors.yellow(string)

    return colors.yellow(string)

  else:

    print '''

          需要輸入兩個參數,一個是顔色(color_type):(blue|red|cyan|green|magenta|white|yellow).

          另一個是任意字元串(string)

          '''

    return None

@hosts('192.168.1.219')

def test(string):

  with settings(warn_only=True):

    status= run(string)

    if status.succeeded:

      color('green','ok')

    else:

      color('red','error')

#執行

#fab -f colors.py color    

#fab -H 192.168.1.219 -f colors.py test:'abc'

#fab -H 192.168.1.219 -f colors.py test:'touch /tmp/dir/1'

本文轉自 msj0905 51CTO部落格,原文連結:http://blog.51cto.com/sky66/1684902

繼續閱讀