1 __author__ = 'Administrator'
2 #coding:utf8
3 importos4 importre5
6 url = "svn://192.168.30.111/ZXJY_ALL"
7 localPath = 'E:\quanli360\项目'
8 vision_num = raw_input('type a vision num:')9
10 #需要运行SVN的命令
11 svn_command = 'svn log' + localPath + '\p2p_standard_2.0_quanli -r' + vision_num + '-v'
12 #转码让system执行得时候可以适应中文
13 svn_command = svn_command.decode("utf-8").encode("gbk")14 print 'run shell is===', svn_command15 #执行svn_command
16 a =os.popen(svn_command).read()17
18 printa19 #正则取出版本号得更新文件路径
20 print "取出文件路径:"
21 defregPath(strPath):22 reg = 'p2p_standard_2.0_quanli\\s*\\w*\\W*\\S*'
23 regCom =re.compile(reg)24 pathList =re.findall(regCom, strPath)25 #print pathList
26 returnpathList27
28 res =regPath(a)29 print '=='*60
30
31 defregPathC(strPath):32 reg = '\\com\\\\s*\\w*\\W*\\S*'
33 regCom =re.compile(reg)34 pathList =re.findall(regCom, strPath)35 #print pathList
36 returnpathList37
38 defregPathS(strPath):39 reg = '\\site\\\\s*\\w*\\W*\\S*'
40 regCom =re.compile(reg)41 pathList =re.findall(regCom, strPath)42 #print pathList
43 returnpathList44
45 #sftp命令上传至服务器,
46 importparamiko47
48 username = 'work'
49 password = 'Ex42tko4{G4NT@{^'
50 hostname = 'XXX.XXX.XXX.XXX'
51 port = 2022
52
53
54 defdeployServer(locath, objPath):55 try:56 t =paramiko.Transport((hostname, port))57 t.connect(username=username, password=password)58 sftp =paramiko.SFTPClient.from_transport(t)59 #rename
60 sftp.remove(objPath)61 print 'Now start'
62 sftp.put(locath, objPath)63 print 'good'
64 print '=='*60
65 t.close();66 exceptException, e:67 importtraceback68 traceback.print_exc()69 try:70 t.close()71 except:72 pass
73
74 #如果一个版本号下多个文件挨个取出并补全路径,执行部署
75 for x inrange(len(res)):76 realLocPath = localPath + '\\' +res[x]77 realLocPath = realLocPath.replace("/", "\\")78 print(realLocPath)79 print '=='*60
80 if realLocPath.__contains__("\\com\\"):81 cutStr =regPathC(realLocPath)82 cutStr = ''.join(cutStr)83 #匹配本地编译后的文件
84 cutStr = cutStr.replace(".java", ".class")85 realLocPath = "E:\\apache-tomcat-6.0.37\\webapps\\archer\\WEB-INF\\classes\\" +cutStr86 cutStrL = cutStr.replace("\\", "/")87 objectPath = "/home/work/tomcat_instances/quanli360.com-instance-3/webapps/archer/WEB-INF/classes/" +cutStrL88 print 'Source:-->',realLocPath89 print 'Server:-->',objectPath90 deployServer(realLocPath,objectPath)91 elif realLocPath.__contains__("\\site\\"):92 print 'start site'
93 cutStr =regPathS(realLocPath)94 printcutStr95 cutStr = ''.join(cutStr)96 realLocPath = 'E:\\apache-tomcat-6.0.37\\webapps\\archer\\site' +cutStr97 objectPath = '/home/work/tomcat_instances/quanli360.com-instance-3/webapps/archer/' +cutStr98 cutStrL = cutStr.replace("\\", "/")99 objectPath = '' +cutStrL100 printcutStr,realLocPath, objectPath101 #deployServer(realLocPath,objectPath)
102 else:103 print ("no contains")104 #deployLoc(realLocPath)
105
106 print '=='*60