[Python-checkins] CVS: python/dist/src/Tools/scripts byteyears.py,1.6,1.7 checkpyc.py,1.8,1.9 classfix.py,1.9,1.10 copytime.py,1.4,1.5 dutree.py,1.8,1.9 findlinksto.py,1.7,1.8 fixcid.py,1.7,1.8 fixheader.py,1.2,1.3 fixps.py,1.4,1.5 ftpmirror.py,1.12,1.13 gencodec.py,1.4,1.5 h2py.py,1.11,1.12 ifdef.py,1.3,1.4 linktree.py,1.5,1.6 lll.py,1.4,1.5 logmerge.py,1.5,1.6 mailerdaemon.py,1.8,1.9 methfix.py,1.4,1.5 mkreal.py,1.5,1.6 ndiff.py,1.6,1.7 nm2def.py,1.3,1.4 objgraph.py,1.4,1.5 parseentities.py,1.2,1.3 pathfix.py,1.2,1.3 pdeps.py,1.4,1.5 pindent.py,1.9,1.10 ptags.py,1.6,1.7 redemo.py,1.1,1.2 suff.py,1.4,1.5 sum5.py,1.2,1.3 texi2html.py,1.11,1.12 trace.py,1.2,1.3 treesync.py,1.4,1.5 which.py,1.8,1.9 xxci.py,1.13,1.14

Tim Peters tim_one@users.sourceforge.net
Wed, 17 Jan 2001 00:48:41 -0800


Update of /cvsroot/python/python/dist/src/Tools/scripts
In directory usw-pr-cvs1:/tmp/cvs-serv17810/python/dist/src/Tools/scripts

Modified Files:
	byteyears.py checkpyc.py classfix.py copytime.py dutree.py 
	findlinksto.py fixcid.py fixheader.py fixps.py ftpmirror.py 
	gencodec.py h2py.py ifdef.py linktree.py lll.py logmerge.py 
	mailerdaemon.py methfix.py mkreal.py ndiff.py nm2def.py 
	objgraph.py parseentities.py pathfix.py pdeps.py pindent.py 
	ptags.py redemo.py suff.py sum5.py texi2html.py trace.py 
	treesync.py which.py xxci.py 
Log Message:
Whitespace normalization.


Index: byteyears.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/byteyears.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** byteyears.py	1996/11/27 19:44:05	1.6
--- byteyears.py	2001/01/17 08:48:39	1.7
***************
*** 13,57 ****
  # Use lstat() to stat files if it exists, else stat()
  try:
! 	statfunc = os.lstat
  except AttributeError:
! 	statfunc = os.stat
  
  # Parse options
  if sys.argv[1] == '-m':
! 	itime = ST_MTIME
! 	del sys.argv[1]
  elif sys.argv[1] == '-c':
! 	itime = ST_CTIME
! 	del sys.argv[1]
  elif sys.argv[1] == '-a':
! 	itime = ST_CTIME
! 	del sys.argv[1]
  else:
! 	itime = ST_MTIME
  
! secs_per_year = 365.0 * 24.0 * 3600.0	# Scale factor
! now = time.time()			# Current time, for age computations
! status = 0				# Exit status, set to 1 on errors
  
  # Compute max file name length
  maxlen = 1
  for file in sys.argv[1:]:
! 	if len(file) > maxlen: maxlen = len(file)
  
  # Process each argument in turn
  for file in sys.argv[1:]:
! 	try:
! 		st = statfunc(file)
! 	except os.error, msg:
! 		sys.stderr.write('can\'t stat ' + `file` + ': ' + `msg` + '\n')
! 		status = 1
! 		st = ()
! 	if st:
! 		anytime = st[itime]
! 		size = st[ST_SIZE]
! 		age = now - anytime
! 		byteyears = float(size) * float(age) / secs_per_year
! 		print string.ljust(file, maxlen),
! 		print string.rjust(`int(byteyears)`, 8)
  
  sys.exit(status)
--- 13,57 ----
  # Use lstat() to stat files if it exists, else stat()
  try:
!     statfunc = os.lstat
  except AttributeError:
!     statfunc = os.stat
  
  # Parse options
  if sys.argv[1] == '-m':
!     itime = ST_MTIME
!     del sys.argv[1]
  elif sys.argv[1] == '-c':
!     itime = ST_CTIME
!     del sys.argv[1]
  elif sys.argv[1] == '-a':
!     itime = ST_CTIME
!     del sys.argv[1]
  else:
!     itime = ST_MTIME
  
! secs_per_year = 365.0 * 24.0 * 3600.0   # Scale factor
! now = time.time()                       # Current time, for age computations
! status = 0                              # Exit status, set to 1 on errors
  
  # Compute max file name length
  maxlen = 1
  for file in sys.argv[1:]:
!     if len(file) > maxlen: maxlen = len(file)
  
  # Process each argument in turn
  for file in sys.argv[1:]:
!     try:
!         st = statfunc(file)
!     except os.error, msg:
!         sys.stderr.write('can\'t stat ' + `file` + ': ' + `msg` + '\n')
!         status = 1
!         st = ()
!     if st:
!         anytime = st[itime]
!         size = st[ST_SIZE]
!         age = now - anytime
!         byteyears = float(size) * float(age) / secs_per_year
!         print string.ljust(file, maxlen),
!         print string.rjust(`int(byteyears)`, 8)
  
  sys.exit(status)

Index: checkpyc.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/checkpyc.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** checkpyc.py	1998/10/07 19:45:33	1.8
--- checkpyc.py	2001/01/17 08:48:39	1.9
***************
*** 9,65 ****
  
  def main():
! 	silent = 0
! 	verbose = 0
! 	if sys.argv[1:]:
! 		if sys.argv[1] == '-v':
! 			verbose = 1
! 		elif sys.argv[1] == '-s':
! 			silent = 1
! 	MAGIC = imp.get_magic()
! 	if not silent:
! 		print 'Using MAGIC word', `MAGIC`
! 	for dirname in sys.path:
! 		try:
! 			names = os.listdir(dirname)
! 		except os.error:
! 			print 'Cannot list directory', `dirname`
! 			continue
! 		if not silent:
! 			print 'Checking', `dirname`, '...'
! 		names.sort()
! 		for name in names:
! 			if name[-3:] == '.py':
! 				name = os.path.join(dirname, name)
! 				try:
! 					st = os.stat(name)
! 				except os.error:
! 					print 'Cannot stat', `name`
! 					continue
! 				if verbose:
! 					print 'Check', `name`, '...'
! 				name_c = name + 'c'
! 				try:
! 					f = open(name_c, 'r')
! 				except IOError:
! 					print 'Cannot open', `name_c`
! 					continue
! 				magic_str = f.read(4)
! 				mtime_str = f.read(4)
! 				f.close()
! 				if magic_str <> MAGIC:
! 					print 'Bad MAGIC word in ".pyc" file',
! 					print `name_c`
! 					continue
! 				mtime = get_long(mtime_str)
! 				if mtime == 0 or mtime == -1:
! 					print 'Bad ".pyc" file', `name_c`
! 				elif mtime <> st[ST_MTIME]:
! 					print 'Out-of-date ".pyc" file',
! 					print `name_c`
  
  def get_long(s):
! 	if len(s) <> 4:
! 		return -1
! 	return ord(s[0]) + (ord(s[1])<<8) + (ord(s[2])<<16) + (ord(s[3])<<24)
  
  main()
--- 9,65 ----
  
  def main():
!     silent = 0
!     verbose = 0
!     if sys.argv[1:]:
!         if sys.argv[1] == '-v':
!             verbose = 1
!         elif sys.argv[1] == '-s':
!             silent = 1
!     MAGIC = imp.get_magic()
!     if not silent:
!         print 'Using MAGIC word', `MAGIC`
!     for dirname in sys.path:
!         try:
!             names = os.listdir(dirname)
!         except os.error:
!             print 'Cannot list directory', `dirname`
!             continue
!         if not silent:
!             print 'Checking', `dirname`, '...'
!         names.sort()
!         for name in names:
!             if name[-3:] == '.py':
!                 name = os.path.join(dirname, name)
!                 try:
!                     st = os.stat(name)
!                 except os.error:
!                     print 'Cannot stat', `name`
!                     continue
!                 if verbose:
!                     print 'Check', `name`, '...'
!                 name_c = name + 'c'
!                 try:
!                     f = open(name_c, 'r')
!                 except IOError:
!                     print 'Cannot open', `name_c`
!                     continue
!                 magic_str = f.read(4)
!                 mtime_str = f.read(4)
!                 f.close()
!                 if magic_str <> MAGIC:
!                     print 'Bad MAGIC word in ".pyc" file',
!                     print `name_c`
!                     continue
!                 mtime = get_long(mtime_str)
!                 if mtime == 0 or mtime == -1:
!                     print 'Bad ".pyc" file', `name_c`
!                 elif mtime <> st[ST_MTIME]:
!                     print 'Out-of-date ".pyc" file',
!                     print `name_c`
  
  def get_long(s):
!     if len(s) <> 4:
!         return -1
!     return ord(s[0]) + (ord(s[1])<<8) + (ord(s[2])<<16) + (ord(s[3])<<24)
  
  main()

Index: classfix.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/classfix.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** classfix.py	1996/11/27 19:44:08	1.9
--- classfix.py	2001/01/17 08:48:39	1.10
***************
*** 5,11 ****
  # Fix Python source files to use the new class definition syntax, i.e.,
  # the syntax used in Python versions before 0.9.8:
! #	class C() = base(), base(), ...: ...
  # is changed to the current syntax:
! #	class C(base, base, ...): ...
  #
  # The script uses heuristics to find class definitions that usually
--- 5,11 ----
  # Fix Python source files to use the new class definition syntax, i.e.,
  # the syntax used in Python versions before 0.9.8:
! #       class C() = base(), base(), ...: ...
  # is changed to the current syntax:
! #       class C(base, base, ...): ...
  #
  # The script uses heuristics to find class definitions that usually
***************
*** 40,150 ****
  
  def main():
! 	bad = 0
! 	if not sys.argv[1:]: # No arguments
! 		err('usage: ' + sys.argv[0] + ' file-or-directory ...\n')
! 		sys.exit(2)
! 	for arg in sys.argv[1:]:
! 		if os.path.isdir(arg):
! 			if recursedown(arg): bad = 1
! 		elif os.path.islink(arg):
! 			err(arg + ': will not process symbolic links\n')
! 			bad = 1
! 		else:
! 			if fix(arg): bad = 1
! 	sys.exit(bad)
  
  ispythonprog = regex.compile('^[a-zA-Z0-9_]+\.py$')
  def ispython(name):
! 	return ispythonprog.match(name) >= 0
  
  def recursedown(dirname):
! 	dbg('recursedown(' + `dirname` + ')\n')
! 	bad = 0
! 	try:
! 		names = os.listdir(dirname)
! 	except os.error, msg:
! 		err(dirname + ': cannot list directory: ' + `msg` + '\n')
! 		return 1
! 	names.sort()
! 	subdirs = []
! 	for name in names:
! 		if name in (os.curdir, os.pardir): continue
! 		fullname = os.path.join(dirname, name)
! 		if os.path.islink(fullname): pass
! 		elif os.path.isdir(fullname):
! 			subdirs.append(fullname)
! 		elif ispython(name):
! 			if fix(fullname): bad = 1
! 	for fullname in subdirs:
! 		if recursedown(fullname): bad = 1
! 	return bad
  
  def fix(filename):
! ##	dbg('fix(' + `filename` + ')\n')
! 	try:
! 		f = open(filename, 'r')
! 	except IOError, msg:
! 		err(filename + ': cannot open: ' + `msg` + '\n')
! 		return 1
! 	head, tail = os.path.split(filename)
! 	tempname = os.path.join(head, '@' + tail)
! 	g = None
! 	# If we find a match, we rewind the file and start over but
! 	# now copy everything to a temp file.
! 	lineno = 0
! 	while 1:
! 		line = f.readline()
! 		if not line: break
! 		lineno = lineno + 1
! 		while line[-2:] == '\\\n':
! 			nextline = f.readline()
! 			if not nextline: break
! 			line = line + nextline
! 			lineno = lineno + 1
! 		newline = fixline(line)
! 		if newline != line:
! 			if g is None:
! 				try:
! 					g = open(tempname, 'w')
! 				except IOError, msg:
! 					f.close()
! 					err(tempname+': cannot create: '+\
! 					    `msg`+'\n')
! 					return 1
! 				f.seek(0)
! 				lineno = 0
! 				rep(filename + ':\n')
! 				continue # restart from the beginning
! 			rep(`lineno` + '\n')
! 			rep('< ' + line)
! 			rep('> ' + newline)
! 		if g is not None:
! 			g.write(newline)
! 
! 	# End of file
! 	f.close()
! 	if not g: return 0 # No changes
! 
! 	# Finishing touch -- move files
! 
! 	# First copy the file's mode to the temp file
! 	try:
! 		statbuf = os.stat(filename)
! 		os.chmod(tempname, statbuf[ST_MODE] & 07777)
! 	except os.error, msg:
! 		err(tempname + ': warning: chmod failed (' + `msg` + ')\n')
! 	# Then make a backup of the original file as filename~
! 	try:
! 		os.rename(filename, filename + '~')
! 	except os.error, msg:
! 		err(filename + ': warning: backup failed (' + `msg` + ')\n')
! 	# Now move the temp file to the original file
! 	try:
! 		os.rename(tempname, filename)
! 	except os.error, msg:
! 		err(filename + ': rename failed (' + `msg` + ')\n')
! 		return 1
! 	# Return succes
! 	return 0
  
  # This expression doesn't catch *all* class definition headers,
--- 40,150 ----
  
  def main():
!     bad = 0
!     if not sys.argv[1:]: # No arguments
!         err('usage: ' + sys.argv[0] + ' file-or-directory ...\n')
!         sys.exit(2)
!     for arg in sys.argv[1:]:
!         if os.path.isdir(arg):
!             if recursedown(arg): bad = 1
!         elif os.path.islink(arg):
!             err(arg + ': will not process symbolic links\n')
!             bad = 1
!         else:
!             if fix(arg): bad = 1
!     sys.exit(bad)
  
  ispythonprog = regex.compile('^[a-zA-Z0-9_]+\.py$')
  def ispython(name):
!     return ispythonprog.match(name) >= 0
  
  def recursedown(dirname):
!     dbg('recursedown(' + `dirname` + ')\n')
!     bad = 0
!     try:
!         names = os.listdir(dirname)
!     except os.error, msg:
!         err(dirname + ': cannot list directory: ' + `msg` + '\n')
!         return 1
!     names.sort()
!     subdirs = []
!     for name in names:
!         if name in (os.curdir, os.pardir): continue
!         fullname = os.path.join(dirname, name)
!         if os.path.islink(fullname): pass
!         elif os.path.isdir(fullname):
!             subdirs.append(fullname)
!         elif ispython(name):
!             if fix(fullname): bad = 1
!     for fullname in subdirs:
!         if recursedown(fullname): bad = 1
!     return bad
  
  def fix(filename):
! ##      dbg('fix(' + `filename` + ')\n')
!     try:
!         f = open(filename, 'r')
!     except IOError, msg:
!         err(filename + ': cannot open: ' + `msg` + '\n')
!         return 1
!     head, tail = os.path.split(filename)
!     tempname = os.path.join(head, '@' + tail)
!     g = None
!     # If we find a match, we rewind the file and start over but
!     # now copy everything to a temp file.
!     lineno = 0
!     while 1:
!         line = f.readline()
!         if not line: break
!         lineno = lineno + 1
!         while line[-2:] == '\\\n':
!             nextline = f.readline()
!             if not nextline: break
!             line = line + nextline
!             lineno = lineno + 1
!         newline = fixline(line)
!         if newline != line:
!             if g is None:
!                 try:
!                     g = open(tempname, 'w')
!                 except IOError, msg:
!                     f.close()
!                     err(tempname+': cannot create: '+\
!                         `msg`+'\n')
!                     return 1
!                 f.seek(0)
!                 lineno = 0
!                 rep(filename + ':\n')
!                 continue # restart from the beginning
!             rep(`lineno` + '\n')
!             rep('< ' + line)
!             rep('> ' + newline)
!         if g is not None:
!             g.write(newline)
! 
!     # End of file
!     f.close()
!     if not g: return 0 # No changes
! 
!     # Finishing touch -- move files
! 
!     # First copy the file's mode to the temp file
!     try:
!         statbuf = os.stat(filename)
!         os.chmod(tempname, statbuf[ST_MODE] & 07777)
!     except os.error, msg:
!         err(tempname + ': warning: chmod failed (' + `msg` + ')\n')
!     # Then make a backup of the original file as filename~
!     try:
!         os.rename(filename, filename + '~')
!     except os.error, msg:
!         err(filename + ': warning: backup failed (' + `msg` + ')\n')
!     # Now move the temp file to the original file
!     try:
!         os.rename(tempname, filename)
!     except os.error, msg:
!         err(filename + ': rename failed (' + `msg` + ')\n')
!         return 1
!     # Return succes
!     return 0
  
  # This expression doesn't catch *all* class definition headers,
***************
*** 160,192 ****
  
  def fixline(line):
! 	if classprog.match(line) < 0: # No 'class' keyword -- no change
! 		return line
! 	
! 	(a0, b0), (a1, b1), (a2, b2) = classprog.regs[:3]
! 	# a0, b0 = Whole match (up to ':')
! 	# a1, b1 = First subexpression (up to classname)
! 	# a2, b2 = Second subexpression (=.*)
! 	head = line[:b1]
! 	tail = line[b0:] # Unmatched rest of line
! 	
! 	if a2 == b2: # No base classes -- easy case
! 		return head + ':' + tail
! 	
! 	# Get rid of leading '='
! 	basepart = line[a2+1:b2]
! 
! 	# Extract list of base expressions
! 	bases = string.splitfields(basepart, ',')
! 	
! 	# Strip trailing '()' from each base expression
! 	for i in range(len(bases)):
! 		if baseprog.match(bases[i]) >= 0:
! 			x1, y1 = baseprog.regs[1]
! 			bases[i] = bases[i][x1:y1]
! 	
! 	# Join the bases back again and build the new line
! 	basepart = string.joinfields(bases, ', ')
! 	
! 	return head + '(' + basepart + '):' + tail
  
  main()
--- 160,192 ----
  
  def fixline(line):
!     if classprog.match(line) < 0: # No 'class' keyword -- no change
!         return line
! 
!     (a0, b0), (a1, b1), (a2, b2) = classprog.regs[:3]
!     # a0, b0 = Whole match (up to ':')
!     # a1, b1 = First subexpression (up to classname)
!     # a2, b2 = Second subexpression (=.*)
!     head = line[:b1]
!     tail = line[b0:] # Unmatched rest of line
! 
!     if a2 == b2: # No base classes -- easy case
!         return head + ':' + tail
! 
!     # Get rid of leading '='
!     basepart = line[a2+1:b2]
! 
!     # Extract list of base expressions
!     bases = string.splitfields(basepart, ',')
! 
!     # Strip trailing '()' from each base expression
!     for i in range(len(bases)):
!         if baseprog.match(bases[i]) >= 0:
!             x1, y1 = baseprog.regs[1]
!             bases[i] = bases[i][x1:y1]
! 
!     # Join the bases back again and build the new line
!     basepart = string.joinfields(bases, ', ')
! 
!     return head + '(' + basepart + '):' + tail
  
  main()

Index: copytime.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/copytime.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** copytime.py	1996/11/27 19:44:09	1.4
--- copytime.py	2001/01/17 08:48:39	1.5
***************
*** 8,25 ****
  
  def main():
! 	if len(sys.argv) <> 3:
! 		sys.stderr.write('usage: copytime source destination\n')
! 		sys.exit(2)
! 	file1, file2 = sys.argv[1], sys.argv[2]
! 	try:
! 		stat1 = os.stat(file1)
! 	except os.error:
! 		sys.stderr.write(file1 + ': cannot stat\n')
! 		sys.exit(1)
! 	try:
! 		os.utime(file2, (stat1[ST_ATIME], stat1[ST_MTIME]))
! 	except os.error:
! 		sys.stderr.write(file2 + ': cannot change time\n')
! 		sys.exit(2)
  
  main()
--- 8,25 ----
  
  def main():
!     if len(sys.argv) <> 3:
!         sys.stderr.write('usage: copytime source destination\n')
!         sys.exit(2)
!     file1, file2 = sys.argv[1], sys.argv[2]
!     try:
!         stat1 = os.stat(file1)
!     except os.error:
!         sys.stderr.write(file1 + ': cannot stat\n')
!         sys.exit(1)
!     try:
!         os.utime(file2, (stat1[ST_ATIME], stat1[ST_MTIME]))
!     except os.error:
!         sys.stderr.write(file2 + ': cannot change time\n')
!         sys.exit(2)
  
  main()

Index: dutree.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/dutree.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** dutree.py	1999/04/02 22:18:25	1.8
--- dutree.py	2001/01/17 08:48:39	1.9
***************
*** 5,59 ****
  
  def main():
! 	p = os.popen('du ' + string.join(sys.argv[1:]), 'r')
! 	total, d = None, {}
! 	for line in p.readlines():
! 		i = 0
! 		while line[i] in '0123456789': i = i+1
! 		size = eval(line[:i])
! 		while line[i] in ' \t': i = i+1
! 		file = line[i:-1]
! 		comps = string.splitfields(file, '/')
! 		if comps[0] == '': comps[0] = '/'
! 		if comps[len(comps)-1] == '': del comps[len(comps)-1]
! 		total, d = store(size, comps, total, d)
! 	try:
! 		display(total, d)
! 	except IOError, e:
! 		if e.errno != errno.EPIPE:
! 			raise
  
  def store(size, comps, total, d):
! 	if comps == []:
! 		return size, d
! 	if not d.has_key(comps[0]):
! 		d[comps[0]] = None, {}
! 	t1, d1 = d[comps[0]]
! 	d[comps[0]] = store(size, comps[1:], t1, d1)
! 	return total, d
  
  def display(total, d):
! 	show(total, d, '')
  
  def show(total, d, prefix):
! 	if not d: return
! 	list = []
! 	sum = 0
! 	for key in d.keys():
! 		tsub, dsub = d[key]
! 		list.append((tsub, key))
! 		if tsub is not None: sum = sum + tsub
! ## 	if sum < total:
! ## 		list.append((total - sum, os.curdir))
! 	list.sort()
! 	list.reverse()
! 	width = len(`list[0][0]`)
! 	for tsub, key in list:
! 		if tsub is None:
! 			psub = prefix
! 		else:
! 			print prefix + string.rjust(`tsub`, width) + ' ' + key
! 			psub = prefix + ' '*(width-1) + '|' + ' '*(len(key)+1)
! 		if d.has_key(key):
! 			show(tsub, d[key][1], psub)
  
  main()
--- 5,59 ----
  
  def main():
