您好,登錄后才能下訂單哦!
根據(jù)SVN相關(guān)目錄中的 .f 文件里面的內(nèi)容來打包,并ci到另一個SVN,然后再發(fā)郵件給指定人員。
腳本如下:
#!/usr/bin/ruby require 'net/smtp' require 'fileutils' require 'find' svn_server = "http://192.168.1.5/svn/TEST" to_mail = "/home/test/maillist.txt" #mail address list svn_tmp_dir = "/tmp/tmp." + rand(99999).to_s def mailer(mailadd,modules,comment,version,tar_name,size,ci_time) File.open(mailadd,'r').each {|dst| msgstr = <<END_OF_MESSAGE From: SVN <sync.svn@163.com> To: #{dst.chomp} Subject: SVN_Release Module: #{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) } end def usage help=<<EOF Usage: ./script ci path tar_name comment EOF puts help end def checkout(path,tmp_dir,ser) FileUtils.mkdir tmp_dir Dir::chdir(tmp_dir) `svn co "#{ser + path.split("TEST")[-1]}"` end def create_tar_list(tmp_dir) #get xxx.f file_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 list true_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) end def writefile(str,tmp_dir) aFile = File.new(tmp_dir + "/tar.list","w") aFile.puts str aFile.close end case 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 usage end
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。