utils/cvslh.py
author rgbecker
Fri, 19 May 2000 13:51:54 +0000
changeset 235 45693891c14e
parent 234 9cf1a7391d98
child 476 8f08a8a9f314
permissions -rw-r--r--
Added comment
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
#
234
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
     9
import re, sys, getopt
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)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    25
	def __str__(self):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    26
		s = str(self.name)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    27
		for e in self.E:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    28
			s = s+'\n'+str(e)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    29
		return s
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    30
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    31
reWorking=re.compile('^Working +file: +(.*)$')
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    32
reVersion=re.compile('^revision +(.*)$')
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    33
reDate=re.compile('^date: +([^;]*); +author: +([^;]*)')
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    34
opt={'-d': None}
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    35
def findWorking():
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    36
	global i, lines
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    37
	while i<len(lines):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    38
		m = reWorking.match(lines[i])
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    39
		i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    40
		if m:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    41
			return m.group(1)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    42
		
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    43
	return None
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    44
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    45
def findVersion(F):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    46
	global i, lines, opt
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    47
	while i<len(lines):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    48
		m = reVersion.match(lines[i])
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    49
		if m:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    50
			E=logFileEntry(m.group(1))
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    51
			i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    52
			m = reDate.match(lines[i])
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    53
			if m:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    54
				E.date = m.group(1)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    55
				E.author = m.group(2)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    56
				i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    57
				if re.match('^branches:',lines[i]): i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    58
				l = ''
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    59
				while i<len(lines) and re.match('^[-=]+$',lines[i]) is None:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    60
					l = l + ' ' + lines[i][:-1]
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    61
					i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    62
				E.comment = l
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    63
				i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    64
			if opt['-d']:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    65
				ok = opt['-d']<=E.date
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    66
			else:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    67
				ok = 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    68
			if ok: F.addEntry(E)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    69
		else:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    70
			if reWorking.search(lines[i]): return None
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    71
			i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    72
	return None
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    73
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    74
opts, argv= getopt.getopt(sys.argv[1:],'d:')
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    75
for k,v in opts: opt[k]=v
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    76
if len(argv):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    77
	lines = open(argv[0],'r').readlines()
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    78
else:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    79
	lines = sys.stdin.readlines()
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    80
i = 0
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    81
while 1:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    82
	f = findWorking()
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    83
	if f is None: break
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    84
	F = logFile(f)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    85
	while findVersion(F):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    86
		pass
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    87
	if F.E != []:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    88
		print str(F)