for file in files: if not os.path.isfile(temp+"/"+file): print (temp+"/"+file) shutil.copyfile(root+"/"+file,temp+"/"+file) filePath=fileDir+tarRealName #停止安装目录下的node.js 进程 commend = nodeCommend %("stop",projectName+"*",projectName+"*",projectName+"*",projectName+"*") print "停止安装目录下的node.js 进程" print commend os.system(commend) print "结束关闭服务命令" time.sleep(5) # for root, dir, files in os.walk(install_home): # if projectName in root: # print root # shutil.rmtree(root) # for file in files: # if projectName in file: # os.remove(root + file) #删除旧的安装目录和tar.gz包 print "删除旧的安装目录" commend = "rm -fr %s%s" %(install_home,projectName+"*") time.sleep(5) print commend os.system(commend) shutil.copytree(filePath,install_home+tarRealName) time.sleep(10) tarName = tarRealName + ".tar.gz" tar = tarfile.open(fileDir+tarName,"w:gz") for root,dir,files in os.walk(filePath): kk = root.replace(fileDir,"")+"/" for file in files: fullpath = os.path.join(root,file) #,arcname=file tar.add(fullpath,arcname=kk+file) tar.close() # 复制tar.gz包到download_dir目录 os.makedirs(download_dir); msg = "复制到下载目录:"+download_dir; print msg shutil.copyfile(fileDir+ tarName, download_dir + "/" + tarName) #执行启动命令 # startcommend = "forever start --minUptime 1000 --spinSleepTime 1000 -l /home/appuser/app/%s/app.js" # startcommend = startcommend %(tarRealName,tarRealName,tarRealName,tarRealName) print "执行启动命令" print 'sh -x /home/jenkins/resin_jenkins/install/data_collect_init.sh start' os.system('sh -x /home/jenkins/resin_jenkins/install/data_collect_init.sh start') print "执行启动命令完成"
python 中tar打包
猜你喜欢
转载自jiandequn.iteye.com/blog/2366791
今日推荐
周排行