#-*-coding:utf-8-*-ImportOSImportShutilImportSYSdefunzipfile (InputPath, Outpath): _unzippath= OS.GETCWD () +"\\7-Zip\\7z.exe"#原来输出成果物的进行了压缩, output to the specified build, so we're going to use 7z.exe to decompress. Need to call this program_param="x"+ InputPath +"- o"_param= _param +Outpath _cmd= _unzippath +_paramPrint_cmd Os.system (_cmd)defGetbiggestfolder (InputPath): #获取文件夹操作 _maxpath=""_maxnum=0 forFolderinchOs.listdir (InputPath): _inputfolderpath=Os.path.join (InputPath, folder)ifOs.path.isdir (_inputfolderpath):ifStr (folder). IsDigit ():ifInt (folder) >_maxnum: _maxnum=Int (folder) _maxpath=_inputfolderpathreturn_maxpathdefcopyFile (_oldpath, _newpath):ifOs.path.exists (_newpath) is notTrue:os.makedirs (_newpath)ifOs.path.isdir (_newpath): Shutil.copy (_oldpath, _newpath)defUsage (s =""): Print "Usage:unzip.py [source folder] [target folder]" ifS:Prints Sys.exit (1)if __name__=="__main__": """While True:g_inputpath = raw_input ("Please input source folder path:") if G_inputpath.rfind (' \ \ ')! =-1: Break When True:g_outputpath = Raw_input ("Please input target folder path:") if G_outputpath.rfind ( ' \ \ ')! = -1:break"""argv=SYS.ARGV i= 1Ilen=Len (argv)ifLen (argv)! = 3: _errorinfor="there should is 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_fileinchOs.listdir (_maxpath): _inputfilepath=Os.path.join (_maxpath, _file)ifOs.path.isfile (_inputfilepath):if_file.find ('. 7z')! =-1or_file.find ('. rar')! =-1or_file.find ('. zip')! =-1: Print_inputfilepath unzipfile (_inputfilepath, G_outputpath) copyFile (_inputfilepath, G_outputpath)
Traverse the folder after Jenkins build to find the latest "build NO." Copying to the development directory for operation