公司经常添加SVN项目。相关领导发一个邮件,注明权限什么的, 然后按这个权限添加。
现在这个脚本,直接把附件的excel文件直接添加, 导入。
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
#!/usr/bin/python
import
xlrd
import
os
import
sys
import
tempfile
def
usage():
tmp
=
'''
useage:
./script excel_file [release username]
e.g.
./script abc.xls
./script abc-rel.xls xiao.mi
'''
print
tmp
shread
=
{
"xiaomi"
:
"xiao.mi"
,
"lishi"
:
"lishi"
}
if
os.getuid() !
=
0
:
print
"Non Root User!"
sys.exit(
1
)
if
len
(sys.argv) <
2
:
usage()
sys.exit(
1
)
if
not
os.path.isfile(sys.argv[
1
]):
print
"File Is Not Exist"
sys.exit(
1
)
file_type
=
int
(os.popen(
"file %s | grep Excel | wc -l"
%
sys.argv[
1
]).read())
if
file_type !
=
1
:
print
"File Is Not EXCEL FILE!"
sys.exit(
1
)
if
not
sys.argv[
-
1
]
in
shread.values():
print
"User Not Exist"
sys.exit(
1
)
data
=
xlrd.open_workbook(sys.argv[
1
])
table
=
data.sheets()[
0
]
svn_name
=
sys.argv[
1
].split(
'.'
)[
0
].upper()
svn_home
=
"/local_home/svn/"
svn_auth
=
"/etc/apache2/%s.authz"
%
svn_name
dav_svn
=
"/etc/apache2/mods-enabled/dav_svn.conf"
svn_tmp
=
tempfile.mkdtemp()
auth
=
'''
[groups]
shread = %s
[%s:/]
test = rw
@shread = r
* =
'''
%
(
","
.join(shread.values()), svn_name)
print
"svn name is %s"
%
svn_name
if
raw_input
(
"Are You Sure Add This SVN? [y|n] \n"
) !
=
'y'
:
sys.exit(
0
)
if
list
(
set
(table.col_values(
2
)))
=
=
['']:
os.makedirs(svn_tmp
+
"/"
+
svn_name
+
"/branches"
)
os.makedirs(svn_tmp
+
"/"
+
svn_name
+
"/tags"
)
os.makedirs(svn_tmp
+
"/"
+
svn_name
+
"/trunk"
)
auth
=
auth
+
'['
+
svn_name
+
':/branches]\n'
auth
=
auth
+
'%s = rw'
%
sys.argv[
-
1
]
else
:
for
i
in
xrange
(table.nrows):
tmp
=
table.row_values(i)
if
list
(
set
(tmp))
=
=
['']:
#blank row
next
else
:
if
tmp[
3
]
=
=
'':
rw
=
"rw"
else
:
if
u
"\u5199"
in
tmp[
3
]:
rw
=
"rw"
else
:
rw
=
"r"
#======================
if
shread.has_key(tmp[
2
].strip()):
tmp[
2
]
=
shread[tmp[
2
].strip()]
#======================
if
tmp[
0
]
=
=
tmp[
1
]
=
=
'':
next
elif
tmp[
0
]
=
=
'
' and tmp[1] != '
':
try
:
tmp[
0
]
=
row0
except
:
pass
svn_name
=
row0.split(
'/'
)[
0
]
svn_module
=
row0.replace(svn_name,'')
os.makedirs(svn_tmp
+
"/"
+
row0
+
"/"
+
tmp[
1
])
auth
=
auth
+
'['
+
svn_name
+
":"
+
svn_module
+
"/"
+
tmp[
1
]
+
"]\n"
auth
=
auth
+
tmp[
2
]
+
" = "
+
rw
+
"\n"
else
:
svn_name
=
tmp[
0
].split(
'/'
)[
0
]
svn_module
=
tmp[
0
].replace(svn_name,'')
row0
=
tmp[
0
]
if
tmp[
1
] !
=
'':
os.makedirs(svn_tmp
+
"/"
+
tmp[
0
]
+
"/"
+
tmp[
1
])
auth
=
auth
+
'['
+
svn_name
+
":"
+
svn_module
+
"/"
+
tmp[
1
]
+
"]\n"
auth
=
auth
+
tmp[
2
]
+
" = "
+
rw
+
"\n"
else
:
os.makedirs(svn_tmp
+
"/"
+
tmp[
0
])
auth
=
auth
+
'['
+
svn_name
+
":"
+
svn_module
+
"]\n"
auth
=
auth
+
tmp[
2
]
+
" = "
+
rw
+
"\n"
def
wirte_file(filename,content,arg):
f
=
open
(filename, arg)
f.write(content)
f.close()
apache_dav
=
'''
<Location /svn/%s>
DAV svn
SVNPath /local_home/svn/%s
AuthType Basic
AuthName "Subversion %s"
AuthBasicProvider ldap file
AuthzLDAPAuthoritative off
AuthLDAPURL "ldap://fw.163.net:389/ou=People,dc=163,dc=net?uid?sub?(objectClass=*)"
AuthzSVNAccessFile /etc/apache2/%s.authz
#AuthUserFile /etc/apache2/%s.passwd
Require valid-user
</Location>
'''
%
(svn_name,svn_name,svn_name,svn_name,svn_name)
os.system(
"svnadmin create %s"
%
(svn_home
+
svn_name))
os.system(
"chown -R www-data:subversion %s"
%
svn_home)
os.system(
"chmod -R g+rws %s"
%
(svn_home
+
svn_name))
wirte_file(dav_svn,apache_dav,
'a'
)
wirte_file(svn_auth,auth,
'w'
)
os.system(
"/etc/init.d/apache2 restart"
)
os.chdir(svn_tmp)
os.system(
"svn co http://%s.163.net/svn/%s --username=test --password=%s --no-auth-cache"
%
(
str
.lower(svn_name),svn_name,
"123123"
))
os.chdir(
"./"
+
svn_name)
folder
=
" "
.join(os.listdir(
'.'
))
os.system(
"svn add %s"
%
folder)
os.system(
"svn ci %s -m 'create by test' --username=test --password=%s --no-auth-cache"
%
(folder,
"123123"
))
os.chdir(
"/tmp"
)
os.system(
'rm -rf $(ls -1 /tmp | grep -E "tmp[a-zA-Z0-9]{6}")'
)
print
"SVN ADD OK"
|
excel文件格式
目录 子目录 人员 权限
ABC/Code test xiaomi 读写
如果excel第三列都是空的, 则添加 release 版本
CentOS svn 使用本地用户认证
1
2
3
4
5
6
|
yum
install
httpd-devel mod_dav_svn pwauth
# install mod-auth-external
# github.com/phokz/mod-auth-external/releases
# 解压后
apxs -c mod_authnz_external.c
apxs -i -a mod_authnz_external.la
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
cat
/etc/httpd/conf
.d
/svn
.conf
AddExternalAuth pwauth
/usr/bin/pwauth
SetExternalAuthMethod pwauth pipe
<Location
/svn/PROJECT
>
DAV svn
SVNPath
/disk2/svn/PROJECT
AuthType Basic
AuthName
"Subversion PROJECT"
AuthzSVNAccessFile
/etc/httpd/PROJECT
.authz
AuthBasicProvider external
AuthExternal pwauth
Require valid-user
<
/Location
>
|
本文转自 nonono11 51CTO博客,原文链接:http://blog.51cto.com/abian/1589082,如需转载请自行联系原作者