六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 48|回复: 0

2SVN目录间合并文件脚本

[复制链接]

升级  59.33%

116

主题

116

主题

116

主题

举人

Rank: 3Rank: 3

积分
378
 楼主| 发表于 2013-1-15 02:26:32 | 显示全部楼层 |阅读模式
之前写了一个SVN提交的脚本, 现在做一个脚本,是把开发环境的代码,合并到要测试的SVN目录中

#!/usr/bin/env python#coding:utf-8"""Author:rikugunSite: http://rikugun.iteye.com/拷贝文件,发布到正式环境TEST_CRM"""import optparseimport osimport reimport subprocessdef main():"""主函数"""def getInput(msg):"""获取用户输入,默认是NO"""return opts.quite or raw_input(msg) not in ['n','no']def sysexec(cmd):"""执行命令幷返回结果"""msg = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE).communicate()#[0].decode('utf-8')if msg[1] is not None:print u'=============== 错误信息====================='print msg[1].decode('utf-8')if opts.debug:print u'================执行命令==================='print cmdprint u'================我是分割线==================='print msg[0].decode('utf-8')print u'================命令完成==================='return msgopt = optparse.OptionParser("dsvn [-m comments] [-L listfile] filepath [other files]")opt.add_option("-m","--comments",help=u"提交的注释",default="commit to compile")opt.add_option("-L","--listfile",help=u"提交的文件列表")opt.add_option("-c","--usecopy",action="store_true",help=u"使用拷贝而不是合并")opt.add_option("-M","--mergetool",help=u"指定合并工具")opt.add_option("-q","--quite",action="store_true",help=u"安静模式,所有提示都选择Y")opt.add_option("-d","--debug",action="store_true",help=u"调试模式")opts,files = opt.parse_args()if len(files) == 0 and opts.listfile is None:print u'请输入要提交文件,或者文件列表'print opt.print_usage()print __doc__exit(2)if not files and opts.listfile:files = [line for line in open(opts.listfile,'r').readlines() if not line.startswith('#')]#获取环境变量# 开发环境dev_dir =os.getenv('CRM')# 本地编译目录test_dir = os.getenv('TEST_CRM')+os.sep+"TEST_"#源文件路径src_file_list =[]#目标文件路径dst_file_list = []add_dst_file_list = []reg = re.compile(dev_dir+os.sep+'(.+)$')#设置合并工具if opts.usecopy:if os.name =='nt':merge_cmd = 'copy /Y'else:merge_cmd='cp -arf'else:if opts.mergetool is not None:merge_cmd = opts.mergetoolelse:mergetool = "opendiff"#svn 提交命令svn_cmd = ['svn ci -m "%s"' % opts.comments,]#过滤文件名 如 CRM_TRANS/src/share/EssErrorTrans.txtfileset = set([reg.match(os.path.realpath(os.getcwd()+os.sep+it)).group(1).strip() for it in files])file_list = '\n'.join(fileset)# 传输文件,提交到TEST_CRM#ifopts.quite or raw_input('commit such files [\n%s\n] to TEST SVN ? (y)es/no :' % file_list) not in ['n','no'] :ifgetInput('commit such files [\n%s\n] to TEST SVN ? (y)es/no :' % file_list):forx in fileset:src_path = dev_dir+os.sep+xdst_path = test_dir+xsrc_file_list.append(src_path)dst_file_list.append(dst_path)sysexec(' '.join([merge_cmd,src_path,dst_path]))print dst_path#过滤新加的文件,需要额外执行svn add命令if not os.path.exists(dst_path):add_dst_file_list.append(dst_path)sysexec(' '.join(['svn up --force']+dst_file_list))if len(add_dst_file_list):sysexec(' '.join(['svn add']+add_dst_file_list))sysexec(' '.join(svn_cmd+dst_file_list))print u'脚本执行成功'if __name__ == "__main__":main()
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表