第一篇博文

直接开门见山的说了。

这是件什么事?:每次部署都是复制本地的文件粘贴到服务器端,因为路径复杂,所以费时且手工容易出漏洞。

一直在想有什么办法可以解决这种,因为以前在微软的一个牛人同事做过一个脚本实现自动化部署,正巧最近在学习python,就用python写一个自动化得脚本吧。

1.首先是环境:SVN的版本控制,windows的本地,linux服务器。

2.思路:应用python,代入cmd脚本,加上强大的python库来做这件事。

3.再详细的思路:

        第一步:利用SVN的cmd下得脚本,获取到对应版本修订号下修改log。用正则表达式取出修改后的文件名及路径

        第二步:因为是java程序,这样取出来的是xx.java文件,但需要部署上去的是编译后的xx.class文件,所以需要取到本地编译过后文件。

        第三步:安装python paramiko库.

        第四步:just build and run it

 __author__ = 'Administrator'
# coding:utf8
import os
import re url = "svn://192.168.30.111/ZXJY_ALL"
localPath = 'E:\quanli360\项目'
vision_num = raw_input('type a vision num: ') # 需要运行SVN的命令
svn_command = 'svn log ' + localPath + '\p2p_standard_2.0_quanli -r ' + vision_num + ' -v'
#转码让system执行得时候可以适应中文
svn_command = svn_command.decode("utf-8").encode("gbk")
print 'run shell is===', svn_command
#执行svn_command
a = os.popen(svn_command).read() print a
#正则取出版本号得更新文件路径
print "取出文件路径:"
def regPath(strPath):
reg = 'p2p_standard_2.0_quanli\\s*\\w*\\W*\\S*'
regCom = re.compile(reg)
pathList = re.findall(regCom, strPath)
#print pathList
return pathList res = regPath(a)
print '=='*60 def regPathC(strPath):
reg = '\\com\\\\s*\\w*\\W*\\S*'
regCom = re.compile(reg)
pathList = re.findall(regCom, strPath)
#print pathList
return pathList def regPathS(strPath):
reg = '\\site\\\\s*\\w*\\W*\\S*'
regCom = re.compile(reg)
pathList = re.findall(regCom, strPath)
#print pathList
return pathList #sftp命令上传至服务器,<目前只能先删除待更新文件,再上传文件过去>
import paramiko username = 'work'
password = 'Ex42tko4{G4NT@{^'
hostname = 'XXX.XXX.XXX.XXX'
port = 2022 def deployServer(locath, objPath):
try:
t = paramiko.Transport((hostname, port))
t.connect(username=username, password=password)
sftp = paramiko.SFTPClient.from_transport(t)
#rename
sftp.remove(objPath)
print 'Now start'
sftp.put(locath, objPath)
print 'good'
print '=='*60
t.close();
except Exception, e:
import traceback
traceback.print_exc()
try:
t.close()
except:
pass # 如果一个版本号下多个文件挨个取出并补全路径,执行部署
for x in range(len(res)):
realLocPath = localPath + '\\' + res[x]
realLocPath = realLocPath.replace("/", "\\")
print (realLocPath)
print '=='*60
if realLocPath.__contains__("\\com\\"):
cutStr = regPathC(realLocPath)
cutStr = ''.join(cutStr)
#匹配本地编译后的文件
cutStr = cutStr.replace(".java", ".class")
realLocPath = "E:\\apache-tomcat-6.0.37\\webapps\\archer\\WEB-INF\\classes\\" + cutStr
cutStrL = cutStr.replace("\\", "/")
objectPath = "/home/work/tomcat_instances/quanli360.com-instance-3/webapps/archer/WEB-INF/classes/" + cutStrL
print 'Source:-->',realLocPath
print 'Server:-->',objectPath
deployServer(realLocPath,objectPath)
elif realLocPath.__contains__("\\site\\"):
print 'start site'
cutStr = regPathS(realLocPath)
print cutStr
cutStr = ''.join(cutStr)
realLocPath = 'E:\\apache-tomcat-6.0.37\\webapps\\archer\\site' + cutStr
objectPath = '/home/work/tomcat_instances/quanli360.com-instance-3/webapps/archer/' + cutStr
cutStrL = cutStr.replace("\\", "/")
objectPath = '' + cutStrL
print cutStr,realLocPath, objectPath
# deployServer(realLocPath,objectPath)
else:
print ("no contains")
# deployLoc(realLocPath) print '=='*60

最新文章

  1. kafka 订单应用需求
  2. AX7: Quick and easy debugging
  3. 快速开发之代码生成器(asp.net mvc4 + easyui + knockoutjs)
  4. linux samba 服务配置及日志管理
  5. Web性能测试中的几个关键指标
  6. jquery笔记(仅供个人参考)
  7. 【原创】用JAVA实现大文件上传及显示进度信息
  8. spring 中的 RowMapper
  9. 泛型转Datatable
  10. 利用echo命令实现倒计时的功能
  11. spring mvc的跨域解决方案
  12. .NET Core使用微软官方类库实现汉字转拼音
  13. jpa 联合查询方法
  14. java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/HBaseConfiguration] with root cause
  15. 买了第一台mac
  16. PHP 网页数据api采集
  17. BZOJ1251序列终结者——非旋转treap
  18. angularJs中的checkboxs
  19. 理解套接字Socket
  20. git笔记:通过给grunt-inline打tag看tag操作

热门文章

  1. $x^2+y^2=c^2$
  2. [笔记]ng2的webpack配置
  3. [LeetCode] First Missing Positive 首个缺失的正数
  4. Hibernate 缓存机制浅析
  5. 开发 ASP.NET vNext 续篇:云优化的概念、Entity Framework 7.0、简单吞吐量压力测试
  6. GreenDao的使用
  7. Redis设计与实现读书笔记(一) SDS
  8. js小练习去掉指定的字符组成一句话输出
  9. 日历插件FullCalendar应用:(二)数据增删改
  10. SQL语句