home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyth_os2.zip / python-1.0.2 / Demo / scripts / fixps.py < prev    next >
Text File  |  1992-12-09  |  617b  |  33 lines

  1. #! /usr/local/bin/python
  2.  
  3. # Fix Python script(s) to reference the interpreter in /usr/local/bin.
  4.  
  5. import sys
  6. import regex
  7. import regsub
  8.  
  9.  
  10. def main():
  11.     for file in sys.argv[1:]:
  12.         try:
  13.             f = open(file, 'r+')
  14.         except IOError:
  15.             print file, ': can\'t open for update'
  16.             continue
  17.         line = f.readline()
  18.         if regex.match('^#! */usr/local/python', line) < 0:
  19.             print file, ': not a /usr/local/python script'
  20.             f.close()
  21.             continue
  22.         rest = f.read()
  23.         line = regsub.sub('/usr/local/python', \
  24.             '/usr/local/bin/python', line)
  25.         print file, ':', `line`
  26.         f.seek(0)
  27.         f.write(line)
  28.         f.write(rest)
  29.         f.close()
  30.  
  31.  
  32. main()
  33.