!     p = os.popen('du ' + string.join(sys.argv[1:]), 'r')
!     total, d = None, {}
!     for line in p.readlines():
!         i = 0
!         while line[i] in '0123456789': i = i+1
!         size = eval(line[:i])
!         while line[i] in ' \t': i = i+1
!         file = line[i:-1]
!         comps = string.splitfields(file, '/')
!         if comps[0] == '': comps[0] = '/'
!         if comps[len(comps)-1] == '': del comps[len(comps)-1]
!         total, d = store(size, comps, total, d)
!     try:
!         display(total, d)
!     except IOError, e:
!         if e.errno != errno.EPIPE:
!             raise
  
  def store(size, comps, total, d):
!     if comps == []:
!         return size, d
!     if not d.has_key(comps[0]):
!         d[comps[0]] = None, {}
!     t1, d1 = d[comps[0]]
!     d[comps[0]] = store(size, comps[1:], t1, d1)
!     return total, d
  
  def display(total, d):
!     show(total, d, '')
  
  def show(total, d, prefix):
!     if not d: return
!     list = []
!     sum = 0
!     for key in d.keys():
!         tsub, dsub = d[key]
!         list.append((tsub, key))
!         if tsub is not None: sum = sum + tsub
! ##      if sum < total:
! ##              list.append((total - sum, os.curdir))
!     list.sort()
!     list.reverse()
!     width = len(`list[0][0]`)
!     for tsub, key in list:
!         if tsub is None:
!             psub = prefix
!         else:
!             print prefix + string.rjust(`tsub`, width) + ' ' + key
!             psub = prefix + ' '*(width-1) + '|' + ' '*(len(key)+1)
!         if d.has_key(key):
!             show(tsub, d[key][1], psub)
  
  main()

Index: findlinksto.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/findlinksto.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** findlinksto.py	1996/11/27 19:44:14	1.7
--- findlinksto.py	2001/01/17 08:48:39	1.8
***************
*** 11,42 ****
  
  def main():
! 	try:
! 		opts, args = getopt.getopt(sys.argv[1:], '')
! 		if len(args) < 2:
! 			raise getopt.error, 'not enough arguments'
! 	except getopt.error, msg:
! 		sys.stdout = sys.stderr
! 		print msg
! 		print 'usage: findlinksto pattern directory ...'
! 		sys.exit(2)
! 	pat, dirs = args[0], args[1:]
! 	prog = regex.compile(pat)
! 	for dirname in dirs:
! 		os.path.walk(dirname, visit, prog)
  
  def visit(prog, dirname, names):
! 	if os.path.islink(dirname):
! 		names[:] = []
! 		return
! 	if os.path.ismount(dirname):
! 		print 'descend into', dirname
! 	for name in names:
! 		name = os.path.join(dirname, name)
! 		try:
! 			linkto = os.readlink(name)
! 			if prog.search(linkto) >= 0:
! 				print name, '->', linkto
! 		except os.error:
! 			pass
  
  main()
--- 11,42 ----
  
  def main():
!     try:
!         opts, args = getopt.getopt(sys.argv[1:], '')
!         if len(args) < 2:
!             raise getopt.error, 'not enough arguments'
!     except getopt.error, msg:
!         sys.stdout = sys.stderr
!         print msg
!         print 'usage: findlinksto pattern directory ...'
!         sys.exit(2)
!     pat, dirs = args[0], args[1:]
!     prog = regex.compile(pat)
!     for dirname in dirs:
!         os.path.walk(dirname, visit, prog)
  
  def visit(prog, dirname, names):
!     if os.path.islink(dirname):
!         names[:] = []
!         return
!     if os.path.ismount(dirname):
!         print 'descend into', dirname
!     for name in names:
!         name = os.path.join(dirname, name)
!         try:
!             linkto = os.readlink(name)
!             if prog.search(linkto) >= 0:
!                 print name, '->', linkto
!         except os.error:
!             pass
  
  main()

Index: fixcid.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/fixcid.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** fixcid.py	1997/05/15 21:51:16	1.7
--- fixcid.py	2001/01/17 08:48:39	1.8
***************
*** 47,195 ****
  
  def usage():
! 	progname = sys.argv[0]
! 	err('Usage: ' + progname +
! 		  ' [-c] [-r] [-s file] ... file-or-directory ...\n')
! 	err('\n')
! 	err('-c           : substitute inside comments\n')
! 	err('-r           : reverse direction for following -s options\n')
! 	err('-s substfile : add a file of substitutions\n')
! 	err('\n')
! 	err('Each non-empty non-comment line in a substitution file must\n')
! 	err('contain exactly two words: an identifier and its replacement.\n')
! 	err('Comments start with a # character and end at end of line.\n')
! 	err('If an identifier is preceded with a *, it is not substituted\n')
! 	err('inside a comment even when -c is specified.\n')
  
  def main():
! 	try:
! 		opts, args = getopt.getopt(sys.argv[1:], 'crs:')
! 	except getopt.error, msg:
! 		err('Options error: ' + str(msg) + '\n')
! 		usage()
! 		sys.exit(2)
! 	bad = 0
! 	if not args: # No arguments
! 		usage()
! 		sys.exit(2)
! 	for opt, arg in opts:
! 		if opt == '-c':
! 			setdocomments()
! 		if opt == '-r':
! 			setreverse()
! 		if opt == '-s':
! 			addsubst(arg)
! 	for arg in args:
! 		if os.path.isdir(arg):
! 			if recursedown(arg): bad = 1
! 		elif os.path.islink(arg):
! 			err(arg + ': will not process symbolic links\n')
! 			bad = 1
! 		else:
! 			if fix(arg): bad = 1
! 	sys.exit(bad)
  
  # Change this regular expression to select a different set of files
  Wanted = '^[a-zA-Z0-9_]+\.[ch]$'
  def wanted(name):
! 	return regex.match(Wanted, name) >= 0
  
  def recursedown(dirname):
! 	dbg('recursedown(' + `dirname` + ')\n')
! 	bad = 0
! 	try:
! 		names = os.listdir(dirname)
! 	except os.error, msg:
! 		err(dirname + ': cannot list directory: ' + str(msg) + '\n')
! 		return 1
! 	names.sort()
! 	subdirs = []
! 	for name in names:
! 		if name in (os.curdir, os.pardir): continue
! 		fullname = os.path.join(dirname, name)
! 		if os.path.islink(fullname): pass
! 		elif os.path.isdir(fullname):
! 			subdirs.append(fullname)
! 		elif wanted(name):
! 			if fix(fullname): bad = 1
! 	for fullname in subdirs:
! 		if recursedown(fullname): bad = 1
! 	return bad
  
  def fix(filename):
! ##	dbg('fix(' + `filename` + ')\n')
! 	if filename == '-':
! 		# Filter mode
! 		f = sys.stdin
! 		g = sys.stdout
! 	else:
! 		# File replacement mode
! 		try:
! 			f = open(filename, 'r')
! 		except IOError, msg:
! 			err(filename + ': cannot open: ' + str(msg) + '\n')
! 			return 1
! 		head, tail = os.path.split(filename)
! 		tempname = os.path.join(head, '@' + tail)
! 		g = None
! 	# If we find a match, we rewind the file and start over but
! 	# now copy everything to a temp file.
! 	lineno = 0
! 	initfixline()
! 	while 1:
! 		line = f.readline()
! 		if not line: break
! 		lineno = lineno + 1
! 		while line[-2:] == '\\\n':
! 			nextline = f.readline()
! 			if not nextline: break
! 			line = line + nextline
! 			lineno = lineno + 1
! 		newline = fixline(line)
! 		if newline != line:
! 			if g is None:
! 				try:
! 					g = open(tempname, 'w')
! 				except IOError, msg:
! 					f.close()
! 					err(tempname+': cannot create: '+
! 					    str(msg)+'\n')
! 					return 1
! 				f.seek(0)
! 				lineno = 0
! 				initfixline()
! 				rep(filename + ':\n')
! 				continue # restart from the beginning
! 			rep(`lineno` + '\n')
! 			rep('< ' + line)
! 			rep('> ' + newline)
! 		if g is not None:
! 			g.write(newline)
! 
! 	# End of file
! 	if filename == '-': return 0 # Done in filter mode
! 	f.close()
! 	if not g: return 0 # No changes
! 
! 	# Finishing touch -- move files
! 
! 	# First copy the file's mode to the temp file
! 	try:
! 		statbuf = os.stat(filename)
! 		os.chmod(tempname, statbuf[ST_MODE] & 07777)
! 	except os.error, msg:
! 		err(tempname + ': warning: chmod failed (' + str(msg) + ')\n')
! 	# Then make a backup of the original file as filename~
! 	try:
! 		os.rename(filename, filename + '~')
! 	except os.error, msg:
! 		err(filename + ': warning: backup failed (' + str(msg) + ')\n')
! 	# Now move the temp file to the original file
! 	try:
! 		os.rename(tempname, filename)
! 	except os.error, msg:
! 		err(filename + ': rename failed (' + str(msg) + ')\n')
! 		return 1
! 	# Return succes
! 	return 0
  
  # Tokenizing ANSI C (partly)
--- 47,195 ----
  
  def usage():
!     progname = sys.argv[0]
!     err('Usage: ' + progname +
!               ' [-c] [-r] [-s file] ... file-or-directory ...\n')
!     err('\n')
!     err('-c           : substitute inside comments\n')
!     err('-r           : reverse direction for following -s options\n')
!     err('-s substfile : add a file of substitutions\n')
!     err('\n')
!     err('Each non-empty non-comment line in a substitution file must\n')
!     err('contain exactly two words: an identifier and its replacement.\n')
!     err('Comments start with a # character and end at end of line.\n')
!     err('If an identifier is preceded with a *, it is not substituted\n')
!     err('inside a comment even when -c is specified.\n')
  
  def main():
!     try:
!         opts, args = getopt.getopt(sys.argv[1:], 'crs:')
!     except getopt.error, msg:
!         err('Options error: ' + str(msg) + '\n')
!         usage()
!         sys.exit(2)
!     bad = 0
!     if not args: # No arguments
!         usage()
!         sys.exit(2)
!     for opt, arg in opts:
!         if opt == '-c':
!             setdocomments()
!         if opt == '-r':
!             setreverse()
!         if opt == '-s':
!             addsubst(arg)
!     for arg in args:
!         if os.path.isdir(arg):
!             if recursedown(arg): bad = 1
!         elif os.path.islink(arg):
!             err(arg + ': will not process symbolic links\n')
!             bad = 1
!         else:
!             if fix(arg): bad = 1
!     sys.exit(bad)
  
  # Change this regular expression to select a different set of files
  Wanted = '^[a-zA-Z0-9_]+\.[ch]$'
  def wanted(name):
!     return regex.match(Wanted, name) >= 0
  
  def recursedown(dirname):
!     dbg('recursedown(' + `dirname` + ')\n')
!     bad = 0
!     try:
!         names = os.listdir(dirname)
!     except os.error, msg:
!         err(dirname + ': cannot list directory: ' + str(msg) + '\n')
!         return 1
!     names.sort()
!     subdirs = []
!     for name in names:
!         if name in (os.curdir, os.pardir): continue
!         fullname = os.path.join(dirname, name)
!         if os.path.islink(fullname): pass
!         elif os.path.isdir(fullname):
!             subdirs.append(fullname)
!         elif wanted(name):
!             if fix(fullname): bad = 1
!     for fullname in subdirs:
!         if recursedown(fullname): bad = 1
!     return bad
  
  def fix(filename):
! ##      dbg('fix(' + `filename` + ')\n')
!     if filename == '-':
!         # Filter mode
!         f = sys.stdin
!         g = sys.stdout
!     else:
!         # File replacement mode
!         try:
!             f = open(filename, 'r')
!         except IOError, msg:
!             err(filename + ': cannot open: ' + str(msg) + '\n')
!             return 1
!         head, tail = os.path.split(filename)
!         tempname = os.path.join(head, '@' + tail)
!         g = None
!     # If we find a match, we rewind the file and start over but
!     # now copy everything to a temp file.
!     lineno = 0
!     initfixline()
!     while 1:
!         line = f.readline()
!         if not line: break
!         lineno = lineno + 1
!         while line[-2:] == '\\\n':
!             nextline = f.readline()
!             if not nextline: break
!             line = line + nextline
!             lineno = lineno + 1
!         newline = fixline(line)
!         if newline != line:
!             if g is None:
!                 try:
!                     g = open(tempname, 'w')
!                 except IOError, msg:
!                     f.close()
!                     err(tempname+': cannot create: '+
!                         str(msg)+'\n')
!                     return 1
!                 f.seek(0)
!                 lineno = 0
!                 initfixline()
!                 rep(filename + ':\n')
!                 continue # restart from the beginning
!             rep(`lineno` + '\n')
!             rep('< ' + line)
!             rep('> ' + newline)
!         if g is not None:
!             g.write(newline)
! 
!     # End of file
!     if filename == '-': return 0 # Done in filter mode
!     f.close()
!     if not g: return 0 # No changes
! 
!     # Finishing touch -- move files
! 
!     # First copy the file's mode to the temp file
!     try:
!         statbuf = os.stat(filename)
!         os.chmod(tempname, statbuf[ST_MODE] & 07777)
!     except os.error, msg:
!         err(tempname + ': warning: chmod failed (' + str(msg) + ')\n')
!     # Then make a backup of the original file as filename~
!     try:
!         os.rename(filename, filename + '~')
!     except os.error, msg:
!         err(filename + ': warning: backup failed (' + str(msg) + ')\n')
!     # Now move the temp file to the original file
!     try:
!         os.rename(tempname, filename)
!     except os.error, msg:
!         err(filename + ': rename failed (' + str(msg) + ')\n')
!         return 1
!     # Return succes
!     return 0
  
  # Tokenizing ANSI C (partly)
***************
*** 222,318 ****
  
  def initfixline():
! 	global Program
! 	Program = OutsideCommentProgram
  
  def fixline(line):
! 	global Program
! ##	print '-->', `line`
! 	i = 0
! 	while i < len(line):
! 		i = Program.search(line, i)
! 		if i < 0: break
! 		found = Program.group(0)
! ##		if Program is InsideCommentProgram: print '...',
! ##		else: print '   ',
! ##		print found
! 		if len(found) == 2:
! 			if found == '/*':
! 				Program = InsideCommentProgram
! 			elif found == '*/':
! 				Program = OutsideCommentProgram
! 		n = len(found)
! 		if Dict.has_key(found):
! 			subst = Dict[found]
! 			if Program is InsideCommentProgram:
! 				if not Docomments:
! 					print 'Found in comment:', found
! 					i = i + n
! 					continue
! 				if NotInComment.has_key(found):
! ##					print 'Ignored in comment:',
! ##					print found, '-->', subst
! ##					print 'Line:', line,
! 					subst = found
! ##				else:
! ##					print 'Substituting in comment:',
! ##					print found, '-->', subst
! ##					print 'Line:', line,
! 			line = line[:i] + subst + line[i+n:]
! 			n = len(subst)
! 		i = i + n
! 	return line
  
  Docomments = 0
  def setdocomments():
! 	global Docomments
! 	Docomments = 1
  
  Reverse = 0
  def setreverse():
! 	global Reverse
! 	Reverse = (not Reverse)
  
  Dict = {}
  NotInComment = {}
  def addsubst(substfile):
! 	try:
! 		fp = open(substfile, 'r')
! 	except IOError, msg:
! 		err(substfile + ': cannot read substfile: ' + str(msg) + '\n')
! 		sys.exit(1)
! 	lineno = 0
! 	while 1:
! 		line = fp.readline()
! 		if not line: break
! 		lineno = lineno + 1
! 		try:
! 			i = string.index(line, '#')
! 		except string.index_error:
! 			i = -1		# Happens to delete trailing \n
! 		words = string.split(line[:i])
! 		if not words: continue
! 		if len(words) == 3 and words[0] == 'struct':
! 			words[:2] = [words[0] + ' ' + words[1]]
! 		elif len(words) <> 2:
! 			err(substfile + ':' + `lineno` +
! 				  ': warning: bad line: ' + line)
! 			continue
! 		if Reverse:
! 			[value, key] = words
! 		else:
! 			[key, value] = words
! 		if value[0] == '*':
! 			value = value[1:]
! 		if key[0] == '*':
! 			key = key[1:]
! 			NotInComment[key] = value
! 		if Dict.has_key(key):
! 			err(substfile + ':' + `lineno` +
! 				  ': warning: overriding: ' +
! 				  key + ' ' + value + '\n')
! 			err(substfile + ':' + `lineno` +
! 				  ': warning: previous: ' + Dict[key] + '\n')
! 		Dict[key] = value
! 	fp.close()
  
  main()
--- 222,318 ----
  
  def initfixline():
!     global Program
!     Program = OutsideCommentProgram
  
  def fixline(line):
!     global Program
! ##      print '-->', `line`
!     i = 0
!     while i < len(line):
!         i = Program.search(line, i)
!         if i < 0: break
!         found = Program.group(0)
! ##              if Program is InsideCommentProgram: print '...',
! ##              else: print '   ',
! ##              print found
!         if len(found) == 2:
!             if found == '/*':
!                 Program = InsideCommentProgram
!             elif found == '*/':
!                 Program = OutsideCommentProgram
!         n = len(found)
!         if Dict.has_key(found):
!             subst = Dict[found]
!             if Program is InsideCommentProgram:
!                 if not Docomments:
!                     print 'Found in comment:', found
!                     i = i + n
!                     continue
!                 if NotInComment.has_key(found):
! ##                                      print 'Ignored in comment:',
! ##                                      print found, '-->', subst
! ##                                      print 'Line:', line,
!                     subst = found
! ##                              else:
! ##                                      print 'Substituting in comment:',
! ##                                      print found, '-->', subst
! ##                                      print 'Line:', line,
!             line = line[:i] + subst + line[i+n:]
!             n = len(subst)
!         i = i + n
!     return line
  
  Docomments = 0
  def setdocomments():
!     global Docomments
!     Docomments = 1
  
  Reverse = 0
  def setreverse():
!     global Reverse
!     Reverse = (not Reverse)
  
  Dict = {}
  NotInComment = {}
  def addsubst(substfile):
!     try:
!         fp = open(substfile, 'r')
!     except IOError, msg:
!         err(substfile + ': cannot read substfile: ' + str(msg) + '\n')
!         sys.exit(1)
!     lineno = 0
!     while 1:
!         line = fp.readline()
!         if not line: break
!         lineno = lineno + 1
!         try:
!             i = string.index(line, '#')
!         except string.index_error:
!             i = -1          # Happens to delete trailing \n
!         words = string.split(line[:i])
!         if not words: continue
!         if len(words) == 3 and words[0] == 'struct':
!             words[:2] = [words[0] + ' ' + words[1]]
!         elif len(words) <> 2:
!             err(substfile + ':' + `lineno` +
!                       ': warning: bad line: ' + line)
!             continue
!         if Reverse:
!             [value, key] = words
!         else:
!             [key, value] = words
!         if value[0] == '*':
!             value = value[1:]
!         if key[0] == '*':
!             key = key[1:]
!             NotInComment[key] = value
!         if Dict.has_key(key):
!             err(substfile + ':' + `lineno` +
!                       ': warning: overriding: ' +
!                       key + ' ' + value + '\n')
!             err(substfile + ':' + `lineno` +
!                       ': warning: previous: ' + Dict[key] + '\n')
!         Dict[key] = value
!     fp.close()
  
  main()

Index: fixheader.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/fixheader.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** fixheader.py	1996/11/27 19:44:17	1.2
--- fixheader.py	2001/01/17 08:48:39	1.3
***************
*** 7,49 ****
  
  def main():
! 	args = sys.argv[1:]
! 	for file in args:
! 		process(file)
  
  def process(file):
! 	try:
! 		f = open(file, 'r')
! 	except IOError, msg:
! 		sys.stderr.write('%s: can\'t open: %s\n' % (file, str(msg)))
! 		return
! 	data = f.read()
! 	f.close()
! 	if data[:2] <> '/*':
! 		sys.stderr.write('%s does not begin with C comment\n' % file)
! 		return
! 	try:
! 		f = open(file, 'w')
! 	except IOError, msg:
! 		sys.stderr.write('%s: can\'t write: %s\n' % (file, str(msg)))
! 		return
! 	sys.stderr.write('Processing %s ...\n' % file)
! 	magic = 'Py_'
! 	for c in file:
! 		if c in string.letters + string.digits:
! 			magic = magic + string.upper(c)
! 		else: magic = magic + '_'
! 	sys.stdout = f
! 	print '#ifndef', magic
! 	print '#define', magic
! 	print '#ifdef __cplusplus'
! 	print 'extern "C" {'
! 	print '#endif'
! 	print
! 	f.write(data)
! 	print
! 	print '#ifdef __cplusplus'
! 	print '}'
! 	print '#endif'
! 	print '#endif /*', '!'+magic, '*/'
  
  main()
--- 7,49 ----
  
  def main():
!     args = sys.argv[1:]
!     for file in args:
!         process(file)
  
  def process(file):
!     try:
!         f = open(file, 'r')
!     except IOError, msg:
!         sys.stderr.write('%s: can\'t open: %s\n' % (file, str(msg)))
!         return
!     data = f.read()
!     f.close()
!     if data[:2] <> '/*':
!         sys.stderr.write('%s does not begin with C comment\n' % file)
!         return
!     try:
!         f = open(file, 'w')
!     except IOError, msg:
!         sys.stderr.write('%s: can\'t write: %s\n' % (file, str(msg)))
!         return
!     sys.stderr.write('Processing %s ...\n' % file)
!     magic = 'Py_'
!     for c in file:
!         if c in string.letters + string.digits:
!             magic = magic + string.upper(c)
!         else: magic = magic + '_'
!     sys.stdout = f
!     print '#ifndef', magic
!     print '#define', magic
!     print '#ifdef __cplusplus'
!     print 'extern "C" {'
!     print '#endif'
!     print
!     f.write(data)
!     print
!     print '#ifdef __cplusplus'
!     print '}'
!     print '#endif'
!     print '#endif /*', '!'+magic, '*/'
  
  main()

Index: fixps.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/fixps.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** fixps.py	1999/04/09 14:56:35	1.4
--- fixps.py	2001/01/17 08:48:39	1.5
***************
*** 9,32 ****
  
  def main():
! 	for file in sys.argv[1:]:
! 		try:
! 			f = open(file, 'r')
! 		except IOError, msg:
! 			print file, ': can\'t open :', msg
! 			continue
! 		line = f.readline()
! 		if not re.match('^#! */usr/local/bin/python', line):
! 			print file, ': not a /usr/local/bin/python script'
! 			f.close()
! 			continue
! 		rest = f.read()
! 		f.close()
! 		line = re.sub('/usr/local/bin/python',
! 			      '/usr/bin/env python', line)
! 		print file, ':', `line`
! 		f = open(file, "w")
! 		f.write(line)
! 		f.write(rest)
! 		f.close()
  
  
--- 9,32 ----
  
  def main():
!     for file in sys.argv[1:]:
!         try:
!             f = open(file, 'r')
!         except IOError, msg:
!             print file, ': can\'t open :', msg
!             continue
!         line = f.readline()
!         if not re.match('^#! */usr/local/bin/python', line):
!             print file, ': not a /usr/local/bin/python script'
!             f.close()
!             continue
!         rest = f.read()
!         f.close()
!         line = re.sub('/usr/local/bin/python',
!                       '/usr/bin/env python', line)
!         print file, ':', `line`
!         f = open(file, "w")
!         f.write(line)
!         f.write(rest)
!         f.close()
  
  

