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-*-
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 '''
          需要输入两个参数,一个是颜色(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

相关文章
|
开发框架 .NET 区块链
Hyperledger fabric部署链码(五)初始化与链码升级
fabric部署chaincode-go(智能合约)系列之五
182 0
|
测试技术 Go 区块链
Hyperledger fabric 测试环境部署
Hyperledger fabric 测试环境部署及相关问题解答
241 3
Hyperledger fabric 测试环境部署
|
JavaScript 测试技术 Go
Hyperledger fabric部署链码(一)打包链码
fabric部署chaincode-go(智能合约)系列之一
216 0
|
存储 JSON 安全
Hyperledger fabric智能合约编写(一)
本篇文章主要对链码编写的主要思路和部分API进行梳理。
161 1
|
区块链
Hyperledger fabric部署链码(二)安装链码到fabric
fabric部署chaincode-go(智能合约)系列之二
123 1
|
Go API 区块链
Hyperledger Fabric相关概念介绍
在学习Hyperledger Fabric的过程中,初步对相关概念的了解。
238 0
Hyperledger Fabric相关概念介绍
|
JSON 区块链 数据格式
Hyperledger fabric部署链码(四)提交链码定义到channel
fabric部署chaincode-go(智能合约)系列之四
|
测试技术 API 区块链
Hyperledger fabric部署链码(三)批准链码定义
fabric部署chaincode-go(智能合约)系列之三
117 0