欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Pysvn 使用指南

 更新時(shí)間:2023年02月20日 08:38:41   作者:大付的博客  
本文主要介紹了Pysvn 使用指南,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

這是一篇關(guān)于pysvn模塊的指南.

完整和詳細(xì)的API請(qǐng)參考 http://pysvn.tigris.org/docs/pysvn_prog_ref.html

pysvn是操作Subversion版本控制的Python接口模塊. 這個(gè)API接口可以管理一個(gè)工作副本, 查詢檔案庫, 和同步兩個(gè).

該API不能創(chuàng)建新的倉庫; 只能作用在現(xiàn)有倉庫上. 如果你需要?jiǎng)?chuàng)建一個(gè)倉庫, 請(qǐng)使用Subversion的svnadmin命令.

使用這個(gè)API, 你可以check out一份工作拷貝, 添加, 編輯, 和刪除工作文件, 和check in, 比較, 或者放棄更改. 倉庫屬性, 如關(guān)鍵字?jǐn)U展, 行字符結(jié)束, 或者忽略的列表也可以檢查和控制.

Subversion 模型

Subversion是一個(gè)更新-編輯-提交的模型. 首先在本地建立一個(gè)工作副本. 在工作副本上進(jìn)行修改, 最后提交到中央倉庫 (可以是本地或者遠(yuǎn)程).

這個(gè)模型允許多人偶爾會(huì)同時(shí)修改同一個(gè)文件. 大多情況下. Subversion不會(huì)干預(yù)合并這些不同修改, 如果一個(gè)提交失敗, 用戶或者應(yīng)用則要重新檢查和修改然后再次提交.

常見任務(wù)

本節(jié)給出一些使用pysvn接口的常用例子. 業(yè)務(wù)可以會(huì)遞歸的處理目錄. 添加參數(shù)recurse=False以防止這種行為; 例如, 你可以需要添加內(nèi)容沒有增加一個(gè)目錄.

check out一份工作副本

import pysvn
client = pysvn.Client()
#check out the current version of the pysvn project
client.checkout('http://localhost/example/trunk',
    './examples/pysvn')
#check out revision 11 of the pysvn project
client.checkout('http://localhost/example/trunk',
   './examples/pysvn-11',
   revision=pysvn.Revision(pysvn.opt_revision_kind.number, 11))

這是一個(gè)建立example測試項(xiàng)目的例子,目錄是examples/pysvn. 這個(gè)項(xiàng)目是用在剩下的例子.

添加一個(gè)文件或者目錄到倉庫

import pysvn
# write a file foo.txt
f = file('./examples/pysvn/foo.txt', 'w')
f.write('Sample versioned file via pithon\n')
f.close()
client = pysvn.Client()
#schedule the addition;
#  the working copy will now track the file as a scheduled change
client.add('./examples/pysvn/foo.txt')
#committing the change actually adds the file to the repository
client.checkin(['./examples/pysvn/foo.txt'], 'Adding a sample file')

這個(gè)例子是在工作副本中創(chuàng)建了'foo.txt'文件, 然后添加到倉庫. 請(qǐng)注意Client.import_()命令會(huì)同時(shí)增加和提交. 大多數(shù)應(yīng)用, 會(huì)在許多修改后再提交.

更新工作副本

import pysvn
client = pysvn.Client()
client.update('./examples/pysvn')

從倉庫中更新其他用戶修改并保存到本地副本. 大多數(shù)應(yīng)用應(yīng)該經(jīng)常這樣做以防止沖突.

提交更新到倉庫

import pysvn
# edit the file foo.txt
f = open('./examples/pysvn/foo.txt', 'w')
f.write('Sample versioned file via python\n')
f.close()
# checkin the change with a log message
client = pysvn.Client()
client.checkin(['./examples/pysvn'], 'Corrected spelling of python in foo.txt')

提交到Subversion是原子的. 要么所有修改都成功提交, 要么提交失敗. 大部分應(yīng)用會(huì)提交工作副本所有修改, 如本例所示, 或者通過個(gè)別文件或者目錄, 但必須是同一單位.

放棄工作副本修改

import pysvn
# edit the file foo.txt
f = file('./examples/pysvn/foo.txt', 'w')
f.write('This change will never be seen\n')
f.close()
#discard the edits
client = pysvn.Client()
client.revert('./examples/pysvn/foo.txt')

這丟棄在工作拷貝和恢復(fù)的文件或目錄的任何未提交的未經(jīng)編輯的狀態(tài)變化.