Index: ftpmirror.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/ftpmirror.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** ftpmirror.py	2000/09/16 22:09:51	1.12
--- ftpmirror.py	2001/01/17 08:48:39	1.13
***************
*** 5,9 ****
  usage: ftpmirror [-v] [-q] [-i] [-m] [-n] [-r] [-s pat]
                   [-l username [-p passwd [-a account]]]
! 		 hostname [remotedir [localdir]]
  -v: verbose
  -q: quiet
--- 5,9 ----
  usage: ftpmirror [-v] [-q] [-i] [-m] [-n] [-r] [-s pat]
                   [-l username [-p passwd [-a account]]]
!                  hostname [remotedir [localdir]]
  -v: verbose
  -q: quiet
***************
*** 29,36 ****
  # Print usage message and exit
  def usage(*args):
! 	sys.stdout = sys.stderr
! 	for msg in args: print msg
! 	print __doc__
! 	sys.exit(2)
  
  verbose = 1 # 0 for -q, 2 for -v
--- 29,36 ----
  # Print usage message and exit
  def usage(*args):
!     sys.stdout = sys.stderr
!     for msg in args: print msg
!     print __doc__
!     sys.exit(2)
  
  verbose = 1 # 0 for -q, 2 for -v
***************
*** 43,372 ****
  # Main program: parse command line and start processing
  def main():
! 	global verbose, interactive, mac, rmok, nologin
! 	try:
! 		opts, args = getopt.getopt(sys.argv[1:], 'a:bil:mnp:qrs:v')
! 	except getopt.error, msg:
! 		usage(msg)
! 	login = ''
! 	passwd = ''
! 	account = ''
! 	for o, a in opts:
! 		if o == '-l': login = a
! 		if o == '-p': passwd = a
! 		if o == '-a': account = a
! 		if o == '-v': verbose = verbose + 1
! 		if o == '-q': verbose = 0
! 		if o == '-i': interactive = 1
! 		if o == '-m': mac = 1; nologin = 1; skippats.append('*.o')
! 		if o == '-n': nologin = 1
! 		if o == '-r': rmok = 1
! 		if o == '-s': skippats.append(a)
! 	if not args: usage('hostname missing')
! 	host = args[0]
! 	remotedir = ''
! 	localdir = ''
! 	if args[1:]:
! 		remotedir = args[1]
! 		if args[2:]:
! 			localdir = args[2]
! 			if args[3:]: usage('too many arguments')
! 	#
! 	f = ftplib.FTP()
! 	if verbose: print 'Connecting to %s...' % `host`
! 	f.connect(host)
! 	if not nologin:
! 		if verbose:
! 			print 'Logging in as %s...' % `login or 'anonymous'`
! 		f.login(login, passwd, account)
! 	if verbose: print 'OK.'
! 	pwd = f.pwd()
! 	if verbose > 1: print 'PWD =', `pwd`
! 	if remotedir:
! 		if verbose > 1: print 'cwd(%s)' % `remotedir`
! 		f.cwd(remotedir)
! 		if verbose > 1: print 'OK.'
! 		pwd = f.pwd()
! 		if verbose > 1: print 'PWD =', `pwd`
! 	#
! 	mirrorsubdir(f, localdir)
  
  # Core logic: mirror one subdirectory (recursively)
  def mirrorsubdir(f, localdir):
! 	pwd = f.pwd()
! 	if localdir and not os.path.isdir(localdir):
! 		if verbose: print 'Creating local directory', `localdir`
! 		try:
! 		    makedir(localdir)
! 		except os.error, msg:
! 		    print "Failed to establish local directory", `localdir`
! 		    return
! 	infofilename = os.path.join(localdir, '.mirrorinfo')
! 	try:
! 		text = open(infofilename, 'r').read()
! 	except IOError, msg:
! 		text = '{}'
! 	try:
! 		info = eval(text)
! 	except (SyntaxError, NameError):
! 		print 'Bad mirror info in %s' % `infofilename`
! 		info = {}
! 	subdirs = []
! 	listing = []
! 	if verbose: print 'Listing remote directory %s...' % `pwd`
! 	f.retrlines('LIST', listing.append)
! 	filesfound = []
! 	for line in listing:
! 		if verbose > 1: print '-->', `line`
! 		if mac:
! 			# Mac listing has just filenames;
! 			# trailing / means subdirectory
! 			filename = string.strip(line)
! 			mode = '-'
! 			if filename[-1:] == '/':
! 				filename = filename[:-1]
! 				mode = 'd'
! 			infostuff = ''
! 		else:
! 			# Parse, assuming a UNIX listing
! 			words = string.split(line, None, 8)
! 			if len(words) < 6:
! 				if verbose > 1: print 'Skipping short line'
! 				continue
! 			filename = string.lstrip(words[-1])
! 			i = string.find(filename, " -> ")
! 			if i >= 0:
! 				# words[0] had better start with 'l'...
! 				if verbose > 1:
! 				    print 'Found symbolic link %s' % `filename`
! 				linkto = filename[i+4:]
! 				filename = filename[:i]
! 			infostuff = words[-5:-1]
! 			mode = words[0]
! 		skip = 0
! 		for pat in skippats:
! 			if fnmatch(filename, pat):
! 				if verbose > 1:
! 					print 'Skip pattern', `pat`,
! 					print 'matches', `filename`
! 				skip = 1
! 				break
! 		if skip:
! 			continue
! 		if mode[0] == 'd':
! 			if verbose > 1:
! 				print 'Remembering subdirectory', `filename`
! 			subdirs.append(filename)
! 			continue
! 		filesfound.append(filename)
! 		if info.has_key(filename) and info[filename] == infostuff:
! 			if verbose > 1:
! 				print 'Already have this version of',`filename`
! 			continue
! 		fullname = os.path.join(localdir, filename)
! 		tempname = os.path.join(localdir, '@'+filename)
! 		if interactive:
! 			doit = askabout('file', filename, pwd)
! 			if not doit:
! 				if not info.has_key(filename):
! 					info[filename] = 'Not retrieved'
! 				continue
! 		try:
! 			os.unlink(tempname)
! 		except os.error:
! 			pass
! 		if mode[0] == 'l':
! 			if verbose:
! 				print "Creating symlink %s -> %s" % (
! 					`filename`, `linkto`)
! 			try:
! 				os.symlink(linkto, tempname)
! 			except IOError, msg:
! 				print "Can't create %s: %s" % (
! 					`tempname`, str(msg))
! 				continue
! 		else:
! 			try:
! 				fp = open(tempname, 'wb')
! 			except IOError, msg:
! 				print "Can't create %s: %s" % (
! 					`tempname`, str(msg))
! 				continue
! 			if verbose:
! 				print 'Retrieving %s from %s as %s...' % \
! 					  (`filename`, `pwd`, `fullname`)
! 			if verbose:
! 				fp1 = LoggingFile(fp, 1024, sys.stdout)
! 			else:
! 				fp1 = fp
! 			t0 = time.time()
! 			try:
! 				f.retrbinary('RETR ' + filename,
! 					     fp1.write, 8*1024)
! 			except ftplib.error_perm, msg:
! 				print msg
! 			t1 = time.time()
! 			bytes = fp.tell()
! 			fp.close()
! 			if fp1 != fp:
! 				fp1.close()
! 		try:
! 			os.unlink(fullname)
! 		except os.error:
! 			pass		# Ignore the error
! 		try:
! 			os.rename(tempname, fullname)
! 		except os.error, msg:
! 			print "Can't rename %s to %s: %s" % (`tempname`,
! 							     `fullname`,
! 							     str(msg))
! 			continue
! 		info[filename] = infostuff
! 		writedict(info, infofilename)
! 		if verbose and mode[0] != 'l':
! 			dt = t1 - t0
! 			kbytes = bytes / 1024.0
! 			print int(round(kbytes)),
! 			print 'Kbytes in',
! 			print int(round(dt)),
! 			print 'seconds',
! 			if t1 > t0:
! 				print '(~%d Kbytes/sec)' % \
! 					  int(round(kbytes/dt),)
! 			print
! 	#
! 	# Remove files from info that are no longer remote
! 	deletions = 0
! 	for filename in info.keys():
! 		if filename not in filesfound:
! 			if verbose:
! 				print "Removing obsolete info entry for",
! 				print `filename`, "in", `localdir or "."`
! 			del info[filename]
! 			deletions = deletions + 1
! 	if deletions:
! 		writedict(info, infofilename)
! 	#
! 	# Remove local files that are no longer in the remote directory
! 	try:
! 	    if not localdir: names = os.listdir(os.curdir)
! 	    else: names = os.listdir(localdir)
! 	except os.error:
! 	    names = []
! 	for name in names:
! 		if name[0] == '.' or info.has_key(name) or name in subdirs:
! 			continue
! 		skip = 0
! 		for pat in skippats:
! 			if fnmatch(name, pat):
! 				if verbose > 1:
! 					print 'Skip pattern', `pat`,
! 					print 'matches', `name`
! 				skip = 1
! 				break
! 		if skip:
! 			continue
! 		fullname = os.path.join(localdir, name)
! 		if not rmok:
! 			if verbose:
! 				print 'Local file', `fullname`,
! 				print 'is no longer pertinent'
! 			continue
! 		if verbose: print 'Removing local file/dir', `fullname`
! 		remove(fullname)
! 	#
! 	# Recursively mirror subdirectories
! 	for subdir in subdirs:
! 		if interactive:
! 			doit = askabout('subdirectory', subdir, pwd)
! 			if not doit: continue
! 		if verbose: print 'Processing subdirectory', `subdir`
! 		localsubdir = os.path.join(localdir, subdir)
! 		pwd = f.pwd()
! 		if verbose > 1:
! 			print 'Remote directory now:', `pwd`
! 			print 'Remote cwd', `subdir`
! 		try:
! 			f.cwd(subdir)
! 		except ftplib.error_perm, msg:
! 			print "Can't chdir to", `subdir`, ":", `msg`
! 		else:
! 			if verbose: print 'Mirroring as', `localsubdir`
! 			mirrorsubdir(f, localsubdir)
! 			if verbose > 1: print 'Remote cwd ..'
! 			f.cwd('..')
! 		newpwd = f.pwd()
! 		if newpwd != pwd:
! 			print 'Ended up in wrong directory after cd + cd ..'
! 			print 'Giving up now.'
! 			break
! 		else:
! 			if verbose > 1: print 'OK.'
  
  # Helper to remove a file or directory tree
  def remove(fullname):
! 	if os.path.isdir(fullname) and not os.path.islink(fullname):
! 		try:
! 			names = os.listdir(fullname)
! 		except os.error:
! 			names = []
! 		ok = 1
! 		for name in names:
! 			if not remove(os.path.join(fullname, name)):
! 				ok = 0
! 		if not ok:
! 			return 0
! 		try:
! 			os.rmdir(fullname)
! 		except os.error, msg:
! 			print "Can't remove local directory %s: %s" % \
! 			      (`fullname`, str(msg))
! 			return 0
! 	else:
! 		try:
! 			os.unlink(fullname)
! 		except os.error, msg:
! 			print "Can't remove local file %s: %s" % \
! 			      (`fullname`, str(msg))
! 			return 0
! 	return 1
  
  # Wrapper around a file for writing to write a hash sign every block.
  class LoggingFile:
! 	def __init__(self, fp, blocksize, outfp):
! 		self.fp = fp
! 		self.bytes = 0
! 		self.hashes = 0
! 		self.blocksize = blocksize
! 		self.outfp = outfp
! 	def write(self, data):
! 		self.bytes = self.bytes + len(data)
! 		hashes = int(self.bytes) / self.blocksize
! 		while hashes > self.hashes:
! 			self.outfp.write('#')
! 			self.outfp.flush()
! 			self.hashes = self.hashes + 1
! 		self.fp.write(data)
! 	def close(self):
! 		self.outfp.write('\n')
  
  # Ask permission to download a file.
  def askabout(filetype, filename, pwd):
! 	prompt = 'Retrieve %s %s from %s ? [ny] ' % (filetype, filename, pwd)
! 	while 1:
! 		reply = string.lower(string.strip(raw_input(prompt)))
! 		if reply in ['y', 'ye', 'yes']:
! 			return 1
! 		if reply in ['', 'n', 'no', 'nop', 'nope']:
! 			return 0
! 		print 'Please answer yes or no.'
  
  # Create a directory if it doesn't exist.  Recursively create the
  # parent directory as well if needed.
  def makedir(pathname):
! 	if os.path.isdir(pathname):
! 		return
! 	dirname = os.path.dirname(pathname)
! 	if dirname: makedir(dirname)
! 	os.mkdir(pathname, 0777)
  
  # Write a dictionary to a file in a way that can be read back using
--- 43,372 ----
  # Main program: parse command line and start processing
  def main():
!     global verbose, interactive, mac, rmok, nologin
!     try:
!         opts, args = getopt.getopt(sys.argv[1:], 'a:bil:mnp:qrs:v')
!     except getopt.error, msg:
!         usage(msg)
!     login = ''
!     passwd = ''
!     account = ''
!     for o, a in opts:
!         if o == '-l': login = a
!         if o == '-p': passwd = a
!         if o == '-a': account = a
!         if o == '-v': verbose = verbose + 1
!         if o == '-q': verbose = 0
!         if o == '-i': interactive = 1
!         if o == '-m': mac = 1; nologin = 1; skippats.append('*.o')
!         if o == '-n': nologin = 1
!         if o == '-r': rmok = 1
!         if o == '-s': skippats.append(a)
!     if not args: usage('hostname missing')
!     host = args[0]
!     remotedir = ''
!     localdir = ''
!     if args[1:]:
!         remotedir = args[1]
!         if args[2:]:
!             localdir = args[2]
!             if args[3:]: usage('too many arguments')
!     #
!     f = ftplib.FTP()
!     if verbose: print 'Connecting to %s...' % `host`
!     f.connect(host)
!     if not nologin:
!         if verbose:
!             print 'Logging in as %s...' % `login or 'anonymous'`
!         f.login(login, passwd, account)
!     if verbose: print 'OK.'
!     pwd = f.pwd()
!     if verbose > 1: print 'PWD =', `pwd`
!     if remotedir:
!         if verbose > 1: print 'cwd(%s)' % `remotedir`
!         f.cwd(remotedir)
!         if verbose > 1: print 'OK.'
!         pwd = f.pwd()
!         if verbose > 1: print 'PWD =', `pwd`
!     #
!     mirrorsubdir(f, localdir)
  
  # Core logic: mirror one subdirectory (recursively)
  def mirrorsubdir(f, localdir):
!     pwd = f.pwd()
!     if localdir and not os.path.isdir(localdir):
!         if verbose: print 'Creating local directory', `localdir`
!         try:
!             makedir(localdir)
!         except os.error, msg:
!             print "Failed to establish local directory", `localdir`
!             return
!     infofilename = os.path.join(localdir, '.mirrorinfo')
!     try:
!         text = open(infofilename, 'r').read()
!     except IOError, msg:
!         text = '{}'
!     try:
!         info = eval(text)
!     except (SyntaxError, NameError):
!         print 'Bad mirror info in %s' % `infofilename`
!         info = {}
!     subdirs = []
!     listing = []
!     if verbose: print 'Listing remote directory %s...' % `pwd`
!     f.retrlines('LIST', listing.append)
!     filesfound = []
!     for line in listing:
!         if verbose > 1: print '-->', `line`
!         if mac:
!             # Mac listing has just filenames;
!             # trailing / means subdirectory
!             filename = string.strip(line)
!             mode = '-'
!             if filename[-1:] == '/':
!                 filename = filename[:-1]
!                 mode = 'd'
!             infostuff = ''
!         else:
!             # Parse, assuming a UNIX listing
!             words = string.split(line, None, 8)
!             if len(words) < 6:
!                 if verbose > 1: print 'Skipping short line'
!                 continue
!             filename = string.lstrip(words[-1])
!             i = string.find(filename, " -> ")
!             if i >= 0:
!                 # words[0] had better start with 'l'...
!                 if verbose > 1:
!                     print 'Found symbolic link %s' % `filename`
!                 linkto = filename[i+4:]
!                 filename = filename[:i]
!             infostuff = words[-5:-1]
!             mode = words[0]
!         skip = 0
!         for pat in skippats:
!             if fnmatch(filename, pat):
!                 if verbose > 1:
!                     print 'Skip pattern', `pat`,
!                     print 'matches', `filename`
!                 skip = 1
!                 break
!         if skip:
!             continue
!         if mode[0] == 'd':
!             if verbose > 1:
!                 print 'Remembering subdirectory', `filename`
!             subdirs.append(filename)
!             continue
!         filesfound.append(filename)
!         if info.has_key(filename) and info[filename] == infostuff:
!             if verbose > 1:
!                 print 'Already have this version of',`filename`
!             continue
!         fullname = os.path.join(localdir, filename)
!         tempname = os.path.join(localdir, '@'+filename)
!         if interactive:
!             doit = askabout('file', filename, pwd)
!             if not doit:
!                 if not info.has_key(filename):
!                     info[filename] = 'Not retrieved'
!                 continue
!         try:
!             os.unlink(tempname)
!         except os.error:
!             pass
!         if mode[0] == 'l':
!             if verbose:
!                 print "Creating symlink %s -> %s" % (
!                         `filename`, `linkto`)
!             try:
!                 os.symlink(linkto, tempname)
!             except IOError, msg:
!                 print "Can't create %s: %s" % (
!                         `tempname`, str(msg))
!                 continue
!         else:
!             try:
!                 fp = open(tempname, 'wb')
!             except IOError, msg:
!                 print "Can't create %s: %s" % (
!                         `tempname`, str(msg))
!                 continue
!             if verbose:
!                 print 'Retrieving %s from %s as %s...' % \
!                           (`filename`, `pwd`, `fullname`)
!             if verbose:
!                 fp1 = LoggingFile(fp, 1024, sys.stdout)
!             else:
!                 fp1 = fp
!             t0 = time.time()
!             try:
!                 f.retrbinary('RETR ' + filename,
!                              fp1.write, 8*1024)
!             except ftplib.error_perm, msg:
!                 print msg
!             t1 = time.time()
!             bytes = fp.tell()
!             fp.close()
!             if fp1 != fp:
!                 fp1.close()
!         try:
!             os.unlink(fullname)
!         except os.error:
!             pass            # Ignore the error
!         try:
!             os.rename(tempname, fullname)
!         except os.error, msg:
!             print "Can't rename %s to %s: %s" % (`tempname`,
!                                                  `fullname`,
!                                                  str(msg))
!             continue
!         info[filename] = infostuff
!         writedict(info, infofilename)
!         if verbose and mode[0] != 'l':
!             dt = t1 - t0
!             kbytes = bytes / 1024.0
!             print int(round(kbytes)),
!             print 'Kbytes in',
!             print int(round(dt)),
!             print 'seconds',
!             if t1 > t0:
!                 print '(~%d Kbytes/sec)' % \
!                           int(round(kbytes/dt),)
!             print
!     #
!     # Remove files from info that are no longer remote
!     deletions = 0
!     for filename in info.keys():
!         if filename not in filesfound:
!             if verbose:
!                 print "Removing obsolete info entry for",
!                 print `filename`, "in", `localdir or "."`
!             del info[filename]
!             deletions = deletions + 1
!     if deletions:
!         writedict(info, infofilename)
!     #
!     # Remove local files that are no longer in the remote directory
!     try:
!         if not localdir: names = os.listdir(os.curdir)
!         else: names = os.listdir(localdir)
!     except os.error:
!         names = []
!     for name in names:
!         if name[0] == '.' or info.has_key(name) or name in subdirs:
!             continue
!         skip = 0
!         for pat in skippats:
!             if fnmatch(name, pat):
!                 if verbose > 1:
!                     print 'Skip pattern', `pat`,
!                     print 'matches', `name`
!                 skip = 1
!                 break
!         if skip:
!             continue
!         fullname = os.path.join(localdir, name)
!         if not rmok:
!             if verbose:
!                 print 'Local file', `fullname`,
!                 print 'is no longer pertinent'
!             continue
!         if verbose: print 'Removing local file/dir', `fullname`
!         remove(fullname)
!     #
!     # Recursively mirror subdirectories
!     for subdir in subdirs:
!         if interactive:
!             doit = askabout('subdirectory', subdir, pwd)
!             if not doit: continue
!         if verbose: print 'Processing subdirectory', `subdir`
!         localsubdir = os.path.join(localdir, subdir)
!         pwd = f.pwd()
!         if verbose > 1:
!             print 'Remote directory now:', `pwd`
!             print 'Remote cwd', `subdir`
!         try:
!             f.cwd(subdir)
!         except ftplib.error_perm, msg:
!             print "Can't chdir to", `subdir`, ":", `msg`
!         else:
!             if verbose: print 'Mirroring as', `localsubdir`
!             mirrorsubdir(f, localsubdir)
!             if verbose > 1: print 'Remote cwd ..'
!             f.cwd('..')
!         newpwd = f.pwd()
!         if newpwd != pwd:
!             print 'Ended up in wrong directory after cd + cd ..'
!             print 'Giving up now.'
!             break
!         else:
!             if verbose > 1: print 'OK.'
  
  # Helper to remove a file or directory tree
  def remove(fullname):
!     if os.path.isdir(fullname) and not os.path.islink(fullname):
!         try:
!             names = os.listdir(fullname)
!         except os.error:
!             names = []
!         ok = 1
!         for name in names:
!             if not remove(os.path.join(fullname, name)):
!                 ok = 0
!         if not ok:
!             return 0
!         try:
!             os.rmdir(fullname)
!         except os.error, msg:
!             print "Can't remove local directory %s: %s" % \
!                   (`fullname`, str(msg))
!             return 0
!     else:
!         try:
!             os.unlink(fullname)
!         except os.error, msg:
!             print "Can't remove local file %s: %s" % \
!                   (`fullname`, str(msg))
!             return 0
!     return 1
  
  # Wrapper around a file for writing to write a hash sign every block.
  class LoggingFile:
!     def __init__(self, fp, blocksize, outfp):
!         self.fp = fp
!         self.bytes = 0
!         self.hashes = 0
!         self.blocksize = blocksize
!         self.outfp = outfp
!     def write(self, data):
!         self.bytes = self.bytes + len(data)
!         hashes = int(self.bytes) / self.blocksize
!         while hashes > self.hashes:
!             self.outfp.write('#')
!             self.outfp.flush()
!             self.hashes = self.hashes + 1
!         self.fp.write(data)
!     def close(self):
!         self.outfp.write('\n')
  
  # Ask permission to download a file.
  def askabout(filetype, filename, pwd):
!     prompt = 'Retrieve %s %s from %s ? [ny] ' % (filetype, filename, pwd)
!     while 1:
!         reply = string.lower(string.strip(raw_input(prompt)))
!         if reply in ['y', 'ye', 'yes']:
!             return 1
!         if reply in ['', 'n', 'no', 'nop', 'nope']:
!             return 0
!         print 'Please answer yes or no.'
  
  # Create a directory if it doesn't exist.  Recursively create the
  # parent directory as well if needed.
  def makedir(pathname):
