【转】Python定期从SVN更新文件

如果一个测试站点要及时的从svn获取最新的文件,那么写一个定期更新程序是非常必要的,下面的代码Python的简单实现

svnupdate.py

import  time,os,sys,svnconfig

dist
= svnconfig.setting[ ' dist ' ]
os.chdir(svnconfig.setting[
' svn ' ])

def  checkout():
    svnconfig.setting[
' dist ' ] = dist + time.strftime( ' %Y-%m-%d-%H-%M-%S ' ,time.localtime())
    cmd
= ' svn export %(url)s %(dist)s --username %(user)s --password %(pwd)s ' % svnconfig.setting
    
print   " execute %s " % cmd
    
# print os.popen(cmd).read()
     return  os.system(cmd)

while  True:
    ret
= checkout()
    
if (ret == 0):
        
print   ' check out success '
    
else :
        
print   ' check out fail '
    time.sleep(svnconfig.setting[
' interval ' ])

svnconfig.py

setting = {
    
' svn ' : ' C:/Program Files/Subversion/bin/ ' , # svn的程序所在路径
     ' url ' : ' http://www.xxx.com/svn/project/trunk ' , # svn地址
     ' user ' : ' xxx,#用户名
     ' pwd ' : ' xxx ' , # 密码
     ' dist ' : ' D:/svn/ ' , # 目标地址
     ' interval ' : 15   # 更新时间
}


可能是装了多个svn的缘故,直接用system('svn xx')命令执行失败,所以就先chdir到svn的目录下面,然后在执行svn命令

svn也有一个Python程序包,也可以直接使用,没有具体使用过。
svn以及python包的地址:
 http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91

http://blog.csdn.net/foyuan/article/details/1718615

上次在拉闷用ruby写,最终写的也蛮简便,有空在试试python

猜你喜欢

转载自miss678.iteye.com/blog/1748253