Ruby_SVN打包脚本
根据SVN相关目录中的 .f 文件里面的内容来打包,并ci到另一个SVN,然后再发邮件给指定人员。
脚本如下:
#!/usr/bin/rubyrequire 'net/smtp'require 'fileutils'require 'find'svn_server = "http://192.168.1.5/svn/TEST"to_mail = "/home/test/maillist.txt" #mail address listsvn_tmp_dir = "/tmp/tmp." + rand(99999).to_sdef mailer(mailadd,modules,comment,version,tar_name,size,ci_time)File.open(mailadd,'r').each {|dst|msgstr = <<END_OF_MESSAGEFrom: SVN <sync.svn@163.com>To: #{dst.chomp}Subject: SVN_ReleaseModule: #{modules}Comment: #{comment}Version: #{version}TarName: #{tar_name}TarSize: #{size}CiTime: #{ci_time}END_OF_MESSAGE acct = 'sync.svn@163.com' domain = "163.com" pass = '123123' Net::SMTP.start('smtp.163.com', 25, domain, acct, pass, :login) { |smtp| smtp.send_message msgstr,'sync.svn@163.com',dst.chomp } #Net::SMTP.start(server, port, domain, acct, passwd, authtype)}enddef usagehelp=<<EOFUsage: ./script ci path tar_name comment EOFputs helpenddef checkout(path,tmp_dir,ser) FileUtils.mkdir tmp_dir Dir::chdir(tmp_dir) `svn co "#{ser + path.split("TEST")[-1]}"`enddef create_tar_list(tmp_dir)#get xxx.ffile_path_name = []tar_list = []Find.find(tmp_dir) { |x| if File.basename(x) == x.split('/')[-2] + ".f" file_path_name << x else next end}#get need tar file listtrue_path = ''tmp_line = []file_path_name.length.times { |x| # file_path_name /tmp/svn_tmp_dir/RTL/include/include.f File.open(file_path_name[x],'r').each { |line| if line.strip.match(/^\/\//) # ^// next elsif line.strip.match(/^\.|^\w+/) if line.match(/\/\//) tmp_line = line.strip.split('//')[0].rstrip.split('/') else tmp_line = line.strip.split('/') end tmp_line.delete('.') tmp_line.delete('..') true_path = File.join((file_path_name[x].split('/')[3..-2] + tmp_line).uniq) tar_list << true_path if File.exist?(true_path) else next end }}writefile(tar_list.uniq,tmp_dir)enddef writefile(str,tmp_dir)aFile = File.new(tmp_dir + "/tar.list","w") aFile.puts straFile.closeendcase ARGV[0] when "ci" olddir = Dir.pwd if `[ -d .svn ] && grep "TEST-REL" .svn/* | wc -l`.to_i == 0 puts "Not SVN Work Dir OR Not SVN Release Work Dir" exit end #hwasvn ci TEST/Code TarName comment ARGV[1].match(/\/$/) ? path = ARGV[1][0..-2] : path = ARGV[1] checkout(path,svn_tmp_dir,svn_server) create_tar_list(svn_tmp_dir) Dir::chdir(svn_tmp_dir) tar_name = "#{ARGV[2]}.tar.bz2" `tar -jc -T tar.list -f #{tar_name}` FileUtils.mv tar_name, olddir Dir::chdir(olddir) result = `svn ci #{tar_name} -m "#{ARGV[3]}" 2>&1` if result.match(/not under/) `svn add #{tar_name}` result = `svn ci #{tar_name} -m "#{ARGV[3]}"` end mailer(to_mail,path,ARGV[3],result.split[-1][0..-2],tar_name,File.size(tar_name),Time.now.strftime("%Y/%m/%d %H:%M")) FileUtils.rm tar_name, :force => true FileUtils.remove_dir(svn_tmp_dir) else usageend
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。