!     if os.path.isdir(pathname):
!         return
!     dirname = os.path.dirname(pathname)
!     if dirname: makedir(dirname)
!     os.mkdir(pathname, 0777)
  
  # Write a dictionary to a file in a way that can be read back using
***************
*** 374,397 ****
  # Also creates a backup file.
  def writedict(dict, filename):
! 	dir, file = os.path.split(filename)
! 	tempname = os.path.join(dir, '@' + file)
! 	backup = os.path.join(dir, file + '~')
! 	try:
! 		os.unlink(backup)
! 	except os.error:
! 		pass
! 	fp = open(tempname, 'w')
! 	fp.write('{\n')
! 	for key, value in dict.items():
! 		fp.write('%s: %s,\n' % (`key`, `value`))
! 	fp.write('}\n')
! 	fp.close()
! 	try:
! 		os.rename(filename, backup)
! 	except os.error:
! 		pass
! 	os.rename(tempname, filename)
  
  
  if __name__ == '__main__':
! 	main()
--- 374,397 ----
  # Also creates a backup file.
  def writedict(dict, filename):
!     dir, file = os.path.split(filename)
!     tempname = os.path.join(dir, '@' + file)
!     backup = os.path.join(dir, file + '~')
!     try:
!         os.unlink(backup)
!     except os.error:
!         pass
!     fp = open(tempname, 'w')
!     fp.write('{\n')
!     for key, value in dict.items():
!         fp.write('%s: %s,\n' % (`key`, `value`))
!     fp.write('}\n')
!     fp.close()
!     try:
!         os.rename(filename, backup)
!     except os.error:
!         pass
!     os.rename(tempname, filename)
  
  
  if __name__ == '__main__':
!     main()

Index: gencodec.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/gencodec.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** gencodec.py	2001/01/03 21:29:14	1.4
--- gencodec.py	2001/01/17 08:48:39	1.5
***************
*** 181,185 ****
  
          return codecs.charmap_encode(input,errors,encoding_map)
!         
      def decode(self,input,errors='strict'):
  
--- 181,185 ----
  
          return codecs.charmap_encode(input,errors,encoding_map)
! 
      def decode(self,input,errors='strict'):
  
***************
*** 188,192 ****
  class StreamWriter(Codec,codecs.StreamWriter):
      pass
!         
  class StreamReader(Codec,codecs.StreamReader):
      pass
--- 188,192 ----
  class StreamWriter(Codec,codecs.StreamWriter):
      pass
! 
  class StreamReader(Codec,codecs.StreamReader):
      pass
***************
*** 211,215 ****
          l.append("decoding_map = {")
          splits = 0
!         
      mappings = map.items()
      mappings.sort()
--- 211,215 ----
          l.append("decoding_map = {")
          splits = 0
! 
      mappings = map.items()
      mappings.sort()
***************
*** 291,295 ****
  
  def rewritepythondir(dir,prefix='',comments=1):
!     
      mapnames = os.listdir(dir)
      for mapname in mapnames:
--- 291,295 ----
  
  def rewritepythondir(dir,prefix='',comments=1):
! 
      mapnames = os.listdir(dir)
      for mapname in mapnames:

Index: h2py.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/h2py.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** h2py.py	1998/12/17 18:02:15	1.11
--- h2py.py	2001/01/17 08:48:39	1.12
***************
*** 42,150 ****
  
  try:
! 	searchdirs=string.splitfields(os.environ['include'],';')
  except KeyError:
! 	try:
! 		searchdirs=string.splitfields(os.environ['INCLUDE'],';')
! 	except KeyError:
! 		try:
! 			if string.find( sys.platform, "beos" ) == 0:
! 				searchdirs=string.splitfields(os.environ['BEINCLUDES'],';')
! 			else:
! 				raise KeyError
! 		except KeyError:
! 			searchdirs=['/usr/include']
  
  def main():
! 	global filedict
! 	opts, args = getopt.getopt(sys.argv[1:], 'i:')
! 	for o, a in opts:
! 		if o == '-i':
! 			ignores.append(regex.compile(a))
! 	if not args:
! 		args = ['-']
! 	for filename in args:
! 		if filename == '-':
! 			sys.stdout.write('# Generated by h2py from stdin\n')
! 			process(sys.stdin, sys.stdout)
! 		else:
! 			fp = open(filename, 'r')
! 			outfile = os.path.basename(filename)
! 			i = string.rfind(outfile, '.')
! 			if i > 0: outfile = outfile[:i]
! 			outfile = string.upper(outfile)
! 			outfile = outfile + '.py'
! 			outfp = open(outfile, 'w')
! 			outfp.write('# Generated by h2py from %s\n' % filename)
! 			filedict = {}
! 			for dir in searchdirs:
! 				if filename[:len(dir)] == dir:
! 					filedict[filename[len(dir)+1:]] = None	# no '/' trailing
! 					break
! 			process(fp, outfp)
! 			outfp.close()
! 			fp.close()
  
  def process(fp, outfp, env = {}):
! 	lineno = 0
! 	while 1:
! 		line = fp.readline()
! 		if not line: break
! 		lineno = lineno + 1
! 		n = p_define.match(line)
! 		if n >= 0:
! 			# gobble up continuation lines
! 			while line[-2:] == '\\\n':
! 				nextline = fp.readline()
! 				if not nextline: break
! 				lineno = lineno + 1
! 				line = line + nextline
! 			name = p_define.group(1)
! 			body = line[n:]
! 			# replace ignored patterns by spaces
! 			for p in ignores:
! 				body = regsub.gsub(p, ' ', body)
! 			# replace char literals by ord(...)
! 			body = regsub.gsub(p_char, 'ord(\\0)', body)
! 			stmt = '%s = %s\n' % (name, string.strip(body))
! 			ok = 0
! 			try:
! 				exec stmt in env
! 			except:
! 				sys.stderr.write('Skipping: %s' % stmt)
! 			else:
! 				outfp.write(stmt)
! 		n =p_macro.match(line)
! 		if n >= 0:
! 			macro, arg = p_macro.group(1, 2)
! 			body = line[n:]
! 			for p in ignores:
! 				body = regsub.gsub(p, ' ', body)
! 			body = regsub.gsub(p_char, 'ord(\\0)', body)
! 			stmt = 'def %s(%s): return %s\n' % (macro, arg, body)
! 			try:
! 				exec stmt in env
! 			except:
! 				sys.stderr.write('Skipping: %s' % stmt)
! 			else:
! 				outfp.write(stmt)
! 		if p_include.match(line) >= 0:
! 			regs = p_include.regs
! 			a, b = regs[1]
! 			filename = line[a:b]
! 			if not filedict.has_key(filename):
! 				filedict[filename] = None
! 				inclfp = None
! 				for dir in searchdirs:
! 					try:
! 						inclfp = open(dir + '/' + filename, 'r')
! 						break
! 					except IOError:
! 						pass
! 				if inclfp:
! 					outfp.write(
! 						'\n# Included from %s\n' % filename)
! 					process(inclfp, outfp, env)
! 				else:
! 					sys.stderr.write('Warning - could not find file %s' % filename)
  
  main()
--- 42,150 ----
  
  try:
!     searchdirs=string.splitfields(os.environ['include'],';')
  except KeyError:
!     try:
!         searchdirs=string.splitfields(os.environ['INCLUDE'],';')
!     except KeyError:
!         try:
!             if string.find( sys.platform, "beos" ) == 0:
!                 searchdirs=string.splitfields(os.environ['BEINCLUDES'],';')
!             else:
!                 raise KeyError
!         except KeyError:
!             searchdirs=['/usr/include']
  
  def main():
!     global filedict
!     opts, args = getopt.getopt(sys.argv[1:], 'i:')
!     for o, a in opts:
!         if o == '-i':
!             ignores.append(regex.compile(a))
!     if not args:
!         args = ['-']
!     for filename in args:
!         if filename == '-':
!             sys.stdout.write('# Generated by h2py from stdin\n')
!             process(sys.stdin, sys.stdout)
!         else:
!             fp = open(filename, 'r')
!             outfile = os.path.basename(filename)
!             i = string.rfind(outfile, '.')
!             if i > 0: outfile = outfile[:i]
!             outfile = string.upper(outfile)
!             outfile = outfile + '.py'
!             outfp = open(outfile, 'w')
!             outfp.write('# Generated by h2py from %s\n' % filename)
!             filedict = {}
!             for dir in searchdirs:
!                 if filename[:len(dir)] == dir:
!                     filedict[filename[len(dir)+1:]] = None  # no '/' trailing
!                     break
!             process(fp, outfp)
!             outfp.close()
!             fp.close()
  
  def process(fp, outfp, env = {}):
!     lineno = 0
!     while 1:
!         line = fp.readline()
!         if not line: break
!         lineno = lineno + 1
!         n = p_define.match(line)
!         if n >= 0:
!             # gobble up continuation lines
!             while line[-2:] == '\\\n':
!                 nextline = fp.readline()
!                 if not nextline: break
!                 lineno = lineno + 1
!                 line = line + nextline
!             name = p_define.group(1)
!             body = line[n:]
!             # replace ignored patterns by spaces
!             for p in ignores:
!                 body = regsub.gsub(p, ' ', body)
!             # replace char literals by ord(...)
!             body = regsub.gsub(p_char, 'ord(\\0)', body)
!             stmt = '%s = %s\n' % (name, string.strip(body))
!             ok = 0
!             try:
!                 exec stmt in env
!             except:
!                 sys.stderr.write('Skipping: %s' % stmt)
!             else:
!                 outfp.write(stmt)
!         n =p_macro.match(line)
!         if n >= 0:
!             macro, arg = p_macro.group(1, 2)
!             body = line[n:]
!             for p in ignores:
!                 body = regsub.gsub(p, ' ', body)
!             body = regsub.gsub(p_char, 'ord(\\0)', body)
!             stmt = 'def %s(%s): return %s\n' % (macro, arg, body)
!             try:
!                 exec stmt in env
!             except:
!                 sys.stderr.write('Skipping: %s' % stmt)
!             else:
!                 outfp.write(stmt)
!         if p_include.match(line) >= 0:
!             regs = p_include.regs
!             a, b = regs[1]
!             filename = line[a:b]
!             if not filedict.has_key(filename):
!                 filedict[filename] = None
!                 inclfp = None
!                 for dir in searchdirs:
!                     try:
!                         inclfp = open(dir + '/' + filename, 'r')
!                         break
!                     except IOError:
!                         pass
!                 if inclfp:
!                     outfp.write(
!                             '\n# Included from %s\n' % filename)
!                     process(inclfp, outfp, env)
!                 else:
!                     sys.stderr.write('Warning - could not find file %s' % filename)
  
  main()

Index: ifdef.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/ifdef.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** ifdef.py	1998/10/08 15:24:47	1.3
--- ifdef.py	2001/01/17 08:48:39	1.4
***************
*** 4,8 ****
  # Usage:
  # ifdef [-Dname] ... [-Uname] ... [file] ...
! # 
  # This scans the file(s), looking for #ifdef and #ifndef preprocessor
  # commands that test for one of the names mentioned in the -D and -U
--- 4,8 ----
  # Usage:
  # ifdef [-Dname] ... [-Uname] ... [file] ...
! #
  # This scans the file(s), looking for #ifdef and #ifndef preprocessor
  # commands that test for one of the names mentioned in the -D and -U
***************
*** 36,113 ****
  
  def main():
! 	opts, args = getopt.getopt(sys.argv[1:], 'D:U:')
! 	for o, a in opts:
! 		if o == '-D':
! 			defs.append(a)
! 		if o == '-U':
! 			undefs.append(a)
! 	if not args:
! 		args = ['-']
! 	for file in args:
! 		if file == '-':
! 			process(sys.stdin, sys.stdout)
! 		else:
! 			f = open(file, 'r')
! 			process(f, sys.stdout)
! 			f.close()
  
  def process(fpi, fpo):
! 	keywords = ('if', 'ifdef', 'ifndef', 'else', 'endif')
! 	ok = 1
! 	stack = []
! 	while 1:
! 		line = fpi.readline()
! 		if not line: break
! 		while line[-2:] == '\\\n':
! 			nextline = fpi.readline()
! 			if not nextline: break
! 			line = line + nextline
! 		tmp = string.strip(line)
! 		if tmp[:1] != '#':
! 			if ok: fpo.write(line)
! 			continue
! 		tmp = string.strip(tmp[1:])
! 		words = string.split(tmp)
! 		keyword = words[0]
! 		if keyword not in keywords:
! 			if ok: fpo.write(line)
! 			continue
! 		if keyword in ('ifdef', 'ifndef') and len(words) == 2:
! 			if keyword == 'ifdef':
! 				ko = 1
! 			else:
! 				ko = 0
! 			word = words[1]
! 			if word in defs:
! 				stack.append((ok, ko, word))
! 				if not ko: ok = 0
! 			elif word in undefs:
! 				stack.append((ok, not ko, word))
! 				if ko: ok = 0
! 			else:
! 				stack.append((ok, -1, word))
! 				if ok: fpo.write(line)
! 		elif keyword == 'if':
! 			stack.append((ok, -1, ''))
! 			if ok: fpo.write(line)
! 		elif keyword == 'else' and stack:
! 			s_ok, s_ko, s_word = stack[-1]
! 			if s_ko < 0:
! 				if ok: fpo.write(line)
! 			else:
! 				s_ko = not s_ko
! 				ok = s_ok
! 				if not s_ko: ok = 0
! 				stack[-1] = s_ok, s_ko, s_word
! 		elif keyword == 'endif' and stack:
! 			s_ok, s_ko, s_word = stack[-1]
! 			if s_ko < 0:
! 				if ok: fpo.write(line)
! 			del stack[-1]
! 			ok = s_ok
! 		else:
! 			sys.stderr.write('Unknown keyword %s\n' % keyword)
! 	if stack:
! 		sys.stderr.write('stack: %s\n' % stack)
  
  main()
--- 36,113 ----
  
  def main():
!     opts, args = getopt.getopt(sys.argv[1:], 'D:U:')
!     for o, a in opts:
!         if o == '-D':
!             defs.append(a)
!         if o == '-U':
!             undefs.append(a)
!     if not args:
!         args = ['-']
!     for file in args:
!         if file == '-':
!             process(sys.stdin, sys.stdout)
!         else:
!             f = open(file, 'r')
!             process(f, sys.stdout)
!             f.close()
  
  def process(fpi, fpo):
!     keywords = ('if', 'ifdef', 'ifndef', 'else', 'endif')
!     ok = 1
!     stack = []
!     while 1:
!         line = fpi.readline()
!         if not line: break
!         while line[-2:] == '\\\n':
!             nextline = fpi.readline()
!             if not nextline: break
!             line = line + nextline
!         tmp = string.strip(line)
!         if tmp[:1] != '#':
!             if ok: fpo.write(line)
!             continue
!         tmp = string.strip(tmp[1:])
!         words = string.split(tmp)
!         keyword = words[0]
!         if keyword not in keywords:
!             if ok: fpo.write(line)
!             continue
!         if keyword in ('ifdef', 'ifndef') and len(words) == 2:
!             if keyword == 'ifdef':
!                 ko = 1
!             else:
!                 ko = 0
!             word = words[1]
!             if word in defs:
!                 stack.append((ok, ko, word))
!                 if not ko: ok = 0
!             elif word in undefs:
!                 stack.append((ok, not ko, word))
!                 if ko: ok = 0
!             else:
!                 stack.append((ok, -1, word))
!                 if ok: fpo.write(line)
!         elif keyword == 'if':
!             stack.append((ok, -1, ''))
!             if ok: fpo.write(line)
!         elif keyword == 'else' and stack:
!             s_ok, s_ko, s_word = stack[-1]
!             if s_ko < 0:
!                 if ok: fpo.write(line)
!             else:
!                 s_ko = not s_ko
!                 ok = s_ok
!                 if not s_ko: ok = 0
!                 stack[-1] = s_ok, s_ko, s_word
!         elif keyword == 'endif' and stack:
!             s_ok, s_ko, s_word = stack[-1]
!             if s_ko < 0:
!                 if ok: fpo.write(line)
!             del stack[-1]
!             ok = s_ok
!         else:
!             sys.stderr.write('Unknown keyword %s\n' % keyword)
!     if stack:
!         sys.stderr.write('stack: %s\n' % stack)
  
  main()

Index: linktree.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/linktree.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** linktree.py	1998/03/24 05:30:24	1.5
--- linktree.py	2001/01/17 08:48:39	1.6
***************
*** 18,79 ****
  
  def main():
! 	if not 3 <= len(sys.argv) <= 4:
! 		print 'usage:', sys.argv[0], 'oldtree newtree [linkto]'
! 		return 2
! 	oldtree, newtree = sys.argv[1], sys.argv[2]
! 	if len(sys.argv) > 3:
! 		link = sys.argv[3]
! 		link_may_fail = 1
! 	else:
! 		link = LINK
! 		link_may_fail = 0
! 	if not os.path.isdir(oldtree):
! 		print oldtree + ': not a directory'
! 		return 1
! 	try:
! 		os.mkdir(newtree, 0777)
! 	except os.error, msg:
! 		print newtree + ': cannot mkdir:', msg
! 		return 1
! 	linkname = os.path.join(newtree, link)
! 	try:
! 		os.symlink(os.path.join(os.pardir, oldtree), linkname)
! 	except os.error, msg:
! 		if not link_may_fail:
! 			print linkname + ': cannot symlink:', msg
! 			return 1
! 		else:
! 			print linkname + ': warning: cannot symlink:', msg
! 	linknames(oldtree, newtree, link)
! 	return 0
  
  def linknames(old, new, link):
! 	if debug: print 'linknames', (old, new, link)
! 	try:
! 		names = os.listdir(old)
! 	except os.error, msg:
! 		print old + ': warning: cannot listdir:', msg
! 		return
! 	for name in names:
! 		if name not in (os.curdir, os.pardir):
! 			oldname = os.path.join(old, name)
! 			linkname = os.path.join(link, name)
! 			newname = os.path.join(new, name)
! 			if debug > 1: print oldname, newname, linkname
! 			if os.path.isdir(oldname) and \
! 			   not os.path.islink(oldname):
! 				try:
! 					os.mkdir(newname, 0777)
! 					ok = 1
! 				except:
! 					print newname + \
! 					      ': warning: cannot mkdir:', msg
! 					ok = 0
! 				if ok:
! 					linkname = os.path.join(os.pardir,
! 								linkname)
! 					linknames(oldname, newname, linkname)
! 			else:
! 				os.symlink(linkname, newname)
  
  sys.exit(main())
--- 18,79 ----
  
  def main():
!     if not 3 <= len(sys.argv) <= 4:
!         print 'usage:', sys.argv[0], 'oldtree newtree [linkto]'
!         return 2
!     oldtree, newtree = sys.argv[1], sys.argv[2]
!     if len(sys.argv) > 3:
!         link = sys.argv[3]
!         link_may_fail = 1
!     else:
!         link = LINK
!         link_may_fail = 0
!     if not os.path.isdir(oldtree):
!         print oldtree + ': not a directory'
!         return 1
!     try:
!         os.mkdir(newtree, 0777)
!     except os.error, msg:
!         print newtree + ': cannot mkdir:', msg
!         return 1
!     linkname = os.path.join(newtree, link)
!     try:
!         os.symlink(os.path.join(os.pardir, oldtree), linkname)
!     except os.error, msg:
!         if not link_may_fail:
!             print linkname + ': cannot symlink:', msg
!             return 1
!         else:
!             print linkname + ': warning: cannot symlink:', msg
!     linknames(oldtree, newtree, link)
!     return 0
  
  def linknames(old, new, link):
!     if debug: print 'linknames', (old, new, link)
!     try:
!         names = os.listdir(old)
!     except os.error, msg:
!         print old + ': warning: cannot listdir:', msg
!         return
!     for name in names:
!         if name not in (os.curdir, os.pardir):
!             oldname = os.path.join(old, name)
!             linkname = os.path.join(link, name)
!             newname = os.path.join(new, name)
!             if debug > 1: print oldname, newname, linkname
!             if os.path.isdir(oldname) and \
!                not os.path.islink(oldname):
!                 try:
!                     os.mkdir(newname, 0777)
!                     ok = 1
!                 except:
!                     print newname + \
!                           ': warning: cannot mkdir:', msg
!                     ok = 0
!                 if ok:
!                     linkname = os.path.join(os.pardir,
!                                             linkname)
!                     linknames(oldname, newname, linkname)
!             else:
!                 os.symlink(linkname, newname)
  
  sys.exit(main())

Index: lll.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/lll.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** lll.py	1996/11/27 19:44:25	1.4
--- lll.py	2001/01/17 08:48:39	1.5
***************
*** 9,17 ****
  
  def lll(dirname):
! 	for name in os.listdir(dirname):
! 		if name not in (os.curdir, os.pardir):
! 			full = os.path.join(dirname, name)
! 			if os.path.islink(full):
! 				print name, '->', os.readlink(full)
  
  args = sys.argv[1:]
--- 9,17 ----
  
  def lll(dirname):
!     for name in os.listdir(dirname):
!         if name not in (os.curdir, os.pardir):
!             full = os.path.join(dirname, name)
!             if os.path.islink(full):
!                 print name, '->', os.readlink(full)
  
  args = sys.argv[1:]
***************
*** 19,25 ****
  first = 1
  for arg in args:
! 	if len(args) > 1:
! 		if not first: print
! 		first = 0
! 		print arg + ':'
! 	lll(arg)
--- 19,25 ----
  first = 1
  for arg in args:
!     if len(args) > 1:
!         if not first: print
!         first = 0
!         print arg + ':'
!     lll(arg)

Index: logmerge.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/logmerge.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** logmerge.py	2000/02/14 21:41:50	1.5
--- logmerge.py	2001/01/17 08:48:39	1.6
***************
*** 117,121 ****
          records.append((date, working_file, rev, author, text))
      return records
!         
  def format_output(database):
      prevtext = None
--- 117,121 ----
          records.append((date, working_file, rev, author, text))
      return records
! 
  def format_output(database):
      prevtext = None

Index: mailerdaemon.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/mailerdaemon.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** mailerdaemon.py	2000/02/29 13:00:16	1.8
--- mailerdaemon.py	2001/01/17 08:48:39	1.9
***************
*** 167,171 ****
      files = filter(lambda fn, pat=pat: pat.match(fn) is not None, os.listdir('.'))
      files.sort(sort_numeric)
!     
      for fn in files:
          # Lets try to parse the file.
--- 167,171 ----
      files = filter(lambda fn, pat=pat: pat.match(fn) is not None, os.listdir('.'))
      files.sort(sort_numeric)
! 
      for fn in files:
          # Lets try to parse the file.

Index: methfix.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/methfix.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** methfix.py	1996/11/27 19:44:26	1.4
--- methfix.py	2001/01/17 08:48:39	1.5
***************
*** 1,8 ****
  #! /usr/bin/env python
  
! # Fix Python source files to avoid using 
! #	def method(self, (arg1, ..., argn)):
  # instead of the more rational
