| 
									
										
										
										
											2010-03-11 22:53:45 +00:00
										 |  |  | #!/usr/bin/env python3 | 
					
						
							| 
									
										
										
										
											1992-12-09 23:14:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1996-11-27 19:43:49 +00:00
										 |  |  | # Fix Python script(s) to reference the interpreter via /usr/bin/env python. | 
					
						
							| 
									
										
										
										
											1999-04-09 14:56:35 +00:00
										 |  |  | # Warning: this overwrites the file without making a backup. | 
					
						
							| 
									
										
										
										
											1992-12-09 23:14:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | import sys | 
					
						
							| 
									
										
										
										
											1999-04-09 14:56:35 +00:00
										 |  |  | import re | 
					
						
							| 
									
										
										
										
											1992-12-09 23:14:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def main(): | 
					
						
							| 
									
										
										
										
											2003-05-13 18:14:25 +00:00
										 |  |  |     for filename in sys.argv[1:]: | 
					
						
							| 
									
										
										
										
											2001-01-17 08:48:39 +00:00
										 |  |  |         try: | 
					
						
							| 
									
										
										
										
											2003-05-13 18:14:25 +00:00
										 |  |  |             f = open(filename, 'r') | 
					
						
							| 
									
										
										
										
											2007-01-10 16:19:56 +00:00
										 |  |  |         except IOError as msg: | 
					
						
							| 
									
										
										
										
											2007-08-03 17:06:41 +00:00
										 |  |  |             print(filename, ': can\'t open :', msg) | 
					
						
							| 
									
										
										
										
											2001-01-17 08:48:39 +00:00
										 |  |  |             continue | 
					
						
							|  |  |  |         line = f.readline() | 
					
						
							|  |  |  |         if not re.match('^#! */usr/local/bin/python', line): | 
					
						
							| 
									
										
										
										
											2007-08-03 17:06:41 +00:00
										 |  |  |             print(filename, ': not a /usr/local/bin/python script') | 
					
						
							| 
									
										
										
										
											2001-01-17 08:48:39 +00:00
										 |  |  |             f.close() | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  |         rest = f.read() | 
					
						
							|  |  |  |         f.close() | 
					
						
							|  |  |  |         line = re.sub('/usr/local/bin/python', | 
					
						
							|  |  |  |                       '/usr/bin/env python', line) | 
					
						
							| 
									
										
										
										
											2007-08-03 17:06:41 +00:00
										 |  |  |         print(filename, ':', repr(line)) | 
					
						
							| 
									
										
										
										
											2003-05-13 18:14:25 +00:00
										 |  |  |         f = open(filename, "w") | 
					
						
							| 
									
										
										
										
											2001-01-17 08:48:39 +00:00
										 |  |  |         f.write(line) | 
					
						
							|  |  |  |         f.write(rest) | 
					
						
							|  |  |  |         f.close() | 
					
						
							| 
									
										
										
										
											1992-12-09 23:14:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-08-09 17:27:55 +00:00
										 |  |  | if __name__ == '__main__': | 
					
						
							|  |  |  |     main() |