公司的部署程序太多,每次部署安装完后,还得从SVN上对比版本,手工做实在太麻烦。
比如下面的一个版本
思路:
将需要检查的部件及安装的位置、SVN相关信息写入配置文件,然后程序读取配置文件
配置文件内容如下:
[server1] ipaddr=192.168.3.2 password=qqqqq port=22 dir=/home/gx/ ----##部件按装的位置 compent=sc,cag,ghomeAgent,IfTImg,Stream,TransDownload ---###服务器上安装的部件 [Server2] ipaddr=192.168.14.31 password=qqqqq port=22 dir=/home/gx/ compent=bms,bussinessAgent [SVN] svnserver=192.168.3.185 user=nenenen password=xxxx url=http://192.168.3.185/TM/VS/VSP/04_Build ~
因设计到公司内部的产品,代码屏蔽了一些东西:
#!/usr/bin/python #coding:utf-8 import paramiko import sys import subprocess import ConfigParser import os,time import re import urllib2 from urlparse import urlparse import unittest #从SVN获取组件及版本号 class snvparser(): aa={} def __init__(self,url,server,user,passwd): auth_handler = urllib2.HTTPBasicAuthHandler() auth_handler.add_password(realm='TM Repository', uri=server, user=user, passwd=passwd) self.opener = urllib2.build_opener(auth_handler) urllib2.install_opener(self.opener) self.url=url #print self.url a=self.opener.open(self.url) data=a.read() patten='href="(w*?)/"' self.compentlist=re.findall(patten,data) #print self.compentlist if 'mvp' in "".join(self.compentlist) or 'GXVCP' in ''.join(self.compentlist): urldd = urlparse(self.url) result=urldd.path.split('/')[-1] self.compentlist.sort(reverse=True) #print self.compentlist #print self.compentlist[0] self.aa[result]=self.compentlist[0] else: for self.subb in self.compentlist: #print self.subb #print '-'*50 self.suburl=self.url+'/'+self.subb #print self.suburl self.openurl(self.suburl) def openurl(self,url): #self.url=url #print url a=self.opener.open(url) data=a.read() patten='href="(w*?)/"' self.compentlist=re.findall(patten,data) if 'mvp' in "".join(self.compentlist) or 'GXVCP' in ''.join(self.compentlist): urldd = urlparse(url) result=urldd.path.split('/')[-1] self.compentlist.sort(reverse=True) # print self.compentlist # print self.compentlist[0] self.aa[result]=self.compentlist[0] else: for self.subb in self.compentlist: #print self.subb #print '-'*50 self.suburl=url+'/'+self.subb #print self.suburl self.openurl(self.suburl) def result(self): return self.aa #配置文件判断及读取 config=ConfigParser.ConfigParser() if not os.path.exists('config.ini'): print "config.ini is not exists,please check it!!" exit(-1) config.read('config.ini') print print "You want to check follow Component:" print config.get('server1','compent') print config.get('Server2','compent') #SSH远程操作函数 def ssh2(ip,pt,pw,us,comm): try: ssh = paramiko.SSHClient() ssh.load_system_host_keys() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(ip,port=int(pt),username=us,password=pw) #for COMM in comm: stdin,stdout,stderr = ssh.exec_command(comm) print "The Installed Version is :", read = stdout.read() #print read compi=re.compile('Implementation-Version:(.*)') qq=re.search(compi,read).group(1) #print '======================' print "