! #	def method(self, arg1, ..., argn):
  #
  # Command line arguments are files or directories to be processed.
--- 1,8 ----
  #! /usr/bin/env python
  
! # Fix Python source files to avoid using
! #       def method(self, (arg1, ..., argn)):
  # instead of the more rational
! #       def method(self, arg1, ..., argn):
  #
  # Command line arguments are files or directories to be processed.
***************
*** 38,162 ****
  
  def main():
! 	bad = 0
! 	if not sys.argv[1:]: # No arguments
! 		err('usage: ' + sys.argv[0] + ' file-or-directory ...\n')
! 		sys.exit(2)
! 	for arg in sys.argv[1:]:
! 		if os.path.isdir(arg):
! 			if recursedown(arg): bad = 1
! 		elif os.path.islink(arg):
! 			err(arg + ': will not process symbolic links\n')
! 			bad = 1
! 		else:
! 			if fix(arg): bad = 1
! 	sys.exit(bad)
  
  ispythonprog = regex.compile('^[a-zA-Z0-9_]+\.py$')
  def ispython(name):
! 	return ispythonprog.match(name) >= 0
  
  def recursedown(dirname):
! 	dbg('recursedown(' + `dirname` + ')\n')
! 	bad = 0
! 	try:
! 		names = os.listdir(dirname)
! 	except os.error, msg:
! 		err(dirname + ': cannot list directory: ' + `msg` + '\n')
! 		return 1
! 	names.sort()
! 	subdirs = []
! 	for name in names:
! 		if name in (os.curdir, os.pardir): continue
! 		fullname = os.path.join(dirname, name)
! 		if os.path.islink(fullname): pass
! 		elif os.path.isdir(fullname):
! 			subdirs.append(fullname)
! 		elif ispython(name):
! 			if fix(fullname): bad = 1
! 	for fullname in subdirs:
! 		if recursedown(fullname): bad = 1
! 	return bad
  
  def fix(filename):
! ##	dbg('fix(' + `filename` + ')\n')
! 	try:
! 		f = open(filename, 'r')
! 	except IOError, msg:
! 		err(filename + ': cannot open: ' + `msg` + '\n')
! 		return 1
! 	head, tail = os.path.split(filename)
! 	tempname = os.path.join(head, '@' + tail)
! 	g = None
! 	# If we find a match, we rewind the file and start over but
! 	# now copy everything to a temp file.
! 	lineno = 0
! 	while 1:
! 		line = f.readline()
! 		if not line: break
! 		lineno = lineno + 1
! 		if g is None and '\0' in line:
! 			# Check for binary files
! 			err(filename + ': contains null bytes; not fixed\n')
! 			f.close()
! 			return 1
! 		if lineno == 1 and g is None and line[:2] == '#!':
! 			# Check for non-Python scripts
! 			words = string.split(line[2:])
! 			if words and regex.search('[pP]ython', words[0]) < 0:
! 				msg = filename + ': ' + words[0]
! 				msg = msg + ' script; not fixed\n'
! 				err(msg)
! 				f.close()
! 				return 1
! 		while line[-2:] == '\\\n':
! 			nextline = f.readline()
! 			if not nextline: break
! 			line = line + nextline
! 			lineno = lineno + 1
! 		newline = fixline(line)
! 		if newline != line:
! 			if g is None:
! 				try:
! 					g = open(tempname, 'w')
! 				except IOError, msg:
! 					f.close()
! 					err(tempname+': cannot create: '+\
! 					    `msg`+'\n')
! 					return 1
! 				f.seek(0)
! 				lineno = 0
! 				rep(filename + ':\n')
! 				continue # restart from the beginning
! 			rep(`lineno` + '\n')
! 			rep('< ' + line)
! 			rep('> ' + newline)
! 		if g is not None:
! 			g.write(newline)
! 
! 	# End of file
! 	f.close()
! 	if not g: return 0 # No changes
! 	
! 	# Finishing touch -- move files
! 
! 	# First copy the file's mode to the temp file
! 	try:
! 		statbuf = os.stat(filename)
! 		os.chmod(tempname, statbuf[ST_MODE] & 07777)
! 	except os.error, msg:
! 		err(tempname + ': warning: chmod failed (' + `msg` + ')\n')
! 	# Then make a backup of the original file as filename~
! 	try:
! 		os.rename(filename, filename + '~')
! 	except os.error, msg:
! 		err(filename + ': warning: backup failed (' + `msg` + ')\n')
! 	# Now move the temp file to the original file
! 	try:
! 		os.rename(tempname, filename)
! 	except os.error, msg:
! 		err(filename + ': rename failed (' + `msg` + ')\n')
! 		return 1
! 	# Return succes
! 	return 0
  
  
--- 38,162 ----
  
  def main():
!     bad = 0
!     if not sys.argv[1:]: # No arguments
!         err('usage: ' + sys.argv[0] + ' file-or-directory ...\n')
!         sys.exit(2)
!     for arg in sys.argv[1:]:
!         if os.path.isdir(arg):
!             if recursedown(arg): bad = 1
!         elif os.path.islink(arg):
!             err(arg + ': will not process symbolic links\n')
!             bad = 1
!         else:
!             if fix(arg): bad = 1
!     sys.exit(bad)
  
  ispythonprog = regex.compile('^[a-zA-Z0-9_]+\.py$')
  def ispython(name):
!     return ispythonprog.match(name) >= 0
  
  def recursedown(dirname):
!     dbg('recursedown(' + `dirname` + ')\n')
!     bad = 0
!     try:
!         names = os.listdir(dirname)
!     except os.error, msg:
!         err(dirname + ': cannot list directory: ' + `msg` + '\n')
!         return 1
!     names.sort()
!     subdirs = []
!     for name in names:
!         if name in (os.curdir, os.pardir): continue
!         fullname = os.path.join(dirname, name)
!         if os.path.islink(fullname): pass
!         elif os.path.isdir(fullname):
!             subdirs.append(fullname)
!         elif ispython(name):
!             if fix(fullname): bad = 1
!     for fullname in subdirs:
!         if recursedown(fullname): bad = 1
!     return bad
  
  def fix(filename):
! ##      dbg('fix(' + `filename` + ')\n')
!     try:
!         f = open(filename, 'r')
!     except IOError, msg:
!         err(filename + ': cannot open: ' + `msg` + '\n')
!         return 1
!     head, tail = os.path.split(filename)
!     tempname = os.path.join(head, '@' + tail)
!     g = None
!     # If we find a match, we rewind the file and start over but
!     # now copy everything to a temp file.
!     lineno = 0
!     while 1:
!         line = f.readline()
!         if not line: break
!         lineno = lineno + 1
!         if g is None and '\0' in line:
!             # Check for binary files
!             err(filename + ': contains null bytes; not fixed\n')
!             f.close()
!             return 1
!         if lineno == 1 and g is None and line[:2] == '#!':
!             # Check for non-Python scripts
!             words = string.split(line[2:])
!             if words and regex.search('[pP]ython', words[0]) < 0:
!                 msg = filename + ': ' + words[0]
!                 msg = msg + ' script; not fixed\n'
!                 err(msg)
!                 f.close()
!                 return 1
!         while line[-2:] == '\\\n':
!             nextline = f.readline()
!             if not nextline: break
!             line = line + nextline
!             lineno = lineno + 1
!         newline = fixline(line)
!         if newline != line:
!             if g is None:
!                 try:
!                     g = open(tempname, 'w')
!                 except IOError, msg:
!                     f.close()
!                     err(tempname+': cannot create: '+\
!                         `msg`+'\n')
!                     return 1
!                 f.seek(0)
!                 lineno = 0
!                 rep(filename + ':\n')
!                 continue # restart from the beginning
!             rep(`lineno` + '\n')
!             rep('< ' + line)
!             rep('> ' + newline)
!         if g is not None:
!             g.write(newline)
! 
!     # End of file
!     f.close()
!     if not g: return 0 # No changes
! 
!     # Finishing touch -- move files
! 
!     # First copy the file's mode to the temp file
!     try:
!         statbuf = os.stat(filename)
!         os.chmod(tempname, statbuf[ST_MODE] & 07777)
!     except os.error, msg:
!         err(tempname + ': warning: chmod failed (' + `msg` + ')\n')
!     # Then make a backup of the original file as filename~
!     try:
!         os.rename(filename, filename + '~')
!     except os.error, msg:
!         err(filename + ': warning: backup failed (' + `msg` + ')\n')
!     # Now move the temp file to the original file
!     try:
!         os.rename(tempname, filename)
!     except os.error, msg:
!         err(filename + ': rename failed (' + `msg` + ')\n')
!         return 1
!     # Return succes
!     return 0
  
  
***************
*** 165,172 ****
  
  def fixline(line):
! 	if fixprog.match(line) >= 0:
! 		(a, b), (c, d) = fixprog.regs[1:3]
! 		line = line[:a] + line[c:d] + line[b:]
! 	return line
  
  
--- 165,172 ----
  
  def fixline(line):
!     if fixprog.match(line) >= 0:
!         (a, b), (c, d) = fixprog.regs[1:3]
!         line = line[:a] + line[c:d] + line[b:]
!     return line
  
  

Index: mkreal.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/mkreal.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** mkreal.py	1996/11/27 19:44:28	1.5
--- mkreal.py	2001/01/17 08:48:39	1.6
***************
*** 16,65 ****
  
  def mkrealfile(name):
! 	st = os.stat(name) # Get the mode
! 	mode = S_IMODE(st[ST_MODE])
! 	linkto = os.readlink(name) # Make sure again it's a symlink
! 	f_in = open(name, 'r') # This ensures it's a file
! 	os.unlink(name)
! 	f_out = open(name, 'w')
! 	while 1:
! 		buf = f_in.read(BUFSIZE)
! 		if not buf: break
! 		f_out.write(buf)
! 	del f_out # Flush data to disk before changing mode
! 	os.chmod(name, mode)
  
  def mkrealdir(name):
! 	st = os.stat(name) # Get the mode
! 	mode = S_IMODE(st[ST_MODE])
! 	linkto = os.readlink(name)
! 	files = os.listdir(name)
! 	os.unlink(name)
! 	os.mkdir(name, mode)
! 	os.chmod(name, mode)
! 	linkto = join(os.pardir, linkto)
! 	#
! 	for file in files:
! 		if file not in (os.curdir, os.pardir):
! 			os.symlink(join(linkto, file), join(name, file))
  
  def main():
! 	sys.stdout = sys.stderr
! 	progname = os.path.basename(sys.argv[0])
! 	if progname == '-c': progname = 'mkreal'
! 	args = sys.argv[1:]
! 	if not args:
! 		print 'usage:', progname, 'path ...'
! 		sys.exit(2)
! 	status = 0
! 	for name in args:
! 		if not os.path.islink(name):
! 			print progname+':', name+':', 'not a symlink'
! 			status = 1
! 		else:
! 			if os.path.isdir(name):
! 				mkrealdir(name)
! 			else:
! 				mkrealfile(name)
! 	sys.exit(status)
  
  main()
--- 16,65 ----
  
  def mkrealfile(name):
!     st = os.stat(name) # Get the mode
!     mode = S_IMODE(st[ST_MODE])
!     linkto = os.readlink(name) # Make sure again it's a symlink
!     f_in = open(name, 'r') # This ensures it's a file
!     os.unlink(name)
!     f_out = open(name, 'w')
!     while 1:
!         buf = f_in.read(BUFSIZE)
!         if not buf: break
!         f_out.write(buf)
!     del f_out # Flush data to disk before changing mode
!     os.chmod(name, mode)
  
  def mkrealdir(name):
!     st = os.stat(name) # Get the mode
!     mode = S_IMODE(st[ST_MODE])
!     linkto = os.readlink(name)
!     files = os.listdir(name)
!     os.unlink(name)
!     os.mkdir(name, mode)
!     os.chmod(name, mode)
!     linkto = join(os.pardir, linkto)
!     #
!     for file in files:
!         if file not in (os.curdir, os.pardir):
!             os.symlink(join(linkto, file), join(name, file))
  
  def main():
!     sys.stdout = sys.stderr
!     progname = os.path.basename(sys.argv[0])
!     if progname == '-c': progname = 'mkreal'
!     args = sys.argv[1:]
!     if not args:
!         print 'usage:', progname, 'path ...'
!         sys.exit(2)
!     status = 0
!     for name in args:
!         if not os.path.islink(name):
!             print progname+':', name+':', 'not a symlink'
!             status = 1
!         else:
!             if os.path.isdir(name):
!                 mkrealdir(name)
!             else:
!                 mkrealfile(name)
!     sys.exit(status)
  
  main()

Index: ndiff.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/ndiff.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** ndiff.py	2000/12/09 05:03:22	1.6
--- ndiff.py	2001/01/17 08:48:39	1.7
***************
*** 15,19 ****
  (-r1) or file2 (-r2) on stdout, from an ndiff report on stdin.
  
! In the first form, if -q ("quiet") is not specified, the first two lines
  of output are
  
--- 15,19 ----
  (-r1) or file2 (-r2) on stdout, from an ndiff report on stdin.
  
! In the first form, if -q ("quiet") is not specified, the first two lines
  of output are
  

Index: nm2def.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/nm2def.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** nm2def.py	1998/10/07 14:46:09	1.3
--- nm2def.py	2001/01/17 08:48:39	1.4
***************
*** 99,103 ****
      f.write(DEF_TEMPLATE % (exports))
      f.close()
!     
  if __name__ == '__main__':
      main()
--- 99,103 ----
      f.write(DEF_TEMPLATE % (exports))
      f.close()
! 
  if __name__ == '__main__':
      main()

Index: objgraph.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/objgraph.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** objgraph.py	1996/11/27 19:44:29	1.4
--- objgraph.py	2001/01/17 08:48:39	1.5
***************
*** 41,48 ****
  #
  def store(dict, key, item):
! 	if dict.has_key(key):
! 		dict[key].append(item)
! 	else:
! 		dict[key] = [item]
  
  # Return a flattened version of a list of strings: the concatenation
--- 41,48 ----
  #
  def store(dict, key, item):
!     if dict.has_key(key):
!         dict[key].append(item)
!     else:
!         dict[key] = [item]
  
  # Return a flattened version of a list of strings: the concatenation
***************
*** 50,57 ****
  #
  def flat(list):
! 	s = ''
! 	for item in list:
! 		s = s + ' ' + item
! 	return s[1:]
  
  # Global variables mapping defined/undefined names to files and back.
--- 50,57 ----
  #
  def flat(list):
!     s = ''
!     for item in list:
!         s = s + ' ' + item
!     return s[1:]
  
  # Global variables mapping defined/undefined names to files and back.
***************
*** 66,86 ****
  #
  def readinput(file):
! 	while 1:
! 		s = file.readline()
! 		if not s:
! 			break
! 		# If you get any output from this line,
! 		# it is probably caused by an unexpected input line:
! 		if matcher.search(s) < 0: s; continue # Shouldn't happen
! 		(ra, rb), (r1a, r1b), (r2a, r2b), (r3a, r3b) = matcher.regs[:4]
! 		fn, name, type = s[r1a:r1b], s[r3a:r3b], s[r2a:r2b]
! 		if type in definitions:
! 			store(def2file, name, fn)
! 			store(file2def, fn, name)
! 		elif type in externals:
! 			store(file2undef, fn, name)
! 			store(undef2file, name, fn)
! 		elif not type in ignore:
! 			print fn + ':' + name + ': unknown type ' + type
  
  # Print all names that were undefined in some module and where they are
--- 66,86 ----
  #
  def readinput(file):
!     while 1:
!         s = file.readline()
!         if not s:
!             break
!         # If you get any output from this line,
!         # it is probably caused by an unexpected input line:
!         if matcher.search(s) < 0: s; continue # Shouldn't happen
!         (ra, rb), (r1a, r1b), (r2a, r2b), (r3a, r3b) = matcher.regs[:4]
!         fn, name, type = s[r1a:r1b], s[r3a:r3b], s[r2a:r2b]
!         if type in definitions:
!             store(def2file, name, fn)
!             store(file2def, fn, name)
!         elif type in externals:
!             store(file2undef, fn, name)
!             store(undef2file, name, fn)
!         elif not type in ignore:
!             print fn + ':' + name + ': unknown type ' + type
  
  # Print all names that were undefined in some module and where they are
***************
*** 88,208 ****
  #
  def printcallee():
! 	flist = file2undef.keys()
! 	flist.sort()
! 	for file in flist:
! 		print file + ':'
! 		elist = file2undef[file]
! 		elist.sort()
! 		for ext in elist:
! 			if len(ext) >= 8:
! 				tabs = '\t'
! 			else:
! 				tabs = '\t\t'
! 			if not def2file.has_key(ext):
! 				print '\t' + ext + tabs + ' *undefined'
! 			else:
! 				print '\t' + ext + tabs + flat(def2file[ext])
  
  # Print for each module the names of the other modules that use it.
  #
  def printcaller():
! 	files = file2def.keys()
! 	files.sort()
! 	for file in files:
! 		callers = []
! 		for label in file2def[file]:
! 			if undef2file.has_key(label):
! 				callers = callers + undef2file[label]
! 		if callers:
! 			callers.sort()
! 			print file + ':'
! 			lastfn = ''
! 			for fn in callers:
! 				if fn <> lastfn:
! 					print '\t' + fn
! 				lastfn = fn
! 		else:
! 			print file + ': unused'
  
  # Print undefine names and where they are used.
  #
  def printundef():
! 	undefs = {}
! 	for file in file2undef.keys():
! 		for ext in file2undef[file]:
! 			if not def2file.has_key(ext):
! 				store(undefs, ext, file)
! 	elist = undefs.keys()
! 	elist.sort()
! 	for ext in elist:
! 		print ext + ':'
! 		flist = undefs[ext]
! 		flist.sort()
! 		for file in flist:
! 			print '\t' + file
  
  # Print warning messages about names defined in more than one file.
  #
  def warndups():
! 	savestdout = sys.stdout
! 	sys.stdout = sys.stderr
! 	names = def2file.keys()
! 	names.sort()
! 	for name in names:
! 		if len(def2file[name]) > 1:
! 			print 'warning:', name, 'multiply defined:',
! 			print flat(def2file[name])
! 	sys.stdout = savestdout
  
  # Main program
  #
  def main():
! 	try:
! 		optlist, args = getopt.getopt(sys.argv[1:], 'cdu')
! 	except getopt.error:
! 		sys.stdout = sys.stderr
! 		print 'Usage:', os.path.basename(sys.argv[0]),
! 		print           '[-cdu] [file] ...'
! 		print '-c: print callers per objectfile'
! 		print '-d: print callees per objectfile'
! 		print '-u: print usage of undefined symbols'
! 		print 'If none of -cdu is specified, all are assumed.'
! 		print 'Use "nm -o" to generate the input (on IRIX: "nm -Bo"),'
! 		print 'e.g.: nm -o /lib/libc.a | objgraph'
! 		return 1
! 	optu = optc = optd = 0
! 	for opt, void in optlist:
! 		if opt == '-u':
! 			optu = 1
! 		elif opt == '-c':
! 			optc = 1
! 		elif opt == '-d':
! 			optd = 1
! 	if optu == optc == optd == 0:
! 		optu = optc = optd = 1
! 	if not args:
! 		args = ['-']
! 	for file in args:
! 		if file == '-':
! 			readinput(sys.stdin)
! 		else:
! 			readinput(open(file, 'r'))
! 	#
! 	warndups()
! 	#
! 	more = (optu + optc + optd > 1)
! 	if optd:
! 		if more:
! 			print '---------------All callees------------------'
! 		printcallee()
! 	if optu:
! 		if more:
! 			print '---------------Undefined callees------------'
! 		printundef()
! 	if optc:
! 		if more:
! 			print '---------------All Callers------------------'
! 		printcaller()
! 	return 0
  
  # Call the main program.
--- 88,208 ----
  #
  def printcallee():
!     flist = file2undef.keys()
!     flist.sort()
!     for file in flist:
!         print file + ':'
!         elist = file2undef[file]
!         elist.sort()
!         for ext in elist:
!             if len(ext) >= 8:
!                 tabs = '\t'
!             else:
!                 tabs = '\t\t'
!             if not def2file.has_key(ext):
!                 print '\t' + ext + tabs + ' *undefined'
!             else:
!                 print '\t' + ext + tabs + flat(def2file[ext])
  
  # Print for each module the names of the other modules that use it.
  #
  def printcaller():
!     files = file2def.keys()
!     files.sort()
!     for file in files:
!         callers = []
!         for label in file2def[file]:
!             if undef2file.has_key(label):
!                 callers = callers + undef2file[label]
!         if callers:
!             callers.sort()
!             print file + ':'
!             lastfn = ''
!             for fn in callers:
!                 if fn <> lastfn:
!                     print '\t' + fn
!                 lastfn = fn
!         else:
!             print file + ': unused'
  
  # Print undefine names and where they are used.
  #
  def printundef():
!     undefs = {}
!     for file in file2undef.keys():
!         for ext in file2undef[file]:
!             if not def2file.has_key(ext):
!                 store(undefs, ext, file)
!     elist = undefs.keys()
!     elist.sort()
!     for ext in elist:
!         print ext + ':'
!         flist = undefs[ext]
!         flist.sort()
!         for file in flist:
!             print '\t' + file
  
  # Print warning messages about names defined in more than one file.
  #
  def warndups():
!     savestdout = sys.stdout
!     sys.stdout = sys.stderr
!     names = def2file.keys()
!     names.sort()
!     for name in names:
!         if len(def2file[name]) > 1:
!             print 'warning:', name, 'multiply defined:',
!             print flat(def2file[name])
!     sys.stdout = savestdout
  
  # Main program
  #
  def main():
!     try:
!         optlist, args = getopt.getopt(sys.argv[1:], 'cdu')
!     except getopt.error:
!         sys.stdout = sys.stderr
!         print 'Usage:', os.path.basename(sys.argv[0]),
!         print           '[-cdu] [file] ...'
!         print '-c: print callers per objectfile'
!         print '-d: print callees per objectfile'
!         print '-u: print usage of undefined symbols'
!         print 'If none of -cdu is specified, all are assumed.'
!         print 'Use "nm -o" to generate the input (on IRIX: "nm -Bo"),'
!         print 'e.g.: nm -o /lib/libc.a | objgraph'
!         return 1
!     optu = optc = optd = 0
!     for opt, void in optlist:
!         if opt == '-u':
!             optu = 1
!         elif opt == '-c':
!             optc = 1
!         elif opt == '-d':
!             optd = 1
!     if optu == optc == optd == 0:
!         optu = optc = optd = 1
!     if not args:
!         args = ['-']
!     for file in args:
!         if file == '-':
!             readinput(sys.stdin)
!         else:
!             readinput(open(file, 'r'))
!     #
!     warndups()
!     #
!     more = (optu + optc + optd > 1)
!     if optd:
!         if more:
!             print '---------------All callees------------------'
!         printcallee()
!     if optu:
!         if more:
!             print '---------------Undefined callees------------'
!         printundef()
!     if optc:
!         if more:
!             print '---------------All Callers------------------'
!         printcaller()
!     return 0
  
  # Call the main program.
***************
*** 211,215 ****
  #
  try:
