遍历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)

 

转载于:https://www.cnblogs.com/BUGU/p/5381933.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值