utils/cvslh.py
author rgbecker
Wed, 25 Oct 2000 08:57:46 +0000
changeset 494 54257447cfe9
parent 476 8f08a8a9f314
child 1496 d756d81bf8cc
permissions -rw-r--r--
Changed to indirect copyright
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
494
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 476
diff changeset
     1
#copyright ReportLab Inc. 2000
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 476
diff changeset
     2
#see license.txt for license details
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 476
diff changeset
     3
#history http://cvs.sourceforge.net/cgi-bin/cvsweb.cgi/utils/cvslh.py?cvsroot=reportlab
54257447cfe9 Changed to indirect copyright
rgbecker
parents: 476
diff changeset
     4
#$Header: /tmp/reportlab/utils/cvslh.py,v 1.4 2000/10/25 08:57:46 rgbecker Exp $
235
45693891c14e Added comment
rgbecker
parents: 234
diff changeset
     5
#
45693891c14e Added comment
rgbecker
parents: 234
diff changeset
     6
#	after cvs -z7 log >\tmp\log
45693891c14e Added comment
rgbecker
parents: 234
diff changeset
     7
#
45693891c14e Added comment
rgbecker
parents: 234
diff changeset
     8
#	python cvslh.py -d"2000/04/10 14:00:00" <\tmp\log >\tmp\hacked_log
45693891c14e Added comment
rgbecker
parents: 234
diff changeset
     9
#
45693891c14e Added comment
rgbecker
parents: 234
diff changeset
    10
#	makes a reasonably formatted file of the log entries since the specified
45693891c14e Added comment
rgbecker
parents: 234
diff changeset
    11
#	date.
45693891c14e Added comment
rgbecker
parents: 234
diff changeset
    12
#
476
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    13
import re, sys, getopt, string
234
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    14
class logFileEntry:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    15
	def __init__(self, version):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    16
		self.version = version
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    17
		self.date = None
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    18
		self.author = None
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    19
		self.comment = None
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    20
	def __str__(self):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    21
		if self.version:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    22
			return "%10s %s %s %s" %(self.version, self.date, self.comment, self.author)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    23
class logFile:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    24
	def __init__(self,name):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    25
		self.name  = name
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    26
		self.E = []
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    27
	def addEntry(self,E):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    28
		self.E.append(E)
476
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    29
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    30
	def getChanges(self,L=None):
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    31
		if L is None: L = []
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    32
		for e in self.E:
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    33
			L.append(Change(self.name,e))
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    34
234
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    35
	def __str__(self):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    36
		s = str(self.name)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    37
		for e in self.E:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    38
			s = s+'\n'+str(e)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    39
		return s
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    40
476
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    41
class Change:
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    42
	def __init__(self,name,lFE):
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    43
		self.name = name
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    44
		self.version = lFE.version
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    45
		self.date = lFE.date
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    46
		self.comment = lFE.comment
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    47
		self.author = lFE.author
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    48
234
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    49
reWorking=re.compile('^Working +file: +(.*)$')
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    50
reVersion=re.compile('^revision +(.*)$')
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    51
reDate=re.compile('^date: +([^;]*); +author: +([^;]*)')
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    52
opt={'-d': None}
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    53
def findWorking():
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    54
	global i, lines
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    55
	while i<len(lines):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    56
		m = reWorking.match(lines[i])
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    57
		i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    58
		if m:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    59
			return m.group(1)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    60
		
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    61
	return None
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    62
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    63
def findVersion(F):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    64
	global i, lines, opt
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    65
	while i<len(lines):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    66
		m = reVersion.match(lines[i])
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    67
		if m:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    68
			E=logFileEntry(m.group(1))
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    69
			i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    70
			m = reDate.match(lines[i])
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    71
			if m:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    72
				E.date = m.group(1)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    73
				E.author = m.group(2)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    74
				i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    75
				if re.match('^branches:',lines[i]): i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    76
				l = ''
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    77
				while i<len(lines) and re.match('^[-=]+$',lines[i]) is None:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    78
					l = l + ' ' + lines[i][:-1]
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    79
					i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    80
				E.comment = l
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    81
				i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    82
			if opt['-d']:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    83
				ok = opt['-d']<=E.date
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    84
			else:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    85
				ok = 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    86
			if ok: F.addEntry(E)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    87
		else:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    88
			if reWorking.search(lines[i]): return None
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    89
			i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    90
	return None
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    91
476
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    92
def sortFunc(a, b):
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    93
	if a.date<b.date: return -1
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    94
	elif a.date>b.date: return 1
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    95
	elif a.name<b.name: return -1
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    96
	elif a.name>b.name: return 1
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    97
	else: return 0
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    98
def sortFuncR(a,b):
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
    99
	return -sortFunc(a,b)
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
   100
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
   101
opts, argv= getopt.getopt(sys.argv[1:],'rsd:')
234
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
   102
for k,v in opts: opt[k]=v
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
   103
if len(argv):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
   104
	lines = open(argv[0],'r').readlines()
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
   105
else:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
   106
	lines = sys.stdin.readlines()
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
   107
i = 0
476
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
   108
cL = []
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
   109
sortFlag = opt.has_key('-s')
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
   110
reverseSort = opt.has_key('-r')
234
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
   111
while 1:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
   112
	f = findWorking()
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
   113
	if f is None: break
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
   114
	F = logFile(f)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
   115
	while findVersion(F):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
   116
		pass
476
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
   117
	if sortFlag:
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
   118
		F.getChanges(cL)
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
   119
	elif F.E != []:
234
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
   120
		print str(F)
476
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
   121
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
   122
if sortFlag:
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
   123
	cL.sort(reverseSort and sortFuncR or sortFunc)
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
   124
	d = ''
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
   125
	for c in cL:
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
   126
		if c.date[:10]!=d:
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
   127
			d = c.date[:10]
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
   128
			print '##### %s #####' % d
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
   129
		print '\t%s %s %s' % (c.name, c.version, c.author)
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
   130
		C = string.split(c.comment,'\n')
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
   131
		for c in C:
8f08a8a9f314 Sorting in cvslh.py
rgbecker
parents: 235
diff changeset
   132
			print '\t\t' + c