! 	sys.exit(main())
  except KeyboardInterrupt:
! 	sys.exit(1)
--- 211,215 ----
  #
  try:
!     sys.exit(main())
  except KeyboardInterrupt:
!     sys.exit(1)

Index: parseentities.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/parseentities.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** parseentities.py	2000/09/18 01:46:01	1.2
--- parseentities.py	2001/01/17 08:48:39	1.3
***************
*** 9,13 ****
      entity name to character or numeric entity.
  
!     Marc-Andre Lemburg, mal@lemburg.com, 1999. 
      Use as you like. NO WARRANTIES.
  
--- 9,13 ----
      entity name to character or numeric entity.
  
!     Marc-Andre Lemburg, mal@lemburg.com, 1999.
      Use as you like. NO WARRANTIES.
  
***************
*** 63,65 ****
      defs = parse(text)
      writefile(outfile,defs)
- 
--- 63,64 ----

Index: pathfix.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/pathfix.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** pathfix.py	1996/11/27 19:43:01	1.2
--- pathfix.py	2001/01/17 08:48:39	1.3
***************
*** 34,149 ****
  
  def main():
! 	global new_interpreter
! 	usage = ('usage: %s -i /interpreter file-or-directory ...\n' %
! 		 sys.argv[0])
! 	try:
! 		opts, args = getopt.getopt(sys.argv[1:], 'i:')
! 	except getopt.error, msg:
! 		err(msg + '\n')
! 		err(usage)
! 		sys.exit(2)
! 	for o, a in opts:
! 		if o == '-i':
! 			new_interpreter = a
! 	if not new_interpreter or new_interpreter[0] != '/' or not args:
! 		err('-i option or file-or-directory missing\n')
! 		err(usage)
! 		sys.exit(2)
! 	bad = 0
! 	for arg in args:
! 		if os.path.isdir(arg):
! 			if recursedown(arg): bad = 1
! 		elif os.path.islink(arg):
! 			err(arg + ': will not process symbolic links\n')
! 			bad = 1
! 		else:
! 			if fix(arg): bad = 1
! 	sys.exit(bad)
  
  ispythonprog = regex.compile('^[a-zA-Z0-9_]+\.py$')
  def ispython(name):
! 	return ispythonprog.match(name) >= 0
  
  def recursedown(dirname):
! 	dbg('recursedown(' + `dirname` + ')\n')
! 	bad = 0
! 	try:
! 		names = os.listdir(dirname)
! 	except os.error, msg:
! 		err(dirname + ': cannot list directory: ' + `msg` + '\n')
! 		return 1
! 	names.sort()
! 	subdirs = []
! 	for name in names:
! 		if name in (os.curdir, os.pardir): continue
! 		fullname = os.path.join(dirname, name)
! 		if os.path.islink(fullname): pass
! 		elif os.path.isdir(fullname):
! 			subdirs.append(fullname)
! 		elif ispython(name):
! 			if fix(fullname): bad = 1
! 	for fullname in subdirs:
! 		if recursedown(fullname): bad = 1
! 	return bad
  
  def fix(filename):
! ##	dbg('fix(' + `filename` + ')\n')
! 	try:
! 		f = open(filename, 'r')
! 	except IOError, msg:
! 		err(filename + ': cannot open: ' + `msg` + '\n')
! 		return 1
! 	line = f.readline()
! 	fixed = fixline(line)
! 	if line == fixed:
! 		rep(filename+': no change\n')
! 		f.close()
! 		return
! 	head, tail = os.path.split(filename)
! 	tempname = os.path.join(head, '@' + tail)
! 	try:
! 		g = open(tempname, 'w')
! 	except IOError, msg:
! 		f.close()
! 		err(tempname+': cannot create: '+`msg`+'\n')
! 		return 1
! 	rep(filename + ': updating\n')
! 	g.write(fixed)
! 	BUFSIZE = 8*1024
! 	while 1:
! 		buf = f.read(BUFSIZE)
! 		if not buf: break
! 		g.write(buf)
! 	g.close()
! 	f.close()
! 
! 	# Finishing touch -- move files
! 
! 	# First copy the file's mode to the temp file
! 	try:
! 		statbuf = os.stat(filename)
! 		os.chmod(tempname, statbuf[ST_MODE] & 07777)
! 	except os.error, msg:
! 		err(tempname + ': warning: chmod failed (' + `msg` + ')\n')
! 	# Then make a backup of the original file as filename~
! 	try:
! 		os.rename(filename, filename + '~')
! 	except os.error, msg:
! 		err(filename + ': warning: backup failed (' + `msg` + ')\n')
! 	# Now move the temp file to the original file
! 	try:
! 		os.rename(tempname, filename)
! 	except os.error, msg:
! 		err(filename + ': rename failed (' + `msg` + ')\n')
! 		return 1
! 	# Return succes
! 	return 0
  
  def fixline(line):
! 	if line[:2] != '#!':
! 		return line
! 	if string.find(line, "python") < 0:
! 		return line
! 	return '#! %s\n' % new_interpreter
  
  main()
--- 34,149 ----
  
  def main():
!     global new_interpreter
!     usage = ('usage: %s -i /interpreter file-or-directory ...\n' %
!              sys.argv[0])
!     try:
!         opts, args = getopt.getopt(sys.argv[1:], 'i:')
!     except getopt.error, msg:
!         err(msg + '\n')
!         err(usage)
!         sys.exit(2)
!     for o, a in opts:
!         if o == '-i':
!             new_interpreter = a
!     if not new_interpreter or new_interpreter[0] != '/' or not args:
!         err('-i option or file-or-directory missing\n')
!         err(usage)
!         sys.exit(2)
!     bad = 0
!     for arg in args:
!         if os.path.isdir(arg):
!             if recursedown(arg): bad = 1
!         elif os.path.islink(arg):
!             err(arg + ': will not process symbolic links\n')
!             bad = 1
!         else:
!             if fix(arg): bad = 1
!     sys.exit(bad)
  
  ispythonprog = regex.compile('^[a-zA-Z0-9_]+\.py$')
  def ispython(name):
!     return ispythonprog.match(name) >= 0
  
  def recursedown(dirname):
!     dbg('recursedown(' + `dirname` + ')\n')
!     bad = 0
!     try:
!         names = os.listdir(dirname)
!     except os.error, msg:
!         err(dirname + ': cannot list directory: ' + `msg` + '\n')
!         return 1
!     names.sort()
!     subdirs = []
!     for name in names:
!         if name in (os.curdir, os.pardir): continue
!         fullname = os.path.join(dirname, name)
!         if os.path.islink(fullname): pass
!         elif os.path.isdir(fullname):
!             subdirs.append(fullname)
!         elif ispython(name):
!             if fix(fullname): bad = 1
!     for fullname in subdirs:
!         if recursedown(fullname): bad = 1
!     return bad
  
  def fix(filename):
! ##      dbg('fix(' + `filename` + ')\n')
!     try:
!         f = open(filename, 'r')
!     except IOError, msg:
!         err(filename + ': cannot open: ' + `msg` + '\n')
!         return 1
!     line = f.readline()
!     fixed = fixline(line)
!     if line == fixed:
!         rep(filename+': no change\n')
!         f.close()
!         return
!     head, tail = os.path.split(filename)
!     tempname = os.path.join(head, '@' + tail)
!     try:
!         g = open(tempname, 'w')
!     except IOError, msg:
!         f.close()
!         err(tempname+': cannot create: '+`msg`+'\n')
!         return 1
!     rep(filename + ': updating\n')
!     g.write(fixed)
!     BUFSIZE = 8*1024
!     while 1:
!         buf = f.read(BUFSIZE)
!         if not buf: break
!         g.write(buf)
!     g.close()
!     f.close()
! 
!     # Finishing touch -- move files
! 
!     # First copy the file's mode to the temp file
!     try:
!         statbuf = os.stat(filename)
!         os.chmod(tempname, statbuf[ST_MODE] & 07777)
!     except os.error, msg:
!         err(tempname + ': warning: chmod failed (' + `msg` + ')\n')
!     # Then make a backup of the original file as filename~
!     try:
!         os.rename(filename, filename + '~')
!     except os.error, msg:
!         err(filename + ': warning: backup failed (' + `msg` + ')\n')
!     # Now move the temp file to the original file
!     try:
!         os.rename(tempname, filename)
!     except os.error, msg:
!         err(filename + ': rename failed (' + `msg` + ')\n')
!         return 1
!     # Return succes
!     return 0
  
  def fixline(line):
!     if line[:2] != '#!':
!         return line
!     if string.find(line, "python") < 0:
!         return line
!     return '#! %s\n' % new_interpreter
  
  main()

Index: pdeps.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/pdeps.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** pdeps.py	1996/11/27 19:44:30	1.4
--- pdeps.py	2001/01/17 08:48:39	1.5
***************
*** 6,10 ****
  #
  # Usage:
! #	pdeps file1.py file2.py ...
  #
  # Output:
--- 6,10 ----
  #
  # Usage:
! #       pdeps file1.py file2.py ...
  #
  # Output:
***************
*** 30,58 ****
  #
  def main():
! 	args = sys.argv[1:]
! 	if not args:
! 		print 'usage: pdeps file.py file.py ...'
! 		return 2
! 	#
! 	table = {}
! 	for arg in args:
! 		process(arg, table)
! 	#
! 	print '--- Uses ---'
! 	printresults(table)
! 	#
! 	print '--- Used By ---'
! 	inv = inverse(table)
! 	printresults(inv)
! 	#
! 	print '--- Closure of Uses ---'
! 	reach = closure(table)
! 	printresults(reach)
! 	#
! 	print '--- Closure of Used By ---'
! 	invreach = inverse(reach)
! 	printresults(invreach)
! 	#
! 	return 0
  
  
--- 30,58 ----
  #
  def main():
!     args = sys.argv[1:]
!     if not args:
!         print 'usage: pdeps file.py file.py ...'
!         return 2
!     #
!     table = {}
!     for arg in args:
!         process(arg, table)
!     #
!     print '--- Uses ---'
!     printresults(table)
!     #
!     print '--- Used By ---'
!     inv = inverse(table)
!     printresults(inv)
!     #
!     print '--- Closure of Uses ---'
!     reach = closure(table)
!     printresults(reach)
!     #
!     print '--- Closure of Used By ---'
!     invreach = inverse(reach)
!     printresults(invreach)
!     #
!     return 0
  
  
***************
*** 66,92 ****
  #
  def process(filename, table):
! 	fp = open(filename, 'r')
! 	mod = os.path.basename(filename)
! 	if mod[-3:] == '.py':
! 		mod = mod[:-3]
! 	table[mod] = list = []
! 	while 1:
! 		line = fp.readline()
! 		if not line: break
! 		while line[-1:] == '\\':
! 			nextline = fp.readline()
! 			if not nextline: break
! 			line = line[:-1] + nextline
! 		if m_import.match(line) >= 0:
! 			(a, b), (a1, b1) = m_import.regs[:2]
! 		elif m_from.match(line) >= 0:
! 			(a, b), (a1, b1) = m_from.regs[:2]
! 		else: continue
! 		words = string.splitfields(line[a1:b1], ',')
! 		# print '#', line, words
! 		for word in words:
! 			word = string.strip(word)
! 			if word not in list:
! 				list.append(word)
  
  
--- 66,92 ----
  #
  def process(filename, table):
!     fp = open(filename, 'r')
!     mod = os.path.basename(filename)
!     if mod[-3:] == '.py':
!         mod = mod[:-3]
!     table[mod] = list = []
!     while 1:
!         line = fp.readline()
!         if not line: break
!         while line[-1:] == '\\':
!             nextline = fp.readline()
!             if not nextline: break
!             line = line[:-1] + nextline
!         if m_import.match(line) >= 0:
!             (a, b), (a1, b1) = m_import.regs[:2]
!         elif m_from.match(line) >= 0:
!             (a, b), (a1, b1) = m_from.regs[:2]
!         else: continue
!         words = string.splitfields(line[a1:b1], ',')
!         # print '#', line, words
!         for word in words:
!             word = string.strip(word)
!             if word not in list:
!                 list.append(word)
  
  
***************
*** 94,119 ****
  #
  def closure(table):
! 	modules = table.keys()
! 	#
! 	# Initialize reach with a copy of table
! 	#
! 	reach = {}
! 	for mod in modules:
! 		reach[mod] = table[mod][:]
! 	#
! 	# Iterate until no more change
! 	#
! 	change = 1
! 	while change:
! 		change = 0
! 		for mod in modules:
! 			for mo in reach[mod]:
! 				if mo in modules:
! 					for m in reach[mo]:
! 						if m not in reach[mod]:
! 							reach[mod].append(m)
! 							change = 1
! 	#
! 	return reach
  
  
--- 94,119 ----
  #
  def closure(table):
!     modules = table.keys()
!     #
!     # Initialize reach with a copy of table
!     #
!     reach = {}
!     for mod in modules:
!         reach[mod] = table[mod][:]
!     #
!     # Iterate until no more change
!     #
!     change = 1
!     while change:
!         change = 0
!         for mod in modules:
!             for mo in reach[mod]:
!                 if mo in modules:
!                     for m in reach[mo]:
!                         if m not in reach[mod]:
!                             reach[mod].append(m)
!                             change = 1
!     #
!     return reach
  
  
***************
*** 123,133 ****
  #
  def inverse(table):
! 	inv = {}
! 	for key in table.keys():
! 		if not inv.has_key(key):
! 			inv[key] = []
! 		for item in table[key]:
! 			store(inv, item, key)
! 	return inv
  
  
--- 123,133 ----
  #
  def inverse(table):
!     inv = {}
!     for key in table.keys():
!         if not inv.has_key(key):
!             inv[key] = []
!         for item in table[key]:
!             store(inv, item, key)
!     return inv
  
  
***************
*** 137,144 ****
  #
  def store(dict, key, item):
! 	if dict.has_key(key):
! 		dict[key].append(item)
! 	else:
! 		dict[key] = [item]
  
  
--- 137,144 ----
  #
  def store(dict, key, item):
!     if dict.has_key(key):
!         dict[key].append(item)
!     else:
!         dict[key] = [item]
  
  
***************
*** 146,167 ****
  #
  def printresults(table):
! 	modules = table.keys()
! 	maxlen = 0
! 	for mod in modules: maxlen = max(maxlen, len(mod))
! 	modules.sort()
! 	for mod in modules:
! 		list = table[mod]
! 		list.sort()
! 		print string.ljust(mod, maxlen), ':',
! 		if mod in list:
! 			print '(*)',
! 		for ref in list:
! 			print ref,
! 		print
  
  
  # Call main and honor exit status
  try:
! 	sys.exit(main())
  except KeyboardInterrupt:
! 	sys.exit(1)
--- 146,167 ----
  #
  def printresults(table):
!     modules = table.keys()
!     maxlen = 0
!     for mod in modules: maxlen = max(maxlen, len(mod))
!     modules.sort()
!     for mod in modules:
!         list = table[mod]
!         list.sort()
!         print string.ljust(mod, maxlen), ':',
!         if mod in list:
!             print '(*)',
!         for ref in list:
!             print ref,
!         print
  
  
  # Call main and honor exit status
  try:
!     sys.exit(main())
  except KeyboardInterrupt:
!     sys.exit(1)

Index: pindent.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/pindent.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** pindent.py	2000/07/11 16:43:16	1.9
--- pindent.py	2001/01/17 08:48:39	1.10
***************
*** 98,331 ****
  class PythonIndenter:
  
