zoukankan      html  css  js  c++  java
  • 通过中间服务器 将编译出来的镜像 传输到设备上

    #!/usr/bin/python
    
    import ConfigParser
    import sys
    import os
    
    
    conf = ConfigParser.ConfigParser()
    conf.read("/home/cc/.bin/config.ini")
    
    agent_ip = conf.get("agent", "agent_ip")
    agent_path = conf.get("agent", "agent_path")
    agent_name = conf.get("agent", "agent_name")
    
    
    def trans_file_to_agent(file_name):
        if None == file_name:
            print 'None == file name'
    
        cmd = 'scp ' + file_name + ' ' + agent_name+'@'+agent_ip+':'+agent_path
        print cmd
        os.popen(cmd)
    
    def sync_file_to_dev(file_name,ip):
        if None == ip:
            print 'None ==ip'
            exit(1)
        global conf
        try:
            user = conf.get(ip,'dev_user')
            path = conf.get(ip,'dev_path')
        except ConfigParser.NoSectionError:
            print 'Get info fail ' + ip
            exit(1)
    
        cmd_prefix = 'ssh ' + agent_name+'@'+agent_ip+' "'
    
        cmd_suffix = 'scp ' + file_name + ' ' + user+'@'+ip+':'+path + '"'
    
        cmd = cmd_prefix + cmd_suffix
        print cmd
    
        os.popen(cmd)
    
    
    
    if __name__ == '__main__':
        if 3 == len(sys.argv):
            print '------------------------------------------------------------'
            print 'trans file:' + sys.argv[1] + ' to ' + sys.argv[2] + ' by agent ' + agent_ip
            print '------------------------------------------------------------'
            trans_file_to_agent(sys.argv[1])
            print '------------------------------------------------------------'
            sync_file_to_dev(sys.argv[1],sys.argv[2])
            print '------------------------------------------------------------'
            print 'sync done'

    配置文件:

    [agent]
    agent_name=Administrator
    agent_path=/home/Administrator/
    agent_ip=10.190.14.57
    
    
    
    [60.60.12.101]
    dev_user=root
    dev_path=/mnt/cfdisk2/cc/
    [60.60.12.102]
    dev_user=root
    dev_path=/mnt/cfdisk2/cc/
    [60.60.60.105]
    dev_user=root
    dev_path=/mnt/cfdisk2/cc/
  • 相关阅读:
    leecode 91. 解码方法
    leecode 166. 分数到小数
    剑指 Offer 31. 栈的压入、弹出序列
    leecode 386. 字典序排数
    LeetCode 311 稀疏矩阵的乘法
    leecode 89. 格雷编码
    leecode 79. 单词搜索
    leecode 207. 课程表
    QT -- 解决:Error: Could not decode "*.cpp" with "UTF-8"
    VS+QT -- 没有PRO文件的问题
  • 原文地址:https://www.cnblogs.com/shaivas/p/5707344.html
Copyright © 2011-2022 走看看