utils/cvslh.py
author rgbecker
Fri, 19 May 2000 13:45:25 +0000
changeset 234 9cf1a7391d98
child 235 45693891c14e
permissions -rw-r--r--
First version
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
234
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
     1
import re, sys, getopt
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
     2
class logFileEntry:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
     3
	def __init__(self, version):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
     4
		self.version = version
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
     5
		self.date = None
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
     6
		self.author = None
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
     7
		self.comment = None
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
     8
	def __str__(self):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
     9
		if self.version:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    10
			return "%10s %s %s %s" %(self.version, self.date, self.comment, self.author)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    11
class logFile:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    12
	def __init__(self,name):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    13
		self.name  = name
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    14
		self.E = []
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    15
	def addEntry(self,E):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    16
		self.E.append(E)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    17
	def __str__(self):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    18
		s = str(self.name)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    19
		for e in self.E:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    20
			s = s+'\n'+str(e)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    21
		return s
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    22
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    23
reWorking=re.compile('^Working +file: +(.*)$')
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    24
reVersion=re.compile('^revision +(.*)$')
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    25
reDate=re.compile('^date: +([^;]*); +author: +([^;]*)')
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    26
opt={'-d': None}
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    27
def findWorking():
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    28
	global i, lines
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    29
	while i<len(lines):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    30
		m = reWorking.match(lines[i])
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    31
		i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    32
		if m:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    33
			return m.group(1)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    34
		
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    35
	return None
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    36
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    37
def findVersion(F):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    38
	global i, lines, opt
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    39
	while i<len(lines):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    40
		m = reVersion.match(lines[i])
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    41
		if m:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    42
			E=logFileEntry(m.group(1))
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    43
			i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    44
			m = reDate.match(lines[i])
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    45
			if m:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    46
				E.date = m.group(1)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    47
				E.author = m.group(2)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    48
				i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    49
				if re.match('^branches:',lines[i]): i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    50
				l = ''
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    51
				while i<len(lines) and re.match('^[-=]+$',lines[i]) is None:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    52
					l = l + ' ' + lines[i][:-1]
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    53
					i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    54
				E.comment = l
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    55
				i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    56
			if opt['-d']:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    57
				ok = opt['-d']<=E.date
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    58
			else:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    59
				ok = 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    60
			if ok: F.addEntry(E)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    61
		else:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    62
			if reWorking.search(lines[i]): return None
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    63
			i = i + 1
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    64
	return None
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    65
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    66
opts, argv= getopt.getopt(sys.argv[1:],'d:')
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    67
for k,v in opts: opt[k]=v
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    68
if len(argv):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    69
	lines = open(argv[0],'r').readlines()
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    70
else:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    71
	lines = sys.stdin.readlines()
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    72
i = 0
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    73
while 1:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    74
	f = findWorking()
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    75
	if f is None: break
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    76
	F = logFile(f)
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    77
	while findVersion(F):
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    78
		pass
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    79
	if F.E != []:
9cf1a7391d98 First version
rgbecker
parents:
diff changeset
    80
		print str(F)