• copy2Output.py


    import shutil
    from DataCleaning.library.functions.changeDirectory import *
    import logging
    import datetime

    def copy2Output(outputFileName, storagePath, targetPath, rm = False, printLog = True):
    start = datetime.datetime.now()
    print("uploading: " + outputFileName)
    logging.info("uploading: " + outputFileName)
    if rm:
    task = ["remove", "removing", "removed"]
    else:
    task = ["copy", "copying", "copied"]
    tempInitMsg = task[1] + " " + outputFileName + " from " + storagePath + " to " + targetPath
    if printLog:
    print(tempInitMsg)
    logging.info(tempInitMsg)
    tempWd = os.getcwd()
    os.chdir(storagePath)
    try:
    if rm:
    shutil.move(outputFileName, targetPath)
    else:
    shutil.copy(outputFileName, targetPath + "\" + outputFileName)
    tempCompleteMsg = task[2] + " " + outputFileName + " from " + storagePath + " to " + targetPath
    if printLog:
    print(tempCompleteMsg)
    logging.info(tempCompleteMsg)
    except Exception as error:
    tempErrorMsg = "error occurred: file either does not exists in: " + storagePath + " or already exists in: " + targetPath
    if printLog:
    print(tempErrorMsg)
    print(error)
    logging.info(tempErrorMsg)
    os.chdir(tempWd)

    print("successfully uploaded: " + outputFileName)
    logging.info("successfully uploaded: " + outputFileName)
    end = datetime.datetime.now()
    tempTimeMsg = "time spent on copying/moving: " + str(end - start)
    if printLog:
    print(tempTimeMsg)
    logging.info(tempTimeMsg)
  • 相关阅读:
    sphinx-2.1.9的安装使用
    lnmp源码安装
    lvs的负载均衡测试
    Packet Tracer路由器简单配置
    虚拟机克隆系统
    虚拟机永久磁盘和非永久磁盘的应用
    虚拟机和物理机之间的传输的六种方法
    数据库系列(二)之 开发规则与优化
    数据库系列(一)之 底层
    IT之快速提高效率的方法与思考
  • 原文地址:https://www.cnblogs.com/zhulimin/p/15369450.html
Copyright © 2020-2023  润新知