1. Call Method:
From fabric import Colors
2. Method:
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. Practice:
#!/bin/env python2.7
#-*-coding:utf-8-*-
From fabric import Colors
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 ""
You need to enter two parameters, one is color (color_type):(blue|red|cyan|green|magenta|white|yellow).
The other is any 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 '
This article from "My Sky" blog, declined reprint!
Fabric color-colored output class (color)