gpt4 book ai didi

python - 记录 pysvn 更新

转载 作者:太空宇宙 更新时间:2023-11-03 15:29:10 27 4
gpt4 key购买 nike

如果可能的话,在 pysvn 中运行 svn update 时,我如何获取有关已添加、删除、更新哪些文件等的信息?我想将此信息写入日志文件。

最佳答案

您可以保存原始版本和更新版本,然后使用 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

关于python - 记录 pysvn 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1754841/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com