#!/usr/bin/ptyhon#coding:utf-8class svncmd (object): #初始化属性 ,svnpath is the full path of 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 ] &nbsP; 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快速回退上一个版本, full version review, not temporary rollback 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
SVN call script (-)