Page MenuHomec4science

SvnInfo.py
No OneTemporary

File Metadata

Created
Sun, Sep 1, 04:24

SvnInfo.py

#!/usr/bin/env python
from __future__ import print_function
import pysvn
from datetime import datetime
import time
import os
import re
class SvnInfo(object):
def __init__(self, filename):
self.filepath = os.path.expanduser(filename)
self.client = pysvn.Client()
self.root_url = self.client.root_url_from_path(filename)
print ("treated file: " + self.filepath)
self.infos = self.client.info(filename)
#for k,v in self.infos.iteritems():
# print (str(k) + ": " + str(v))
self.logs = self.client.log(filename,
strict_node_history=False,
discover_changed_paths=True)
#print (self.infos["name"])
self.authors = dict()
self.modification_dates = []
self.old_names = set()
for entry in self.logs:
auth = entry["author"]
msg = ""
if "message" in entry:
msg = entry["message"]
if auth not in self.authors:
self.authors[auth] = []
d = entry["date"]
rev = entry["revision"]
for ch_path in entry["changed_paths"]:
if (re.match(".*" + self.infos["name"],ch_path["path"])
and ch_path["copyfrom_path"] is not None):
old_name = ch_path["copyfrom_path"]
self.old_names.add(old_name)
self.authors[auth].append((d,rev,msg))
self.modification_dates.append(d)
def creationDate(self):
return min(self.modification_dates)
def lastModificationDate(self):
return max(self.modification_dates)
def getAuthors(self):
return self.authors
def numberOfModifications(self,author):
return len(self.authors[author])
def modificationsByAuthor(self,author):
a = self.authors[author]
print ("revisions are " + ", ".join([str(_a[1].number) for _a in a]) )
res = "author: {0}:\n".format(author)
for d,r,msg in a:
date = datetime.fromtimestamp(d)
date = date.strftime("%d-%m-%Y")
res += "@ {0} rev {1} msg {2}\n".format(date,r.number,msg)
res += self.getModifications(r)
return res
def getModifications(self,revision):
r_pre = pysvn.Revision(pysvn.opt_revision_kind.number, revision.number - 1)
# try first the local name
try:
res_diff = self.client.diff("/tmp",self.filepath,revision1=r_pre,revision2=revision)
except Exception as e:
res_diff = None
if res_diff is not None:
# print (res_diff)
return res_diff
# try renaming possibilitites
for old_name in list(self.old_names):
try:
print (self.filepath)
print (self.root_url)
url_filename = self.root_url + "/" + old_name
print (url_filename)
res_diff = self.client.diff("/tmp",url_filename,revision1=r_pre,revision2=revision)
except Exception as e:
print (str(e))
res_diff = None
if res_diff is not None: return res_diff
return str(res_diff)

Event Timeline