#!/usr/bin/evn python
#encoding=utf-8
#author:eguotangseng@163.com
import sys
import os
import shutil
import commands
import time
import subprocess
#获得svn分支地址,根据目录判断是checkout还是update
svn_address = sys.argv[1]
branch_dirname = svn_address.split(‘/‘)[-1]
exist_dirname = ‘/soft/tagsoft/%s‘ % (branch_dirname)
svn_checkout = ‘svn checkout %s /soft/tagsoft/%s --username xxxxxxx‘ % (svn_address,branch_dirname)
svn_update = ‘svn update %s‘ % (exist_dirname)
if os.path.exists(exist_dirname):
os.system(svn_update)
else:
os.system(svn_checkout)
#获得要打包的工程,使用逗号分隔。cms,dms,pro 根据工程名重写pom.xml文件
parameter_argv = sys.argv[2]
parameter_argv_name = parameter_argv.split(‘,‘)
parameter_argv_option = ‘‘
for parameter_argv_list in parameter_argv_name:
parameter_argv_option += ‘ <module>../xxxx-%s</module> \n‘ % (parameter_argv_list)
shutil.copyfile(r‘/soft/tagsoft/cms-pom.xml‘,‘/soft/tagsoft/parameter_pom.xml‘)
#查找特定行进行内容替换
with open(‘/soft/tagsoft/parameter_pom.xml‘,‘r‘) as fd:
lines = fd.readlines()
with open(‘/soft/tagsoft/parameter_pom.xml‘,‘w‘) as f_w:
for line in lines:
if ‘qwerty‘ in line:
line = line.replace(‘qwerty‘,parameter_argv_option)
f_w.write(line)
cmd_mv = ‘mv /soft/tagsoft/parameter_pom.xml %s/jzjz-parent/pom.xml‘ % (exist_dirname)
os.system(cmd_mv)
cmd_cd = ‘%s‘ % (exist_dirname)
os.chdir(cmd_cd)
os.system(‘mvn clean package -DtestSkip -P test‘)
#获得tomcat路径准备打包的tomcat工程
tomcat_home_dirname = sys.argv[3]
kill_pid = "ps -ef | grep %s | grep -v grep| grep -v python | awk ‘{print $2}‘ | xargs kill -9" % (tomcat_home_dirname)
subprocess.Popen(kill_pid,stdout=subprocess.PIPE,shell=True)
#删除指定目录内容,先删除然后新建文件夹
rm_war = ‘%s/webapps/‘ % (tomcat_home_dirname)
shutil.rmtree(rm_war)
os.mkdir(rm_war)
for parameter_argv_list in parameter_argv_name:
parameter_argv_list_copy1 = ‘%s/jzjz-%s/target/%s.war‘ % (exist_dirname,parameter_argv_list,parameter_argv_list)
parameter_argv_list_copy2 = ‘%s/webapps/‘ % (tomcat_home_dirname)
shutil.copy(parameter_argv_list_copy1,parameter_argv_list_copy2)
print ‘拷贝%s到%s‘ % (parameter_argv_list,tomcat_home_dirname)
start_tomcat_cmd = ‘nohup %s/bin/startup.sh & ‘ % (tomcat_home_dirname)
subprocess.Popen(start_tomcat_cmd,stdout=subprocess.PIPE,shell=True)
本文出自 “学习交流” 博客,请务必保留此出处http://725689.blog.51cto.com/715689/1931193
原文地址:http://725689.blog.51cto.com/715689/1931193