! 	def __init__(self, fpi = sys.stdin, fpo = sys.stdout,
! 		     indentsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
! 		self.fpi = fpi
! 		self.fpo = fpo
! 		self.indentsize = indentsize
! 		self.tabsize = tabsize
! 		self.lineno = 0
! 		self.expandtabs = expandtabs
! 		self._write = fpo.write
! 		self.kwprog = re.compile(
! 			r'^\s*(?P<kw>[a-z]+)'
! 			r'(\s+(?P<id>[a-zA-Z_]\w*))?'
! 			r'[^\w]')
! 		self.endprog = re.compile(
! 			r'^\s*#?\s*end\s+(?P<kw>[a-z]+)'
! 			r'(\s+(?P<id>[a-zA-Z_]\w*))?'
! 			r'[^\w]')
! 		self.wsprog = re.compile(r'^[ \t]*')
! 	# end def __init__
! 
! 	def write(self, line):
! 		if self.expandtabs:
! 			self._write(string.expandtabs(line, self.tabsize))
! 		else:
! 			self._write(line)
! 		# end if
! 	# end def write
! 
! 	def readline(self):
! 		line = self.fpi.readline()
! 		if line: self.lineno = self.lineno + 1
! 		# end if
! 		return line
! 	# end def readline
! 
! 	def error(self, fmt, *args):
! 		if args: fmt = fmt % args
! 		# end if
! 		sys.stderr.write('Error at line %d: %s\n' % (self.lineno, fmt))
! 		self.write('### %s ###\n' % fmt)
! 	# end def error
! 
! 	def getline(self):
! 		line = self.readline()
! 		while line[-2:] == '\\\n':
! 			line2 = self.readline()
! 			if not line2: break
! 			# end if
! 			line = line + line2
! 		# end while
! 		return line
! 	# end def getline
! 
! 	def putline(self, line, indent = None):
! 		if indent is None:
! 			self.write(line)
! 			return
! 		# end if
! 		tabs, spaces = divmod(indent*self.indentsize, self.tabsize)
! 		i = 0
! 		m = self.wsprog.match(line)
! 		if m: i = m.end()
! 		# end if
! 		self.write('\t'*tabs + ' '*spaces + line[i:])
! 	# end def putline
! 
! 	def reformat(self):
! 		stack = []
! 		while 1:
! 			line = self.getline()
! 			if not line: break	# EOF
! 			# end if
! 			m = self.endprog.match(line)
! 			if m:
! 				kw = 'end'
! 				kw2 = m.group('kw')
! 				if not stack:
! 					self.error('unexpected end')
! 				elif stack[-1][0] != kw2:
! 					self.error('unmatched end')
! 				# end if
! 				del stack[-1:]
! 				self.putline(line, len(stack))
! 				continue
! 			# end if
! 			m = self.kwprog.match(line)
! 			if m:
! 				kw = m.group('kw')
! 				if kw in start:
! 					self.putline(line, len(stack))
! 					stack.append((kw, kw))
! 					continue
! 				# end if
! 				if next.has_key(kw) and stack:
! 					self.putline(line, len(stack)-1)
! 					kwa, kwb = stack[-1]
! 					stack[-1] = kwa, kw
! 					continue
! 				# end if
! 			# end if
! 			self.putline(line, len(stack))
! 		# end while
! 		if stack:
! 			self.error('unterminated keywords')
! 			for kwa, kwb in stack:
! 				self.write('\t%s\n' % kwa)
! 			# end for
! 		# end if
! 	# end def reformat
! 
! 	def delete(self):
! 		begin_counter = 0
! 		end_counter = 0
! 		while 1:
! 			line = self.getline()
! 			if not line: break	# EOF
! 			# end if
! 			m = self.endprog.match(line)
! 			if m:
! 				end_counter = end_counter + 1
! 				continue
! 			# end if
! 			m = self.kwprog.match(line)
! 			if m:
! 				kw = m.group('kw')
! 				if kw in start:
! 					begin_counter = begin_counter + 1
! 				# end if
! 			# end if
! 			self.putline(line)
! 		# end while
! 		if begin_counter - end_counter < 0:
! 			sys.stderr.write('Warning: input contained more end tags than expected\n')
! 		elif begin_counter - end_counter > 0:
! 			sys.stderr.write('Warning: input contained less end tags than expected\n')
! 		# end if
! 	# end def delete
! 	
! 	def complete(self):
! 		self.indentsize = 1
! 		stack = []
! 		todo = []
! 		current, firstkw, lastkw, topid = 0, '', '', ''
! 		while 1:
! 			line = self.getline()
! 			i = 0
! 			m = self.wsprog.match(line)
! 			if m: i = m.end()
! 			# end if
! 			m = self.endprog.match(line)
! 			if m:
! 				thiskw = 'end'
! 				endkw = m.group('kw')
! 				thisid = m.group('id')
! 			else:
! 				m = self.kwprog.match(line)
! 				if m:
! 					thiskw = m.group('kw')
! 					if not next.has_key(thiskw):
! 						thiskw = ''
! 					# end if
! 					if thiskw in ('def', 'class'):
! 						thisid = m.group('id')
! 					else:
! 						thisid = ''
! 					# end if
! 				elif line[i:i+1] in ('\n', '#'):
! 					todo.append(line)
! 					continue
! 				else:
! 					thiskw = ''
! 				# end if
! 			# end if
! 			indent = len(string.expandtabs(line[:i], self.tabsize))
! 			while indent < current:
! 				if firstkw:
! 					if topid:
! 						s = '# end %s %s\n' % (
! 							firstkw, topid)
! 					else:
! 						s = '# end %s\n' % firstkw
! 					# end if
! 					self.putline(s, current)
! 					firstkw = lastkw = ''
! 				# end if
! 				current, firstkw, lastkw, topid = stack[-1]
! 				del stack[-1]
! 			# end while
! 			if indent == current and firstkw:
! 				if thiskw == 'end':
! 					if endkw != firstkw:
! 						self.error('mismatched end')
! 					# end if
! 					firstkw = lastkw = ''
! 				elif not thiskw or thiskw in start:
! 					if topid:
! 						s = '# end %s %s\n' % (
! 							firstkw, topid)
! 					else:
! 						s = '# end %s\n' % firstkw
! 					# end if
! 					self.putline(s, current)
! 					firstkw = lastkw = topid = ''
! 				# end if
! 			# end if
! 			if indent > current:
! 				stack.append((current, firstkw, lastkw, topid))
! 				if thiskw and thiskw not in start:
! 					# error
! 					thiskw = ''
! 				# end if
! 				current, firstkw, lastkw, topid = \
! 					 indent, thiskw, thiskw, thisid
! 			# end if
! 			if thiskw:
! 				if thiskw in start:
! 					firstkw = lastkw = thiskw
! 					topid = thisid
! 				else:
! 					lastkw = thiskw
! 				# end if
! 			# end if
! 			for l in todo: self.write(l)
! 			# end for
! 			todo = []
! 			if not line: break
! 			# end if
! 			self.write(line)
! 		# end while
! 	# end def complete
  
  # end class PythonIndenter
--- 98,331 ----
  class PythonIndenter:
  
!     def __init__(self, fpi = sys.stdin, fpo = sys.stdout,
!                  indentsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
!         self.fpi = fpi
!         self.fpo = fpo
!         self.indentsize = indentsize
!         self.tabsize = tabsize
!         self.lineno = 0
!         self.expandtabs = expandtabs
!         self._write = fpo.write
!         self.kwprog = re.compile(
!                 r'^\s*(?P<kw>[a-z]+)'
!                 r'(\s+(?P<id>[a-zA-Z_]\w*))?'
!                 r'[^\w]')
!         self.endprog = re.compile(
!                 r'^\s*#?\s*end\s+(?P<kw>[a-z]+)'
!                 r'(\s+(?P<id>[a-zA-Z_]\w*))?'
!                 r'[^\w]')
!         self.wsprog = re.compile(r'^[ \t]*')
!     # end def __init__
! 
!     def write(self, line):
!         if self.expandtabs:
!             self._write(string.expandtabs(line, self.tabsize))
!         else:
!             self._write(line)
!         # end if
!     # end def write
! 
!     def readline(self):
!         line = self.fpi.readline()
!         if line: self.lineno = self.lineno + 1
!         # end if
!         return line
!     # end def readline
! 
!     def error(self, fmt, *args):
!         if args: fmt = fmt % args
!         # end if
!         sys.stderr.write('Error at line %d: %s\n' % (self.lineno, fmt))
!         self.write('### %s ###\n' % fmt)
!     # end def error
! 
!     def getline(self):
!         line = self.readline()
!         while line[-2:] == '\\\n':
!             line2 = self.readline()
!             if not line2: break
!             # end if
!             line = line + line2
!         # end while
!         return line
!     # end def getline
! 
!     def putline(self, line, indent = None):
!         if indent is None:
!             self.write(line)
!             return
!         # end if
!         tabs, spaces = divmod(indent*self.indentsize, self.tabsize)
!         i = 0
!         m = self.wsprog.match(line)
!         if m: i = m.end()
!         # end if
!         self.write('\t'*tabs + ' '*spaces + line[i:])
!     # end def putline
! 
!     def reformat(self):
!         stack = []
!         while 1:
!             line = self.getline()
!             if not line: break      # EOF
!             # end if
!             m = self.endprog.match(line)
!             if m:
!                 kw = 'end'
!                 kw2 = m.group('kw')
!                 if not stack:
!                     self.error('unexpected end')
!                 elif stack[-1][0] != kw2:
!                     self.error('unmatched end')
!                 # end if
!                 del stack[-1:]
!                 self.putline(line, len(stack))
!                 continue
!             # end if
!             m = self.kwprog.match(line)
!             if m:
!                 kw = m.group('kw')
!                 if kw in start:
!                     self.putline(line, len(stack))
!                     stack.append((kw, kw))
!                     continue
!                 # end if
!                 if next.has_key(kw) and stack:
!                     self.putline(line, len(stack)-1)
!                     kwa, kwb = stack[-1]
!                     stack[-1] = kwa, kw
!                     continue
!                 # end if
!             # end if
!             self.putline(line, len(stack))
!         # end while
!         if stack:
!             self.error('unterminated keywords')
!             for kwa, kwb in stack:
!                 self.write('\t%s\n' % kwa)
!             # end for
!         # end if
!     # end def reformat
! 
!     def delete(self):
!         begin_counter = 0
!         end_counter = 0
!         while 1:
!             line = self.getline()
!             if not line: break      # EOF
!             # end if
!             m = self.endprog.match(line)
!             if m:
!                 end_counter = end_counter + 1
!                 continue
!             # end if
!             m = self.kwprog.match(line)
!             if m:
!                 kw = m.group('kw')
!                 if kw in start:
!                     begin_counter = begin_counter + 1
!                 # end if
!             # end if
!             self.putline(line)
!         # end while
!         if begin_counter - end_counter < 0:
!             sys.stderr.write('Warning: input contained more end tags than expected\n')
!         elif begin_counter - end_counter > 0:
!             sys.stderr.write('Warning: input contained less end tags than expected\n')
!         # end if
!     # end def delete
! 
!     def complete(self):
!         self.indentsize = 1
!         stack = []
!         todo = []
!         current, firstkw, lastkw, topid = 0, '', '', ''
!         while 1:
!             line = self.getline()
!             i = 0
!             m = self.wsprog.match(line)
!             if m: i = m.end()
!             # end if
!             m = self.endprog.match(line)
!             if m:
!                 thiskw = 'end'
!                 endkw = m.group('kw')
!                 thisid = m.group('id')
!             else:
!                 m = self.kwprog.match(line)
!                 if m:
!                     thiskw = m.group('kw')
!                     if not next.has_key(thiskw):
!                         thiskw = ''
!                     # end if
!                     if thiskw in ('def', 'class'):
!                         thisid = m.group('id')
!                     else:
!                         thisid = ''
!                     # end if
!                 elif line[i:i+1] in ('\n', '#'):
!                     todo.append(line)
!                     continue
!                 else:
!                     thiskw = ''
!                 # end if
!             # end if
!             indent = len(string.expandtabs(line[:i], self.tabsize))
!             while indent < current:
!                 if firstkw:
!                     if topid:
!                         s = '# end %s %s\n' % (
!                                 firstkw, topid)
!                     else:
!                         s = '# end %s\n' % firstkw
!                     # end if
!                     self.putline(s, current)
!                     firstkw = lastkw = ''
!                 # end if
!                 current, firstkw, lastkw, topid = stack[-1]
!                 del stack[-1]
!             # end while
!             if indent == current and firstkw:
!                 if thiskw == 'end':
!                     if endkw != firstkw:
!                         self.error('mismatched end')
!                     # end if
!                     firstkw = lastkw = ''
!                 elif not thiskw or thiskw in start:
!                     if topid:
!                         s = '# end %s %s\n' % (
!                                 firstkw, topid)
!                     else:
!                         s = '# end %s\n' % firstkw
!                     # end if
!                     self.putline(s, current)
!                     firstkw = lastkw = topid = ''
!                 # end if
!             # end if
!             if indent > current:
!                 stack.append((current, firstkw, lastkw, topid))
!                 if thiskw and thiskw not in start:
!                     # error
!                     thiskw = ''
!                 # end if
!                 current, firstkw, lastkw, topid = \
!                          indent, thiskw, thiskw, thisid
!             # end if
!             if thiskw:
!                 if thiskw in start:
!                     firstkw = lastkw = thiskw
!                     topid = thisid
!                 else:
!                     lastkw = thiskw
!                 # end if
!             # end if
!             for l in todo: self.write(l)
!             # end for
!             todo = []
!             if not line: break
!             # end if
!             self.write(line)
!         # end while
!     # end def complete
  
  # end class PythonIndenter
***************
*** 337,468 ****
  
  def complete_filter(input = sys.stdin, output = sys.stdout,
! 		    stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
! 	pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
! 	pi.complete()
  # end def complete_filter
  
  def delete_filter(input= sys.stdin, output = sys.stdout,
! 		    	stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
! 	pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
! 	pi.delete()
  # end def delete_filter
  
  def reformat_filter(input = sys.stdin, output = sys.stdout,
! 		    stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
! 	pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
! 	pi.reformat()
  # end def reformat_filter
  
  class StringReader:
! 	def __init__(self, buf):
! 		self.buf = buf
! 		self.pos = 0
! 		self.len = len(self.buf)
! 	# end def __init__
! 	def read(self, n = 0):
! 		if n <= 0:
! 			n = self.len - self.pos
! 		else:
! 			n = min(n, self.len - self.pos)
! 		# end if
! 		r = self.buf[self.pos : self.pos + n]
! 		self.pos = self.pos + n
! 		return r
! 	# end def read
! 	def readline(self):
! 		i = string.find(self.buf, '\n', self.pos)
! 		return self.read(i + 1 - self.pos)
! 	# end def readline
! 	def readlines(self):
! 		lines = []
! 		line = self.readline()
! 		while line:
! 			lines.append(line)
! 			line = self.readline()
! 		# end while
! 		return lines
! 	# end def readlines
! 	# seek/tell etc. are left as an exercise for the reader
  # end class StringReader
  
  class StringWriter:
! 	def __init__(self):
! 		self.buf = ''
! 	# end def __init__
! 	def write(self, s):
! 		self.buf = self.buf + s
! 	# end def write
! 	def getvalue(self):
! 		return self.buf
! 	# end def getvalue
  # end class StringWriter
  
  def complete_string(source, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
! 	input = StringReader(source)
! 	output = StringWriter()
! 	pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
! 	pi.complete()
! 	return output.getvalue()
  # end def complete_string
  
  def delete_string(source, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
! 	input = StringReader(source)
! 	output = StringWriter()
! 	pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
! 	pi.delete()
! 	return output.getvalue()
  # end def delete_string
  
  def reformat_string(source, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
! 	input = StringReader(source)
! 	output = StringWriter()
! 	pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
! 	pi.reformat()
! 	return output.getvalue()
  # end def reformat_string
  
  def complete_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
! 	source = open(filename, 'r').read()
! 	result = complete_string(source, stepsize, tabsize, expandtabs)
! 	if source == result: return 0
! 	# end if
! 	import os
! 	try: os.rename(filename, filename + '~')
! 	except os.error: pass
! 	# end try
! 	f = open(filename, 'w')
! 	f.write(result)
! 	f.close()
! 	return 1
  # end def complete_file
  
  def delete_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
! 	source = open(filename, 'r').read()
! 	result = delete_string(source, stepsize, tabsize, expandtabs)
! 	if source == result: return 0
! 	# end if
! 	import os
! 	try: os.rename(filename, filename + '~')
! 	except os.error: pass
! 	# end try
! 	f = open(filename, 'w')
! 	f.write(result)
! 	f.close()
! 	return 1
  # end def delete_file
  
  def reformat_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
! 	source = open(filename, 'r').read()
! 	result = reformat_string(source, stepsize, tabsize, expandtabs)
! 	if source == result: return 0
! 	# end if
! 	import os
! 	try: os.rename(filename, filename + '~')
! 	except os.error: pass
! 	# end try
! 	f = open(filename, 'w')
! 	f.write(result)
! 	f.close()
! 	return 1
  # end def reformat_file
  
--- 337,468 ----
  
  def complete_filter(input = sys.stdin, output = sys.stdout,
!                     stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
!     pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
!     pi.complete()
  # end def complete_filter
  
  def delete_filter(input= sys.stdin, output = sys.stdout,
!                         stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
!     pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
!     pi.delete()
  # end def delete_filter
  
  def reformat_filter(input = sys.stdin, output = sys.stdout,
!                     stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
!     pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
!     pi.reformat()
  # end def reformat_filter
  
  class StringReader:
!     def __init__(self, buf):
!         self.buf = buf
!         self.pos = 0
!         self.len = len(self.buf)
!     # end def __init__
!     def read(self, n = 0):
!         if n <= 0:
!             n = self.len - self.pos
!         else:
!             n = min(n, self.len - self.pos)
!         # end if
!         r = self.buf[self.pos : self.pos + n]
!         self.pos = self.pos + n
!         return r
!     # end def read
!     def readline(self):
!         i = string.find(self.buf, '\n', self.pos)
!         return self.read(i + 1 - self.pos)
!     # end def readline
!     def readlines(self):
!         lines = []
!         line = self.readline()
!         while line:
!             lines.append(line)
!             line = self.readline()
!         # end while
!         return lines
!     # end def readlines
!     # seek/tell etc. are left as an exercise for the reader
  # end class StringReader
  
  class StringWriter:
!     def __init__(self):
!         self.buf = ''
!     # end def __init__
!     def write(self, s):
!         self.buf = self.buf + s
!     # end def write
!     def getvalue(self):
!         return self.buf
!     # end def getvalue
  # end class StringWriter
  
  def complete_string(source, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
!     input = StringReader(source)
!     output = StringWriter()
!     pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
!     pi.complete()
!     return output.getvalue()
  # end def complete_string
  
  def delete_string(source, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
!     input = StringReader(source)
!     output = StringWriter()
!     pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
!     pi.delete()
!     return output.getvalue()
  # end def delete_string
  
  def reformat_string(source, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
!     input = StringReader(source)
!     output = StringWriter()
!     pi = PythonIndenter(input, output, stepsize, tabsize, expandtabs)
!     pi.reformat()
!     return output.getvalue()
  # end def reformat_string
  
  def complete_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
!     source = open(filename, 'r').read()
!     result = complete_string(source, stepsize, tabsize, expandtabs)
!     if source == result: return 0
!     # end if
!     import os
!     try: os.rename(filename, filename + '~')
!     except os.error: pass
!     # end try
!     f = open(filename, 'w')
!     f.write(result)
!     f.close()
!     return 1
  # end def complete_file
  
  def delete_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
!     source = open(filename, 'r').read()
!     result = delete_string(source, stepsize, tabsize, expandtabs)
!     if source == result: return 0
!     # end if
!     import os
!     try: os.rename(filename, filename + '~')
!     except os.error: pass
!     # end try
!     f = open(filename, 'w')
!     f.write(result)
!     f.close()
!     return 1
  # end def delete_file
  
  def reformat_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = EXPANDTABS):
!     source = open(filename, 'r').read()
!     result = reformat_string(source, stepsize, tabsize, expandtabs)
!     if source == result: return 0
!     # end if
!     import os
!     try: os.rename(filename, filename + '~')
!     except os.error: pass
!     # end try
!     f = open(filename, 'w')
!     f.write(result)
!     f.close()
!     return 1
  # end def reformat_file
  
***************
*** 483,543 ****
  
  def error_both(op1, op2):
! 	sys.stderr.write('Error: You can not specify both '+op1+' and -'+op2[0]+' at the same time\n')
! 	sys.stderr.write(usage)
! 	sys.exit(2)
  # end def error_both
  
  def test():
! 	import getopt
! 	try:
! 		opts, args = getopt.getopt(sys.argv[1:], 'cdrs:t:e')
! 	except getopt.error, msg:
! 		sys.stderr.write('Error: %s\n' % msg)
! 		sys.stderr.write(usage)
! 		sys.exit(2)
! 	# end try
! 	action = None
! 	stepsize = STEPSIZE
! 	tabsize = TABSIZE
! 	expandtabs = EXPANDTABS
! 	for o, a in opts:
! 		if o == '-c':
! 			if action: error_both(o, action)
! 			# end if
! 			action = 'complete'
! 		elif o == '-d':
! 			if action: error_both(o, action)
! 			# end if
! 			action = 'delete'
! 		elif o == '-r':
! 			if action: error_both(o, action)
! 			# end if
! 			action = 'reformat'
! 		elif o == '-s':
! 			stepsize = string.atoi(a)
! 		elif o == '-t':
! 			tabsize = string.atoi(a)
! 		elif o == '-e':
! 			expandtabs = 1
! 		# end if
! 	# end for
! 	if not action:
! 		sys.stderr.write(
! 			'You must specify -c(omplete), -d(elete) or -r(eformat)\n')
! 		sys.stderr.write(usage)
! 		sys.exit(2)
! 	# end if
! 	if not args or args == ['-']:
! 		action = eval(action + '_filter')
! 		action(sys.stdin, sys.stdout, stepsize, tabsize, expandtabs)
! 	else:
! 		action = eval(action + '_file')
! 		for file in args:
! 			action(file, stepsize, tabsize, expandtabs)
! 		# end for
! 	# end if
  # end def test
  
  if __name__ == '__main__':
! 	test()
  # end if
--- 483,543 ----
  
  def error_both(op1, op2):
!     sys.stderr.write('Error: You can not specify both '+op1+' and -'+op2[0]+' at the same time\n')
!     sys.stderr.write(usage)
!     sys.exit(2)
  # end def error_both
  
  def test():
!     import getopt
!     try:
!         opts, args = getopt.getopt(sys.argv[1:], 'cdrs:t:e')
!     except getopt.error, msg:
!         sys.stderr.write('Error: %s\n' % msg)
!         sys.stderr.write(usage)
!         sys.exit(2)
!     # end try
!     action = None
!     stepsize = STEPSIZE
!     tabsize = TABSIZE
!     expandtabs = EXPANDTABS
!     for o, a in opts:
!         if o == '-c':
!             if action: error_both(o, action)
!             # end if
!             action = 'complete'
!         elif o == '-d':
!             if action: error_both(o, action)
!             # end if
!             action = 'delete'
!         elif o == '-r':
!             if action: error_both(o, action)
!             # end if
!             action = 'reformat'
!         elif o == '-s':
!             stepsize = string.atoi(a)
!         elif o == '-t':
!             tabsize = string.atoi(a)
!         elif o == '-e':
!             expandtabs = 1
!         # end if
!     # end for
!     if not action:
!         sys.stderr.write(
!                 'You must specify -c(omplete), -d(elete) or -r(eformat)\n')
!         sys.stderr.write(usage)
!         sys.exit(2)
!     # end if
!     if not args or args == ['-']:
!         action = eval(action + '_filter')
!         action(sys.stdin, sys.stdout, stepsize, tabsize, expandtabs)
!     else:
!         action = eval(action + '_file')
!         for file in args:
!             action(file, stepsize, tabsize, expandtabs)
!         # end for
!     # end if
  # end def test
  
  if __name__ == '__main__':
!     test()
  # end if

Index: ptags.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/ptags.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** ptags.py	2000/09/01 13:41:37	1.6
--- ptags.py	2001/01/17 08:48:39	1.7
***************
*** 40,44 ****
      while 1:
          line = fp.readline()
!         if not line: 
              break
          m = matcher.match(line)
--- 40,44 ----
      while 1:
          line = fp.readline()
!         if not line:
              break
          m = matcher.match(line)

Index: redemo.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/redemo.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** redemo.py	2000/10/06 17:37:12	1.1
--- redemo.py	2001/01/17 08:48:39	1.2
***************
*** 5,161 ****
  
  class ReDemo:
! 	
! 	def __init__(self, master):
! 		self.master = master
! 
! 		self.promptdisplay = Label(self.master, anchor=W,
! 			text="Enter a Perl-style regular expression:")
! 		self.promptdisplay.pack(side=TOP, fill=X)
! 
! 		self.regexdisplay = Entry(self.master)
! 		self.regexdisplay.pack(fill=X)
! 		self.regexdisplay.focus_set()
! 
! 		self.addoptions()
! 
! 		self.statusdisplay = Label(self.master, text="", anchor=W)
! 		self.statusdisplay.pack(side=TOP, fill=X)
! 
! 		self.labeldisplay = Label(self.master, anchor=W,
! 			text="Enter a string to search:")
! 		self.labeldisplay.pack(fill=X)
! 		self.labeldisplay.pack(fill=X)
! 
! 		self.showframe = Frame(master)
! 		self.showframe.pack(fill=X, anchor=W)
! 
! 		self.showvar = StringVar(master)
! 		self.showvar.set("first")
! 
! 		self.showfirstradio = Radiobutton(self.showframe,
! 						 text="Highlight first match",
! 						  variable=self.showvar,
! 						  value="first",
! 						  command=self.recompile)
! 		self.showfirstradio.pack(side=LEFT)
! 
! 		self.showallradio = Radiobutton(self.showframe,
! 						text="Highlight all matches",
! 						variable=self.showvar,
! 						value="all",
! 						command=self.recompile)
! 		self.showallradio.pack(side=LEFT)
! 
! 		self.stringdisplay = Text(self.master, width=60, height=4)
! 		self.stringdisplay.pack(fill=BOTH, expand=1)
! 		self.stringdisplay.tag_configure("hit", background="yellow")
! 
! 		self.grouplabel = Label(self.master, text="Groups:", anchor=W)
! 		self.grouplabel.pack(fill=X)
! 
! 		self.grouplist = Listbox(self.master)
! 		self.grouplist.pack(expand=1, fill=BOTH)
! 
! 		self.regexdisplay.bind('<Key>', self.recompile)
! 		self.stringdisplay.bind('<Key>', self.reevaluate)
! 
! 		self.compiled = None
! 		self.recompile()
! 
! 		btags = self.regexdisplay.bindtags()
! 		self.regexdisplay.bindtags(btags[1:] + btags[:1])
! 
! 		btags = self.stringdisplay.bindtags()
! 		self.stringdisplay.bindtags(btags[1:] + btags[:1])
! 	
! 	def addoptions(self):
! 		self.frames = []
! 		self.boxes = []
! 		self.vars = []
! 		for name in ('IGNORECASE',
! 			     'LOCALE',
! 			     'MULTILINE',
! 			     'DOTALL',
! 			     'VERBOSE'):
! 			if len(self.boxes) % 3 == 0:
! 				frame = Frame(self.master)
! 				frame.pack(fill=X)
! 				self.frames.append(frame)
! 			val = getattr(re, name)
! 			var = IntVar()
! 			box = Checkbutton(frame,
! 				variable=var, text=name,
! 				offvalue=0, onvalue=val,
! 				command=self.recompile)
! 			box.pack(side=LEFT)
! 			self.boxes.append(box)
! 			self.vars.append(var)
! 	
! 	def getflags(self):
! 		flags = 0
! 		for var in self.vars:
! 			flags = flags | var.get()
! 		flags = flags
! 		return flags
! 	
! 	def recompile(self, event=None):
! 		try:
! 			self.compiled = re.compile(self.regexdisplay.get(),
! 						   self.getflags())
! 			bg = self.promptdisplay['background']
! 			self.statusdisplay.config(text="", background=bg)
! 		except re.error, msg:
! 			self.compiled = None
! 			self.statusdisplay.config(
! 				text="re.error: %s" % str(msg),
! 				background="red")
! 		self.reevaluate()
! 	
! 	def reevaluate(self, event=None):
! 		try:
! 			self.stringdisplay.tag_remove("hit", "1.0", END)
! 		except TclError:
! 			pass
! 		try:
! 			self.stringdisplay.tag_remove("hit0", "1.0", END)
! 		except TclError:
! 			pass
! 		self.grouplist.delete(0, END)
! 		if not self.compiled:
! 			return
! 		self.stringdisplay.tag_configure("hit", background="yellow")
! 		self.stringdisplay.tag_configure("hit0", background="orange")
! 		text = self.stringdisplay.get("1.0", END)
! 		last = 0
! 		nmatches = 0
! 		while last <= len(text):
! 			m = self.compiled.search(text, last)
! 			if m is None:
! 				break
! 			first, last = m.span()
! 			if last == first:
! 				last = first+1
! 				tag = "hit0"
! 			else:
! 				tag = "hit"
! 			pfirst = "1.0 + %d chars" % first
! 			plast = "1.0 + %d chars" % last
! 			self.stringdisplay.tag_add(tag, pfirst, plast)
! 			if nmatches == 0:
! 				self.stringdisplay.yview_pickplace(pfirst)
! 				groups = list(m.groups())
! 				groups.insert(0, m.group())
! 				for i in range(len(groups)):
! 					g = "%2d: %s" % (i, `groups[i]`)
! 					self.grouplist.insert(END, g)
! 			nmatches = nmatches + 1
! 			if self.showvar.get() == "first":
! 				break
! 
! 		if nmatches == 0:
! 			self.statusdisplay.config(text="(no match)",
! 						  background="yellow")
! 		else:
! 			self.statusdisplay.config(text="")
  
  
--- 5,161 ----
  
  class ReDemo:
! 
!     def __init__(self, master):
!         self.master = master
! 
!         self.promptdisplay = Label(self.master, anchor=W,
!                 text="Enter a Perl-style regular expression:")
!         self.promptdisplay.pack(side=TOP, fill=X)
! 
!         self.regexdisplay = Entry(self.master)
!         self.regexdisplay.pack(fill=X)
!         self.regexdisplay.focus_set()
! 
!         self.addoptions()
! 
!         self.statusdisplay = Label(self.master, text="", anchor=W)
!         self.statusdisplay.pack(side=TOP, fill=X)
! 
!         self.labeldisplay = Label(self.master, anchor=W,
!                 text="Enter a string to search:")
!         self.labeldisplay.pack(fill=X)
!         self.labeldisplay.pack(fill=X)
! 
!         self.showframe = Frame(master)
!         self.showframe.pack(fill=X, anchor=W)
! 
!         self.showvar = StringVar(master)
!         self.showvar.set("first")
! 
!         self.showfirstradio = Radiobutton(self.showframe,
!                                          text="Highlight first match",
!                                           variable=self.showvar,
!                                           value="first",
!                                           command=self.recompile)
!         self.showfirstradio.pack(side=LEFT)
! 
!         self.showallradio = Radiobutton(self.showframe,
!                                         text="Highlight all matches",
!                                         variable=self.showvar,
!                                         value="all",
!                                         command=self.recompile)
!         self.showallradio.pack(side=LEFT)
! 
!         self.stringdisplay = Text(self.master, width=60, height=4)
!         self.stringdisplay.pack(fill=BOTH, expand=1)
!         self.stringdisplay.tag_configure("hit", background="yellow")
! 
!         self.grouplabel = Label(self.master, text="Groups:", anchor=W)
!         self.grouplabel.pack(fill=X)
! 
!         self.grouplist = Listbox(self.master)
!         self.grouplist.pack(expand=1, fill=BOTH)
! 
!         self.regexdisplay.bind('<Key>', self.recompile)
!         self.stringdisplay.bind('<Key>', self.reevaluate)
! 
!         self.compiled = None
!         self.recompile()
! 
!         btags = self.regexdisplay.bindtags()
!         self.regexdisplay.bindtags(btags[1:] + btags[:1])
! 
!         btags = self.stringdisplay.bindtags()
!         self.stringdisplay.bindtags(btags[1:] + btags[:1])
! 
!     def addoptions(self):
!         self.frames = []
!         self.boxes = []
!         self.vars = []
!         for name in ('IGNORECASE',
!                      'LOCALE',
!                      'MULTILINE',
!                      'DOTALL',
!                      'VERBOSE'):
!             if len(self.boxes) % 3 == 0:
!                 frame = Frame(self.master)
!                 frame.pack(fill=X)
!                 self.frames.append(frame)
!             val = getattr(re, name)
!             var = IntVar()
!             box = Checkbutton(frame,
!                     variable=var, text=name,
!                     offvalue=0, onvalue=val,
!                     command=self.recompile)
!             box.pack(side=LEFT)
!             self.boxes.append(box)
!             self.vars.append(var)
! 
!     def getflags(self):
!         flags = 0
!         for var in self.vars:
!             flags = flags | var.get()
!         flags = flags
!         return flags
! 
!     def recompile(self, event=None):
!         try:
!             self.compiled = re.compile(self.regexdisplay.get(),
!                                        self.getflags())
!             bg = self.promptdisplay['background']
!             self.statusdisplay.config(text="", background=bg)
!         except re.error, msg:
!             self.compiled = None
!             self.statusdisplay.config(
!                     text="re.error: %s" % str(msg),
!                     background="red")
!         self.reevaluate()
! 
!     def reevaluate(self, event=None):
!         try:
!             self.stringdisplay.tag_remove("hit", "1.0", END)
!         except TclError:
!             pass
!         try:
!             self.stringdisplay.tag_remove("hit0", "1.0", END)
!         except TclError:
!             pass
!         self.grouplist.delete(0, END)
!         if not self.compiled:
!             return
!         self.stringdisplay.tag_configure("hit", background="yellow")
!         self.stringdisplay.tag_configure("hit0", background="orange")
!         text = self.stringdisplay.get("1.0", END)
!         last = 0
!         nmatches = 0
!         while last <= len(text):
!             m = self.compiled.search(text, last)
!             if m is None:
!                 break
!             first, last = m.span()
!             if last == first:
!                 last = first+1
!                 tag = "hit0"
!             else:
!                 tag = "hit"
!             pfirst = "1.0 + %d chars" % first
!             plast = "1.0 + %d chars" % last
!             self.stringdisplay.tag_add(tag, pfirst, plast)
!             if nmatches == 0:
!                 self.stringdisplay.yview_pickplace(pfirst)
!                 groups = list(m.groups())
!                 groups.insert(0, m.group())
!                 for i in range(len(groups)):
!                     g = "%2d: %s" % (i, `groups[i]`)
!                     self.grouplist.insert(END, g)
!             nmatches = nmatches + 1
!             if self.showvar.get() == "first":
!                 break
! 
!         if nmatches == 0:
!             self.statusdisplay.config(text="(no match)",
!                                       background="yellow")
!         else:
!             self.statusdisplay.config(text="")
  
  

Index: suff.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/suff.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** suff.py	1996/11/27 19:44:36	1.4
--- suff.py	2001/01/17 08:48:39	1.5
***************
*** 8,29 ****
  
  def main():
! 	files = sys.argv[1:]
! 	suffixes = {}
! 	for file in files:
! 		suff = getsuffix(file)
! 		if not suffixes.has_key(suff):
! 			suffixes[suff] = []
! 		suffixes[suff].append(file)
! 	keys = suffixes.keys()
! 	keys.sort()
! 	for suff in keys:
! 		print `suff`, len(suffixes[suff])
  
  def getsuffix(file):
! 	suff = ''
! 	for i in range(len(file)):
! 		if file[i] == '.':
! 			suff = file[i:]
! 	return suff
  
  main()
--- 8,29 ----
  
  def main():
!     files = sys.argv[1:]
!     suffixes = {}
!     for file in files:
!         suff = getsuffix(file)
!         if not suffixes.has_key(suff):
!             suffixes[suff] = []
!         suffixes[suff].append(file)
!     keys = suffixes.keys()
!     keys.sort()
!     for suff in keys:
!         print `suff`, len(suffixes[suff])
  
  def getsuffix(file):
!     suff = ''
!     for i in range(len(file)):
!         if file[i] == '.':
!             suff = file[i:]
!     return suff
  
  main()

Index: sum5.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/sum5.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** sum5.py	1996/11/27 19:44:37	1.2
--- sum5.py	2001/01/17 08:48:39	1.3
***************
*** 26,97 ****
  
  def sum(*files):
! 	sts = 0
! 	if files and type(files[-1]) == FileType:
! 		out, files = files[-1], files[:-1]
! 	else:
! 		out = sys.stdout
! 	if len(files) == 1 and type(files[0]) != StringType:
! 		files = files[0]
! 	for f in files:
! 		if type(f) == StringType:
! 			if f == '-':
! 				sts = printsumfp(sys.stdin, '<stdin>', out) or sts
! 			else:
! 				sts = printsum(f, out) or sts
! 		else:
! 			sts = sum(f, out) or sts
! 	return sts
  
  def printsum(file, out = sys.stdout):
! 	try:
! 		fp = open(file, rmode)
! 	except IOError, msg:
! 		sys.stderr.write('%s: Can\'t open: %s\n' % (file, msg))
! 		return 1
! 	if fnfilter:
! 		file = fnfilter(file)
! 	sts = printsumfp(fp, file, out)
! 	fp.close()
! 	return sts
  
  def printsumfp(fp, file, out = sys.stdout):
! 	m = md5.md5()
! 	try:
! 		while 1:
! 			data = fp.read(bufsize)
! 			if not data: break
! 			m.update(data)
! 	except IOError, msg:
! 		sys.stderr.write('%s: I/O error: %s\n' % (file, msg))
! 		return 1
! 	out.write('%s %s\n' % (hexify(m.digest()), file))
! 	return 0
  
  def hexify(s):
! 	res = ''
! 	for c in s:
! 		res = res + '%02x' % ord(c)
! 	return res
  
  def main(args = sys.argv[1:], out = sys.stdout):
! 	global fnfilter, rmode, bufsize
! 	import getopt
! 	try:
! 		opts, args = getopt.getopt(args, 'blts:')
! 	except getopt.error, msg:
! 		sys.stderr.write('%s: %s\n%s' % (sys.argv[0], msg, usage))
! 		return 2
! 	for o, a in opts:
! 		if o == '-l':
! 			fnfilter = os.path.basename
! 		if o == '-b':
! 			rmode = 'rb'
! 		if o == '-t':
! 			rmode = 'r'
! 		if o == '-s':
! 			bufsize = string.atoi(a)
! 	if not args: args = ['-']
! 	return sum(args, out)
  
  if __name__ == '__main__' or __name__ == sys.argv[0]:
! 	sys.exit(main(sys.argv[1:], sys.stdout))
--- 26,97 ----
  
  def sum(*files):
!     sts = 0
!     if files and type(files[-1]) == FileType:
!         out, files = files[-1], files[:-1]
!     else:
!         out = sys.stdout
!     if len(files) == 1 and type(files[0]) != StringType:
!         files = files[0]
!     for f in files:
!         if type(f) == StringType:
!             if f == '-':
!                 sts = printsumfp(sys.stdin, '<stdin>', out) or sts
!             else:
!                 sts = printsum(f, out) or sts
!         else:
!             sts = sum(f, out) or sts
!     return sts
  
  def printsum(file, out = sys.stdout):
!     try:
!         fp = open(file, rmode)
!     except IOError, msg:
!         sys.stderr.write('%s: Can\'t open: %s\n' % (file, msg))
!         return 1
!     if fnfilter:
!         file = fnfilter(file)
!     sts = printsumfp(fp, file, out)
!     fp.close()
!     return sts
  
  def printsumfp(fp, file, out = sys.stdout):
!     m = md5.md5()
!     try:
!         while 1:
!             data = fp.read(bufsize)
!             if not data: break
!             m.update(data)
!     except IOError, msg:
!         sys.stderr.write('%s: I/O error: %s\n' % (file, msg))
!         return 1
!     out.write('%s %s\n' % (hexify(m.digest()), file))
!     return 0
  
  def hexify(s):
!     res = ''
!     for c in s:
!         res = res + '%02x' % ord(c)
!     return res
  
  def main(args = sys.argv[1:], out = sys.stdout):
!     global fnfilter, rmode, bufsize
!     import getopt
!     try:
!         opts, args = getopt.getopt(args, 'blts:')
!     except getopt.error, msg:
!         sys.stderr.write('%s: %s\n%s' % (sys.argv[0], msg, usage))
!         return 2
!     for o, a in opts:
!         if o == '-l':
!             fnfilter = os.path.basename
!         if o == '-b':
!             rmode = 'rb'
!         if o == '-t':
!             rmode = 'r'
!         if o == '-s':
!             bufsize = string.atoi(a)
!     if not args: args = ['-']
!     return sum(args, out)
  
  if __name__ == '__main__' or __name__ == sys.argv[0]:
!     sys.exit(main(sys.argv[1:], sys.stdout))

Index: texi2html.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/texi2html.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -r1.11 -r1.12
*** texi2html.py	1998/10/08 15:24:48	1.11
--- texi2html.py	2001/01/17 08:48:39	1.12
***************
*** 47,51 ****
                                                    # with {} args)
  spprog = re.compile('[\n@{}&<>]')                 # Special characters in
!                                                   # running text 
                                                    #
                                                    # menu item (Yuck!)
--- 47,51 ----
                                                    # with {} args)
  spprog = re.compile('[\n@{}&<>]')                 # Special characters in
!                                                   # running text
                                                    #
                                                    # menu item (Yuck!)
***************
*** 53,57 ****
  
  
! 
  class HTMLNode:
      """Some of the parser's functionality is separated into this class.
--- 53,57 ----
  
  
! 
  class HTMLNode:
      """Some of the parser's functionality is separated into this class.
***************
*** 1569,1573 ****
      cont = 0
      html3 = 0
!    
      while sys.argv[1:2] == ['-d']:
          debugging = debugging + 1
--- 1569,1573 ----
      cont = 0
      html3 = 0
! 
      while sys.argv[1:2] == ['-d']:
          debugging = debugging + 1

Index: trace.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/trace.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** trace.py	2000/09/18 01:46:01	1.2
--- trace.py	2001/01/17 08:48:39	1.3
***************
*** 262,266 ****
      # SET_LINENO instructions.  Isn't there some way to get it from
      # the AST?
!     
      return _find_LINENO(code)
  
--- 262,266 ----
      # SET_LINENO instructions.  Isn't there some way to get it from
      # the AST?
! 
      return _find_LINENO(code)
  
***************
*** 280,284 ****
                  break
      return os.sep.join(prefix)
!     
  def create_results_log(results, dirname = ".", show_missing = 1,
                         save_counts = 0):
--- 280,284 ----
                  break
      return os.sep.join(prefix)
! 
  def create_results_log(results, dirname = ".", show_missing = 1,
                         save_counts = 0):
***************
*** 298,302 ****
      except IOError:
          pass
!     
      # there are many places where this is insufficient, like a blank
      # line embedded in a multiline string.
--- 298,302 ----
      except IOError:
          pass
! 
      # there are many places where this is insufficient, like a blank
      # line embedded in a multiline string.
***************
*** 308,312 ****
      for key in per_file.keys():
          filename = key
!         
          # skip some "files" we don't care about...
          if filename == "<string>":
--- 308,312 ----
      for key in per_file.keys():
          filename = key
! 
          # skip some "files" we don't care about...
          if filename == "<string>":
***************
*** 485,489 ****
  
          return self.trace
!     
  
  def _err_exit(msg):
--- 485,489 ----
  
          return self.trace
! 
  
  def _err_exit(msg):

Index: treesync.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/treesync.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** treesync.py	1998/03/24 05:30:29	1.4
--- treesync.py	2001/01/17 08:48:39	1.5
***************
*** 18,22 ****
          else (the master is newer):
              copy the master to the slave
!     
      normalizing the slave means replacing CRLF with LF when the master
      doesn't use CRLF
--- 18,22 ----
          else (the master is newer):
              copy the master to the slave
! 
      normalizing the slave means replacing CRLF with LF when the master
      doesn't use CRLF
***************
*** 60,64 ****
          return
      process(slave, master)
!     
  def process(slave, master):
      cvsdir = os.path.join(master, "CVS")
--- 60,64 ----
          return
      process(slave, master)
! 
  def process(slave, master):
      cvsdir = os.path.join(master, "CVS")

Index: which.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/which.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** which.py	1997/10/20 23:48:01	1.8
--- which.py	2001/01/17 08:48:39	1.9
***************
*** 12,16 ****
  
  def msg(str):
! 	sys.stderr.write(str + '\n')
  
  pathlist = string.splitfields(os.environ['PATH'], ':')
--- 12,16 ----
  
  def msg(str):
!     sys.stderr.write(str + '\n')
  
  pathlist = string.splitfields(os.environ['PATH'], ':')
***************
*** 20,56 ****
  
  if sys.argv[1:] and sys.argv[1][:2] == '-l':
! 	longlist = sys.argv[1]
! 	del sys.argv[1]
  
  for prog in sys.argv[1:]:
! 	ident = ()
! 	for dir in pathlist:
! 		file = os.path.join(dir, prog)
! 		try:
! 			st = os.stat(file)
! 		except os.error:
! 			continue
! 		if not S_ISREG(st[ST_MODE]):
! 			msg(file + ': not a disk file')
! 		else:
! 			mode = S_IMODE(st[ST_MODE])
! 			if mode & 0111:
! 				if not ident:
! 					print file
! 					ident = st[:3]
! 				else:
! 					if st[:3] == ident:
! 						s = 'same as: '
! 					else:
! 						s = 'also: '
! 					msg(s + file)
! 			else:
! 				msg(file + ': not executable')
! 		if longlist:
! 			sts = os.system('ls ' + longlist + ' ' + file)
! 			if sts: msg('"ls -l" exit status: ' + `sts`)
! 	if not ident:
! 		msg(prog + ': not found')
! 		sts = 1
  
  sys.exit(sts)
--- 20,56 ----
  
  if sys.argv[1:] and sys.argv[1][:2] == '-l':
!     longlist = sys.argv[1]
!     del sys.argv[1]
  
  for prog in sys.argv[1:]:
!     ident = ()
!     for dir in pathlist:
!         file = os.path.join(dir, prog)
!         try:
!             st = os.stat(file)
!         except os.error:
!             continue
!         if not S_ISREG(st[ST_MODE]):
!             msg(file + ': not a disk file')
!         else:
!             mode = S_IMODE(st[ST_MODE])
!             if mode & 0111:
!                 if not ident:
!                     print file
!                     ident = st[:3]
!                 else:
!                     if st[:3] == ident:
!                         s = 'same as: '
!                     else:
!                         s = 'also: '
!                     msg(s + file)
!             else:
!                 msg(file + ': not executable')
!         if longlist:
!             sts = os.system('ls ' + longlist + ' ' + file)
!             if sts: msg('"ls -l" exit status: ' + `sts`)
!     if not ident:
!         msg(prog + ': not found')
!         sts = 1
  
  sys.exit(sts)

Index: xxci.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Tools/scripts/xxci.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -r1.13 -r1.14
*** xxci.py	1996/11/27 19:44:40	1.13
--- xxci.py	2001/01/17 08:48:39	1.14
***************
*** 17,117 ****
  
  def getargs():
! 	args = sys.argv[1:]
! 	if args:
! 		return args
! 	print 'No arguments, checking almost *, in "ls -t" order'
! 	list = []
! 	for file in os.listdir(os.curdir):
! 		if not skipfile(file):
! 			list.append((getmtime(file), file))
! 	list.sort()
! 	if not list:
! 		print 'Nothing to do -- exit 1'
! 		sys.exit(1)
! 	list.sort()
! 	list.reverse()
! 	for mtime, file in list: args.append(file)
! 	return args
  
  def getmtime(file):
! 	try:
! 		st = os.stat(file)
! 		return st[ST_MTIME]
! 	except os.error:
! 		return -1
  
  badnames = ['tags', 'TAGS', 'xyzzy', 'nohup.out', 'core']
  badprefixes = ['.', ',', '@', '#', 'o.']
  badsuffixes = \
! 	['~', '.a', '.o', '.old', '.bak', '.orig', '.new', '.prev', '.not', \
! 	 '.pyc', '.fdc', '.rgb', '.elc', ',v']
  ignore = []
  
  def setup():
! 	ignore[:] = badnames
! 	for p in badprefixes:
! 		ignore.append(p + '*')
! 	for p in badsuffixes:
! 		ignore.append('*' + p)
! 	try:
! 		f = open('.xxcign', 'r')
! 	except IOError:
! 		return
! 	ignore[:] = ignore + string.split(f.read())
  
  def skipfile(file):
! 	for p in ignore:
! 		if fnmatch.fnmatch(file, p): return 1
! 	try:
! 		st = os.lstat(file)
! 	except os.error:
! 		return 1 # Doesn't exist -- skip it
! 	# Skip non-plain files.
! 	if not S_ISREG(st[ST_MODE]): return 1
! 	# Skip huge files -- probably binaries.
! 	if st[ST_SIZE] >= MAXSIZE: return 1
! 	# Skip executables
! 	try:
! 		data = open(file, 'r').read(len(EXECMAGIC))
! 		if data == EXECMAGIC: return 1
! 	except:
! 		pass
! 	return 0
  
  def badprefix(file):
! 	for bad in badprefixes:
! 		if file[:len(bad)] == bad: return 1
! 	return 0
  
  def badsuffix(file):
! 	for bad in badsuffixes:
! 		if file[-len(bad):] == bad: return 1
! 	return 0
  
  def go(args):
! 	for file in args:
! 		print file + ':'
! 		if differing(file):
! 			showdiffs(file)
! 			if askyesno('Check in ' + file + ' ? '):
! 				sts = os.system('rcs -l ' + file) # ignored
! 				sts = os.system('ci -l ' + file)
  
  def differing(file):
! 	cmd = 'co -p ' + file + ' 2>/dev/null | cmp -s - ' + file
! 	sts = os.system(cmd)
! 	return sts != 0
  
  def showdiffs(file):
! 	cmd = 'rcsdiff ' + file + ' 2>&1 | ${PAGER-more}'
! 	sts = os.system(cmd)
  
  def askyesno(prompt):
! 	s = raw_input(prompt)
! 	return s in ['y', 'yes']
  
  try:
! 	setup()
! 	go(getargs())
  except KeyboardInterrupt:
! 	print '[Intr]'
--- 17,117 ----
  
  def getargs():
!     args = sys.argv[1:]
!     if args:
!         return args
!     print 'No arguments, checking almost *, in "ls -t" order'
!     list = []
!     for file in os.listdir(os.curdir):
!         if not skipfile(file):
!             list.append((getmtime(file), file))
!     list.sort()
!     if not list:
!         print 'Nothing to do -- exit 1'
!         sys.exit(1)
!     list.sort()
!     list.reverse()
!     for mtime, file in list: args.append(file)
!     return args
  
  def getmtime(file):
!     try:
!         st = os.stat(file)
!         return st[ST_MTIME]
!     except os.error:
!         return -1
  
  badnames = ['tags', 'TAGS', 'xyzzy', 'nohup.out', 'core']
  badprefixes = ['.', ',', '@', '#', 'o.']
  badsuffixes = \
!         ['~', '.a', '.o', '.old', '.bak', '.orig', '.new', '.prev', '.not', \
!          '.pyc', '.fdc', '.rgb', '.elc', ',v']
  ignore = []
  
  def setup():
!     ignore[:] = badnames
!     for p in badprefixes:
!         ignore.append(p + '*')
!     for p in badsuffixes:
!         ignore.append('*' + p)
!     try:
!         f = open('.xxcign', 'r')
!     except IOError:
!         return
!     ignore[:] = ignore + string.split(f.read())
  
  def skipfile(file):
!     for p in ignore:
!         if fnmatch.fnmatch(file, p): return 1
!     try:
!         st = os.lstat(file)
!     except os.error:
!         return 1 # Doesn't exist -- skip it
!     # Skip non-plain files.
!     if not S_ISREG(st[ST_MODE]): return 1
!     # Skip huge files -- probably binaries.
!     if st[ST_SIZE] >= MAXSIZE: return 1
!     # Skip executables
!     try:
!         data = open(file, 'r').read(len(EXECMAGIC))
!         if data == EXECMAGIC: return 1
!     except:
!         pass
!     return 0
  
  def badprefix(file):
!     for bad in badprefixes:
!         if file[:len(bad)] == bad: return 1
!     return 0
  
  def badsuffix(file):
!     for bad in badsuffixes:
!         if file[-len(bad):] == bad: return 1
!     return 0
  
  def go(args):
!     for file in args:
!         print file + ':'
!         if differing(file):
!             showdiffs(file)
!             if askyesno('Check in ' + file + ' ? '):
!                 sts = os.system('rcs -l ' + file) # ignored
!                 sts = os.system('ci -l ' + file)
  
  def differing(file):
!     cmd = 'co -p ' + file + ' 2>/dev/null | cmp -s - ' + file
!     sts = os.system(cmd)
!     return sts != 0
  
  def showdiffs(file):
!     cmd = 'rcsdiff ' + file + ' 2>&1 | ${PAGER-more}'
!     sts = os.system(cmd)
  
  def askyesno(prompt):
!     s = raw_input(prompt)
!     return s in ['y', 'yes']
  
  try:
!     setup()
!     go(getargs())
  except KeyboardInterrupt:
!     print '[Intr]'