You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
899 B

34 years ago
34 years ago
34 years ago
34 years ago
  1. #!/usr/bin/env python3
  2. # Fix Python script(s) to reference the interpreter via /usr/bin/env python.
  3. # Warning: this overwrites the file without making a backup.
  4. import sys
  5. import re
  6. def main():
  7. for filename in sys.argv[1:]:
  8. try:
  9. f = open(filename, 'r')
  10. except IOError as msg:
  11. print(filename, ': can\'t open :', msg)
  12. continue
  13. line = f.readline()
  14. if not re.match('^#! */usr/local/bin/python', line):
  15. print(filename, ': not a /usr/local/bin/python script')
  16. f.close()
  17. continue
  18. rest = f.read()
  19. f.close()
  20. line = re.sub('/usr/local/bin/python',
  21. '/usr/bin/env python', line)
  22. print(filename, ':', repr(line))
  23. f = open(filename, "w")
  24. f.write(line)
  25. f.write(rest)
  26. f.close()
  27. if __name__ == '__main__':
  28. main()