正在計(jì)劃增加或移除留無版本或恢復(fù)到工作拷貝.

重命名或者移動(dòng)文件

import pysvn
client = pysvn.Client()
#rename the file client side
client.move('./examples/pysvn/foo.txt', './examples/pysvn/foo2.txt')
#checkin the change removes the file from the repository
client.checkin(['./examples/pysvn/foo.txt', './examples/pysvn/foo2.txt'], 'Foo has become Foo2')

移動(dòng)或重命名文件刪除舊路徑或名稱的文件, 并增加了在新的位置, 同時(shí)保留以前的版本有關(guān)的信息.

在這個(gè)例子里, 我們通過文件名Client.checkin()傳遞父目錄也將是有效的.

轉(zhuǎn)移和合并可以在服務(wù)器端單步完成; 可以參見倉庫任務(wù)的那節(jié)例子.

從倉庫中刪除文件或目錄

import pysvn
client = pysvn.Client()
#schedule the removal;
#  the file will be removed from the working copy
client.remove('./examples/pysvn/foo2.txt')
#committing the change removes the file from the repository
client.checkin(['./examples/pysvn/foo2.txt'], 'Removing sample file')

有些人把刪除的文件, 或是用完全清除存儲(chǔ)庫目錄. 該文件仍然存在于以前的版本, 可以通過檢查或以其他方式進(jìn)行審查以前修訂的內(nèi)容檢索.

確定等待變動(dòng)

import pysvn
client = pysvn.Client()
changes = client.status('./examples/pysvn')
print 'files to be added:'
print [f.path for f in changes if f.text_status == pysvn.wc_status_kind.added]
print 'files to be removed:'
print [f.path for f in changes if f.text_status == pysvn.wc_status_kind.deleted]
print 'files that have changed:'
print [f.path for f in changes if f.text_status == pysvn.wc_status_kind.modified]
print 'files with merge conflicts:'
print [f.path for f in changes if f.text_status == pysvn.wc_status_kind.conflicted]
print 'unversioned files:'
print [f.path for f in changes if f.text_status == pysvn.wc_status_kind.unversioned]

生成差異或補(bǔ)丁

import pysvn
client = pysvn.Client()
diff_text = client.diff('./tmp-file-prefix-', '.')

獲取倉庫URL

import pysvn
client = pysvn.Client()
entry = client.info('.')
print 'Url:',entry.url

倉庫任務(wù)

本節(jié)說明任務(wù)的例子, 操縱或檢查倉庫.雖然共同任務(wù), 通過本地工作副本時(shí)間的變化, 這些任務(wù)直接影響到庫
獲取倉庫目錄的清單

import pysvn
client = pysvn.Client()
entry_list = client.ls('.')

從倉庫獲取文件內(nèi)容

import pysvn
client = pysvn.Client()
file_content = client.cat('file.txt')

創(chuàng)建一個(gè)標(biāo)記或分支

import pysvn
client = pysvn.Client()
log_message = "reason for change"
def get_log_message():
    return True, log_message
client.callback_get_log_message = get_log_message
client.copy('http://svnrepo.com/svn/trunk', 'http://svnrepo.com/svn/tag/%s' % tag_name )

從倉庫中轉(zhuǎn)移或者重命名

import pysvn
client = pysvn.Client()
client.move( 'file_old.txt', 'file_new.txt' )

鎖定文件

import pysvn
client = pysvn.Client()
client.lock( 'file.txt', 'reason for locking' )

鎖定文件并鎖定其他用戶或者工作副本

import pysvn
client = pysvn.Client()
client.lock( 'file.txt', 'reason for locking', force=True )

解鎖

import pysvn
client = pysvn.Client()
client.unlock( 'file.txt' )

解鎖文件并鎖定其他用戶或工作副本

import pysvn
client = pysvn.Client()
client.unlock( 'file.txt', force=True )

測試鎖定文件

Method 1:

all_entries = self.client.info2( path, recurse=False )
for path, info in all_entries:
    if info['lock']:
        if info['lock']['token'] != '':
            print '%s is locked' % path
        print info['lock']['comment']

Method 2:

all_status = self.client.status( path, recurse=False, update=True )
for status in all_status:
    if status.entry is not None:
        if status.entry.lock_token is not None:
            print '%s is locked' % status.path

到此這篇關(guān)于Pysvn 使用指南的文章就介紹到這了,更多相關(guān)Pysvn 使用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論