根据SVN相关目录中的 .f 文件里面的内容来打包,并ci到另一个SVN,然后再发邮件给指定人员。
脚本如下:
#!/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
创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。
分享名称:Ruby_SVN打包脚本-创新互联
浏览路径:https://www.cdcxhl.com/article8/jspop.html
成都网站建设公司_创新互联,为您提供网站排名、移动网站建设、云服务器、微信公众号、静态网站、服务器托管
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联