windows/linux系统的本地文件拷贝到共享文件夹

windows系统:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import time
import shutil
# path = "e:/gaia_test/"+time.strftime("%Y%m%d_%H%M%S",time.localtime())
# os.makedirs(path) 创建带有时间的文件夹
# os.chdir(path) 要切换到的新路径
# #os.system("sh.exe")
# cmd = "git clone ssh://yangxue@10.63.11.154:29418/gaia"  直接下载git上的代码
# os.system(cmd)
def chkWPath():
    if  os.path.exists(r"w:/test_results"):
        return True
    else:
        res = os.system(r"net use w: \\robin\share\DMZ\for_test 123456a? /user:xue.yang") #\\robin\share\DMZ\for_test映射为w盘
        if res == 0:
            return True
        else:
            return False
if __name__ == "__main__":
    #copyto = r"W:/test_results/2019/04/2.txt"
    chkWPath() 
    shutil.copy("e:\\3d.txt",r"W:/fw_bin_with_tags/gaia")  #将3d.txt拷贝到共享文件的\\robin\share\DMZ\for_test\fw_bin_with_tags\gaia文件夹下

  linux系统:

#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import time
# path = "e:/gaia_test/"+time.strftime("%Y%m%d_%H%M%S",time.localtime())
# os.makedirs(path)
# os.chdir(path) 
# #os.system("sh.exe")
# cmd = "git clone ssh://yangxue@10.63.11.154:29418/gaia"
# os.system(cmd)

def chiptest():
    cmd = "sudo mount.cifs -o username=xue.yang,password=123456a? //10.63.11.245/share/DMZ/for_test/fw_bin_with_tags/gaia/gaia_tags /mnt/wind"  #将共享文件夹挂载到本地/mnt/wind文件夹下
    ret = os.system(cmd)
    if  ret!=0:
        print "Failed to create chiptest folder"
        os._exit(-1) #不在执行以下程序,直接退出程序
    if os.path.exists('/var/lib/jenkins/workspace/gaia_build_chiptest/ZU19EG_CHIP_TEST/output/'): #是否存在output文件夹
        chiptest_path = "chiptest_"+time.strftime("%Y%m%d_%H%M%S",time.localtime())
        #拷贝output文件夹到共享文件夹\\robin\share\DMZ\for_test\fw_bin_with_tags\gaia\gaia_tags\chiptest
        cp_chiptest = "sudo cp -r /var/lib/jenkins/workspace/gaia_build_chiptest/ZU19EG_CHIP_TEST/output/ /mnt/wind/chiptest/%s"%chiptest_path 
        cp_ret = os.system(cp_chiptest)
        if  cp_ret!=0:
            print "Failed to copy chiptest"
    else:
        print "No output folder exists"
    result = os.system("sudo umount /mnt/wind") #卸载,如果不卸载,执行fw挂载时,会报错
    if result!=0:
        print "umount fail"
        os._exit(-3)
def fw():
    cmd = "sudo mount.cifs -o username=xue.yang,password=123456a? //10.63.11.245/share/DMZ/for_test/fw_bin_with_tags/gaia/gaia_tags /mnt/wind" 
    ret = os.system(cmd)
    if  ret!=0:
        print "Failed to create fw folder"
        os._exit(-2)
    if os.path.exists('/var/lib/jenkins/workspace/gaia_build_fw/ZU19EG_FW/output/'):  
        fw_path = "fw_"+time.strftime("%Y%m%d_%H%M%S",time.localtime())
        cp_fw = "sudo cp -r /var/lib/jenkins/workspace/gaia_build_fw/ZU19EG_FW/output/ /mnt/wind/fw/%s"%fw_path
        cp_ret = os.system(cp_fw)
        if cp_ret!=0:
            print "Failed to copy fw"
    else:
        print "No output folder exists"
    result = os.system("sudo umount /mnt/wind")
    if result!=0:
        print "umount fail"
        os._exit(-4)
if __name__ == "__main__":
    chiptest()
    fw()

  

posted @ 2019-04-09 15:59  yangxueupc  阅读(626)  评论(0)    收藏  举报