码迷,mamicode.com
首页 > 其他好文 > 详细

pysvn安装及常用方法

时间:2016-12-16 19:27:12      阅读:441      评论:0      收藏:0      [点我收藏+]

标签:pre   number   color   test   内容   .text   call   效果   str   

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

pysvn安装及常用方法

标签:pre   number   color   test   内容   .text   call   效果   str   

原文地址:http://www.cnblogs.com/toSeek/p/6187791.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!