#!/usr/bin/ptyhon #coding:utf-8 class SvnCmd(object): #初始化属性,svnpath 为svn的全路径。 def __init__(self,svnpath,tagname = ‘default‘): import commands import time self.svnpath = svnpath self.tagname = tagname self.time = str(time.asctime( time.localtime(time.time()))) #svn状态方法 def svnst(self): import os import commands os.chdir(self.svnpath) status,r = commands.getstatusoutput(‘/usr/bin/svn st‘)[0],commands.getstatusoutput(‘/usr/bin/svn st‘)[1] return status,r #svn预提交方法 def svnpreci(self): import os import commands os.chdir(self.svnpath) commands.getoutput(‘‘‘/usr/bin/svn st|grep -e ‘?‘ | awk ‘{print $2}‘|xargs svn add‘‘‘) commands.getoutput(‘‘‘/usr/bin/svn st|grep -e ‘!‘ | awk ‘{print $2}‘|xargs svn delete‘‘‘) status,r = commands.getstatusoutput(‘/usr/bin/svn st‘)[0],commands.getstatusoutput(‘/usr/bin/svn st‘)[1] return status,r #svn提交 def svnci(self): import os import commands s.chdir(self.svnpath) cmd_svnci = ‘‘‘/usr/bin/svn st|grep -e ‘M‘ -e ‘A‘ -e ‘D‘|/bin/awk ‘{print \$2}‘|xargs svn ci -m "svn ‘‘‘ + self.time + ‘_‘ + self.tagname + ‘"‘ print cmd_svnci commands.getoutput(cmd_svnci) #status,r = commands.getstatusoutput(‘/usr/bin/svn st‘)[0],commands.getstatusoutput(‘/usr/bin/svn st‘)[1] result = commands.getstatusoutput(‘/usr/bin/svn st‘) status,r = result[0],result[1] return status,r #svn更新 def svnupdate(self): import os import commands os.chdir(self.svnpath) #status,r = commands.getstatusoutput(‘/usr/bin/svn update‘)[0],commands.getstatusoutput(‘/usr/bin/svn update‘)[1] result = commands.getstatusoutput(‘/usr/bin/svn update‘) status,r = result[0],result[1] return status,r #svn版本号 def svnrevision(self): import os import commands os.chdir(self.svnpath) #status,r = commands.getstatusoutput(‘/usr/bin/svn info‘)[0], commands.getstatusoutput(‘/usr/bin/svn info‘)[1].split(‘\n‘)[6] result = commands.getstatusoutput(‘/usr/bin/svn info‘) status,r = result[0],result[1].split(‘\n‘)[6] return status,r #svn更新时间 def svnupdatetime(self): import os import commands os.chdir(self.svnpath) #status,r = commands.getstatusoutput(‘/usr/bin/svn info‘)[0], commands.getstatusoutput(‘/usr/bin/svn info‘)[1].split(‘\n‘)[-2] result = commands.getstatusoutput(‘/usr/bin/svn info‘) status,r = result[0],result[1].split(‘\n‘)[-2] return status,r #svn快速回退上一个版本,整个版本回顾,不是临时回滚 def svnrollback(self): import os import commands lately_reversion = int(self.svnrevision()[1].split(‘: ‘)[1]) last_reversion = int(lately_reversion) - 1 os.chdir(self.svnpath) rollcmd = ‘/usr/bin/svn merge -r ‘ + str(lately_reversion) + ‘:‘ + str(last_reversion) + ‘ .‘ print rollcmd result = commands.getstatusoutput(rollcmd) status,r = result[0],result[1] return status,r
时间: 2024-10-11 13:03:12