第一篇博文

直接开门见山的说了。

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

一直在想有什么办法可以解决这种,因为以前在微软的一个牛人同事做过一个脚本实现自动化部署,正巧最近在学习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

python+paramiko库+svn写的自动化部署脚本的更多相关文章

  1. centos7.2环境nginx+mysql+php-fpm+svn配置walle自动化部署系统详解

    centos7.2环境nginx+mysql+php-fpm+svn配置walle自动化部署系统详解 操作系统:centos 7.2 x86_64 安装walle系统服务端 1.以下安装,均在宿主机( ...

  2. 《转载》Jenkins持续集成-自动化部署脚本的实现《python》

    本文转载自慕课网 读者须知:1.本手记本着记续接前面的两张手记内容整理2.本手记针对tomcat部署测试环境实现 最近工作比较繁忙,导致这章一直拖延,没有太抽出时间来总结.要实现Jenkins端的持续 ...

  3. Jenkins+SVN+Maven+shell 自动化部署实践

      JAVA环境中利用Jenkins+svn+maven进行自动化部署实践   一. 前言2 1.介绍jenkins2 1.本地项目打包2 2.通过secureCRT工具,手动传输到服务器2 3.然后 ...

  4. Jenkins持续集成-自动化部署脚本的实现

    要实现Jenkins端的持续集成,其实在CI服务配置端很容易,难点呢?就是如何实现自动化的部署.我的脚本设计就是为了解决以下难题: 难点一.如何使得自动化部署脚本更通用 我用的脚本,依赖依赖一个配置文 ...

  5. 自动化部署脚本--linux执行sh脚本

    自动化部署脚本文件目录: 运行主程序:./install.sh #!/bin/bash SCRIPTPATH=$(cd "$(dirname "$0")"; p ...

  6. 设置ssh免密码登录脚本(hadoop自动化部署脚本一)

    设置ssh免密码登录脚本(hadoop自动化部署脚本一) 设置ssh免密码登录脚本(飞谷云大数据自动化部署脚本一) 1.#!/bin/sh2.#important note:this script i ...

  7. MySQL5.7多实例自动化部署脚本

    一.安装说明 ------------------------------------------------------ mysql5.7.10_onekey_install.sh自动化部署脚本支持 ...

  8. python os库的使用方法 + 自动化安装第三方库脚本

    一.os库基本介绍 os库提供通用的.基本的操作系统交互功能,包括windows.Mac os.linux os库是python标准库,包含几百个函数 常用路径操作.进程管理.环境参数等几类 路径操作 ...

  9. [MySQL-MM] 生产环境自动恢复MM中一台M2库的过程,分享从零开始写的自动化重建脚本以及思路 (转)

    必须是MM架构,而且一台主库M1是完好无损的,一台主库M2可以根据M1主库来进行重建:如果MS架构,自己可以稍微做一下脚本修改动作,也能使用,架构如下图所示: 3  总体思路,建立主脚本a_build ...

随机推荐

  1. 常用linux手头命令

    过滤ip ifconfig eth0|grep -oP "([0-9]{1,3}\.){3}[0-9]{1,3}"|sed -n '1p' ifconfig|sed -n '2p' ...

  2. [LeetCode] Read N Characters Given Read4 II - Call multiple times 用Read4来读取N个字符之二 - 多次调用

    The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actu ...

  3. [转]ExtJs基础--Html DOM、Ext Element及Component三者之间的区别

    要学习及应用好Ext框架,必须需要理解Html DOM.Ext Element及Component三者之间的区别. 每一个HTML页面都有一个层次分明的DOM树模型,浏览器中的所有内容都有相应的DOM ...

  4. php use memcached in ubuntu 14.04

    I assume you already had a lamp environment first step,we must to install memched in our Ubuntu Syst ...

  5. Power BI REST API

    Overview of Power BI REST API https://msdn.microsoft.com/en-us/library/dn877544.aspx 验证方式 OAuth 2.0 ...

  6. mysql-netstat

    在Linux服务器中想要查看连接到服务器的所有IP地址只需要输入命令netstat -an就可以看到全部的资料. 该命令的常见参数供您参考: -a (all)显示所有选项,默认不显示LISTEN相关: ...

  7. django用户认证

    利用django自带认证功能实现用户登录认证. views.py # Create your views here. from django.shortcuts import render_to_re ...

  8. asp.net页面生命周期

    Asp.Net页面生命周期 本文转载自:http://www.cnblogs.com/xhwy/archive/2012/05/20/2510178.html 一.什么是Asp.Net页面生命周期 当 ...

  9. POJ 1797 Heavy Transportation(最大生成树/最短路变形)

    传送门 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 31882   Accept ...

  10. 解决SmartGit序列号问题

    SmartGit过了30天试用期之后,就需要用户输入序列号才能继续使用,有一个办法可以跳过输入序列号. 一.windows+R  输入:%APPDATA%\syntevo\SmartGit 二.打开7 ...