zoukankan      html  css  js  c++  java
  • 遍历jenkins build后的文件夹,找出最新“build NO.”复制到制定目录进行操作

    # -*- coding: utf-8 -*-
    import os
    import shutil
    import sys
    
    def UnZipFile(inputPath, outPath):
        _unZipPath = os.getcwd() + "\7-Zip\7z.exe "#原来输出成果物的进行了压缩,输出到指定的build里,所以我们要利用7z.exe来解压缩。需要调用此程序
        _param = "  x  " + inputPath + " -o"
        _param = _param + outPath
        _cmd = _unZipPath + _param
    
        print _cmd
        os.system(_cmd)
    
    def GetbiggestFolder(inputPath): #获取文件夹操作
    
       _maxPath = ""
       _maxNum = 0
       for folder in os.listdir(inputPath):
          _inputFolderPath = os.path.join(inputPath, folder)
          if os.path.isdir(_inputFolderPath):
             if str(folder).isdigit():
                if int(folder) > _maxNum :
                   _maxNum = int(folder)
                   _maxPath = _inputFolderPath
    
       return _maxPath
    
    def copyFile(_oldPath, _newPath):
            if os.path.exists(_newPath) is not True:
                    os.makedirs(_newPath)
            if os.path.isdir(_newPath):
                    shutil.copy(_oldPath, _newPath)
    
    def Usage(s = ""):
       print "Usage: unzip.py [source folder] [target folder]"
       if s:
          print s
          sys.exit(1)
    
    if __name__ == "__main__":
       """while True:
          g_InputPath = raw_input("Please input source folder path:")
          if g_InputPath.rfind('\') != -1:
             break
       
       while True:
          g_OutputPath = raw_input("Please input target folder path:")
          if g_OutputPath.rfind('\') != -1:
             break
       """
       argv = sys.argv
       i = 1
       iLen = len(argv)
       if len(argv) != 3:
          _errorInfor = "There should be 2 parameters, but you input " + str(iLen -1)
          Usage(_errorInfor)
       
       g_InputPath = argv[1]
       g_OutputPath = argv[2]
    
       _maxPath = GetbiggestFolder(g_InputPath)
       print _maxPath
    
       for _file in os.listdir(_maxPath):
         _inputFilePath = os.path.join(_maxPath, _file)
         if os.path.isfile(_inputFilePath):
             if _file.find('.7z') != -1 or  _file.find('.rar') != -1 or  _file.find('.zip') != -1:
                 print _inputFilePath
                 
                 UnZipFile(_inputFilePath, g_OutputPath)
                 copyFile(_inputFilePath, g_OutputPath)
  • 相关阅读:
    迷の“良心”膜你赛总结*3
    bzoj1704/poj3276[Usaco2007 Mar]Face The Right Way自动转身机
    poj 1840 -- Eqs
    poj 3274 -- Gold Balanced Lineup
    poj 3349 -- Snowflake Snow Snowflakes
    poj 2442 -- Sequence
    BestCoder Round #1 1002 项目管理 (HDU 4858)
    BestCoder Round #1 1001 逃生 (HDU 4857)
    poj 1273 -- Drainage Ditches
    poj 1149 -- PIGS
  • 原文地址:https://www.cnblogs.com/BUGU/p/5381933.html
Copyright © 2011-2022 走看看