Python 日志pysvn更新
在pysvn中运行svn更新时,如果可能的话,我如何获取关于添加、删除、更新了哪些文件的信息?我想将此信息写入日志文件。您可以保存原始版本和更新版本,然后使用“差异汇总”获取更新文件。(见附件) 下面是一个例子:Python 日志pysvn更新,python,logging,pysvn,Python,Logging,Pysvn,在pysvn中运行svn更新时,如果可能的话,我如何获取关于添加、删除、更新了哪些文件的信息?我想将此信息写入日志文件。您可以保存原始版本和更新版本,然后使用“差异汇总”获取更新文件。(见附件) 下面是一个例子: import time import pysvn work_path = '.' client = pysvn.Client() entry = client.info(work_path) old_rev = entry.revision.number revs = clie
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
创建客户端对象时,请添加一个。回调函数是一个获取有关事件的
dict
信息的函数
import pysvn
import pprint
def notify(event_dict):
pprint.pprint(event_dict)
client = pysvn.Client()
client.callback_notify = notify
# Perform actions with client
我知道这很旧,但没有一个公认的答案,我在搜索与
node\u 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]
导入pysvn
tmpFile=open('your.log','w')
repository=sys.argv[1]
transactionId=sys.argv[2]
transaction=pysvn.transaction(存储库,transactionId)
#
#transaction.changed()
#
# {
#u'some.file':('R',1,0),
#u'other.file':('R',1,0),
#u'a目录/a.file':('R',1,0),
#u'anotherDirectory':('A',0,0),
#u'junk.file':('D',0,0)
# }
#
对于事务中的changedFile.changed():
tmpFile.writelines(transaction.cat(changedFile))
#如果需要检查.changed()目录中的数据。。。
#如果事务中的('A'或'R')。已更改()[changedFile][0]
我在SVN预提交钩子脚本中以与上述类似的方式使用事务
有关词典的详细信息,请参阅文档:另外,虽然我没有使用可能也感兴趣的事务的list()方法:
summary=client.diff\u summary(url,pysvn.Revision(pysvn.opt\u Revision\u kind.committed),url,pysvn.Revision(pysvn.opt\u Revision\u kind.previous))
是否可以像上面那样在两个url上使用diff\u summary,而不是在工作路径上?