在pysvn中运行svn更新时,如果可能,我如何获取添加、删除、更新等文件的信息?我想将此信息写入日志文件。
发布于 2010-09-08 14:30:16
您可以保存原始和更新的修订,然后使用diff_summarize获取更新的文件。(参见pysvn Programmer's reference)
下面是一个例子:
import time
import pysvn
work_path = '.'
client = pysvn.Client()
entry = client.info(work_path)
old_rev = entry.revision.number
revs = client.update(work_path)
new_rev = revs[-1].number
print 'updated from %s to %s.\n' % (old_rev, new_rev)
head = pysvn.Revision(pysvn.opt_revision_kind.number, old_rev)
end = pysvn.Revision(pysvn.opt_revision_kind.number, new_rev)
log_messages = client.log(work_path, revision_start=head, revision_end=end,
limit=0)
for log in log_messages:
timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(log.date))
print '[%s]\t%s\t%s\n %s\n' % (log.revision.number, timestamp,
log.author, log.message)
print
FILE_CHANGE_INFO = {
pysvn.diff_summarize_kind.normal: ' ',
pysvn.diff_summarize_kind.modified: 'M',
pysvn.diff_summarize_kind.delete: 'D',
pysvn.diff_summarize_kind.added: 'A',
}
print 'file changed:'
summary = client.diff_summarize(work_path, head, work_path, end)
for info in summary:
path = info.path
if info.node_kind == pysvn.node_kind.dir:
path += '/'
file_changed = FILE_CHANGE_INFO[info.summarize_kind]
prop_changed = ' '
if info.prop_changed:
prop_changed = 'M'
print file_changed + prop_changed, path
print发布于 2010-09-08 14:36:21
创建客户端对象时,添加一个notify callback。回调是一个接受事件相关信息的dict的函数。
import pysvn
import pprint
def notify(event_dict):
pprint.pprint(event_dict)
client = pysvn.Client()
client.callback_notify = notify
# Perform actions with client发布于 2014-03-27 02:05:02
我知道这是旧的,但是没有一个公认的答案,我在搜索与node_kind有关的信息时偶然发现了它。
import pysvn
tmpFile = open('your.log', 'w')
repository = sys.argv[1]
transactionId = sys.argv[2]
transaction = pysvn.Transaction(repository, transactionId)
#
# transaction.changed()
#
# {
# u'some.file': ('R', <node_kind.file>, 1, 0),
# u'another.file': ('R', <node_kind.file>, 1, 0),
# u'aDirectory/a.file': ('R', <node_kind.file>, 1, 0),
# u'anotherDirectory': ('A', <node_kind.dir>, 0, 0),
# u'junk.file': ('D', <node_kind.file>, 0, 0)
# }
#
for changedFile in transaction.changed():
tmpFile.writelines(transaction.cat(changedFile))
# if you need to check data in the .changed() dict...
# if ('A' or 'R') in transaction.changed()[changedFile][0]在SVN预提交钩子脚本中,我使用事务的方式与上面的类似。
有关字典的详细信息,请参阅文档:
http://pysvn.tigris.org/docs/pysvn_prog_ref.html#pysvn_transaction
http://pysvn.tigris.org/docs/pysvn_prog_ref.html#pysvn_transaction_changed
另外,虽然我没有使用Transaction的list()方法,但它可能也很有趣:
http://pysvn.tigris.org/docs/pysvn_prog_ref.html#pysvn_transaction
https://stackoverflow.com/questions/1754841
复制相似问题