home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 April / PCWorld_2001-04_cd.bin / Software / TemaCD / webclean / !!!python!!! / BeOpen-Python-2.0.exe / FIXNOTICE.PY < prev    next >
Encoding:
Python Source  |  2000-09-28  |  1.2 KB  |  49 lines

  1. #! /usr/bin/env python
  2.  
  3. OLD_NOTICE = """/***********************************************************
  4. Copyright (c) 2000, BeOpen.com.
  5. Copyright (c) 1995-2000, Corporation for National Research Initiatives.
  6. Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
  7. All rights reserved.
  8.  
  9. See the file "Misc/COPYRIGHT" for information on usage and
  10. redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  11. ******************************************************************/
  12. """
  13.  
  14. NEW_NOTICE = ""
  15.  
  16. # " <-- Help Emacs
  17.  
  18. import os, sys, string
  19.  
  20. def main():
  21.     args = sys.argv[1:]
  22.     if not args:
  23.         print "No arguments."
  24.     for arg in args:
  25.         process(arg)
  26.  
  27. def process(arg):
  28.     f = open(arg)
  29.     data = f.read()
  30.     f.close()
  31.     i = string.find(data, OLD_NOTICE)
  32.     if i < 0:
  33. ##         print "No old notice in", arg
  34.         return
  35.     data = data[:i] + NEW_NOTICE + data[i+len(OLD_NOTICE):]
  36.     new = arg + ".new"
  37.     backup = arg + ".bak"
  38.     print "Replacing notice in", arg, "...",
  39.     sys.stdout.flush()
  40.     f = open(new, "w")
  41.     f.write(data)
  42.     f.close()
  43.     os.rename(arg, backup)
  44.     os.rename(new, arg)
  45.     print "done"
  46.  
  47. if __name__ == '__main__':
  48.     main()
  49.