How could I, if possible, get information on what files have been added, removed, updated etc when running svn update in pysvn? I want to write this information to a log file.
A:
you can save the original and updated revision, then use diff_summarize getting updated files. (see pysvn Programmer's reference)
here's an example:
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
Xie Yanbo
2010-09-08 06:30:15
A:
When you create your client object, add a notify callback. The callback is a function that takes a dict
of information about the event.
import pysvn
import pprint
def notify(event_dict):
pprint.pprint(event_dict)
client = pysvn.Client()
client.callback_notify = notify
# Perform actions with client
detly
2010-09-08 06:36:20