The company often adds SVN projects. The relevant leader sends an email, notes the permission and so on, then adds by this permission.
Now this script directly adds the attached Excel file and imports it directly.
#!/usr/bin/python import xlrdimport osimport sysimport tempfiledef usage (): tmp = ' useage: ./script excel_file [release username] e.g. ./script abc.xls ./ script abc-rel.xls xiao.mi ' print tmpshread = { "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 _namedav_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_nameif 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&NBSP;=&NBSP;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 =&nbsP; " 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: &NBSP;&NBSP;&NBSP;&NBSP;TMP[0] = row0 except: pass svn_name = row0.split ('/ ') [0] svn_module = row0.replace (Svn_name, ') os.makedirs (svn_tmp + "/" + row0 + "/" &NBSP;+&NBSP;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 =&nbsP;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 file format
Directory subdirectory Staff permissions
Abc/code test Xiaomi Read and write
If the third column of Excel is empty, add release version
SVN Add Project Script