根据SVN相关目录中的 .f 文件里面的内容来打包,并ci到另一个SVN,然后再发邮件给指定人员。
脚本如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#!/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
|
本文转自 nonono11 51CTO博客,原文链接:http://blog.51cto.com/abian/1363780,如需转载请自行联系原作者