pysvn安裝及常用方法


centos 6.5,svn 1.6.11,pysvn 1.7.6,文章內容來自官網文檔:http://pysvn.tigris.org/docs/pysvn_prog_guide.html

直接用yum安裝即可

yum install pysvn -y

創建一個client

import pysvn
def get_login(realm, username, may_save):
    retcode = True    #True,如果需要驗證;否則用False
    username = 'myuser'    #用戶名
    password = 'mypwd'    #密碼
    save = False    #True,如果想之后都不用驗證;否則用False
    return retcode, username, password, save
client = pysvn.Client()
client.callback_get_login = get_login

用這個client進行下面的各種操作

svnurl = 'svn://......'    #svn的路徑
outpath = './test'    #檢出到的目標路徑
client.checkout(svnurl, outpath)    #檢出最新版本
rv = pysvn.Revision(pysvn.opt_revision_kind.number, 1111))
client.checkout(svnurl, outpath, revision=rv)    #檢出指定版本
#Revision類型可以通過rv.number獲取對應的數字
entry = client.info('./test')
print entry.url    #拷貝對應的svn url
print entry.commit_revision    #最新提交的revision
print entry.commit_author    #最新提交的用戶
import time
t = time.localtime(entry.commit_time)    #最新提交的時間
print time.strftime('%Y-%m-%d %H:%M:%S', t)
entries_list = client.ls('./other')
for en in entries_list:
    print en.name,en.size,en.time,en.last_author    #文件屬性
    print en.created_rev    #文件的revision
    print en.kind    #文件類型,file,dir,none,unknown 可以通過str(kind)=='file'判斷
client.update('./test')    #更新
changes = client.status('./test')  #檢測狀態,獲取各種新增、刪除、修改、沖突、未版本化的狀態
for f in changes:
    if f.text_status == pysvn.wc_status_kind.added:
        print f.path,'A'
    elif f.text_status == pysvn.wc_status_kind.deleted:
        print f.path,'D'
    elif f.text_status == pysvn.wc_status_kind.modified:
        print f.path,'M'
    elif f.text_status == pysvn.wc_status_kind.conflicted:
        print f.path,'C'
    elif f.text_status == pysvn.wc_status_kind.unversioned:
        print f.path,'U'
tmppath = '/tmp'    #對比需要使用臨時文件,這個是臨時文件的位置,會自動清除
print client.diff(tmppath, './svntest')    #效果與svn diff一致
client.add('./svntest/add.txt')    #添加一個文件到版本控制
client.revert('./svntest/modify.txt')    #還原文件的修改
client.move('./svntest/move1.txt', './svntest/move2.txt')    #重命名或移動
client.remove('./svntest/delete.txt')    #刪除文件或目錄
client.mkdir('./svntest/testdir', '提交message') #新建一個文件夾,提交message這里沒用,當第一個參數是svnurl時直接提交才有用
 
         
client.checkin(['./svntest/delete.txt'], '提交message') #提交一個或多個修改
entries_list = client.log('./other', discover_changed_paths=True)
for en in entries_list:
    print en.author,en.date,en.message,en.revision    #版本信息
    for e in en.changed_paths:
        print '\t',e.path,e.action    #版本具體修改的信息

over


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM