首页 > 代码库 > svn添加项目脚本
svn添加项目脚本
公司经常添加SVN项目。相关领导发一个邮件,注明权限什么的, 然后按这个权限添加。
现在这个脚本,直接把附件的excel文件直接添加, 导入。
#!/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:/] bian = 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=bian --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 bian.wu‘ --username=bian --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 版本
svn添加项目脚本
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。