copySea.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:CIDDS 作者: markusring 项目源码 文件源码
def copyRandomFile(fileNames, destination):

    # Select a random file 
    fileNameWithPath = fileNames[randint(0, len(fileNames)-1)]

    if platform.system() == "Linux":
        separator = "/"
    elif platform.system() == "Windows":
        separator = "\\"

    # If the file is copied to the VM, the MAC address (as an integer) is placed before the file names
    # -> Avoid deadlocks when copying to the server
    if "localstorage" in destination:
        localFileName = str(getnode()) + "-" + fileNameWithPath.split(separator)[-1]
    else:
        localFileName = fileNameWithPath.split(separator)[-1]

    # Path to the corresponding drive and filename
    dstWithFileName = destination + localFileName

    # Copy file 
    try:
        copyfile(fileNameWithPath, dstWithFileName)
        echoC(__name__, "Copied file " + localFileName + " to " + destination)
    except Exception as e:
        echoC(__name__, "copyfile() with destination " + destination + " error: " + str(e))
        return -1

    # copyfile() is not blocking 
    time.sleep(random.randint(15, 300))
    return 0

# Select a file and copy it to the VM or the file server
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号