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