根据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
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。