comparison Mac/Tools/fixapplepython23.py @ 43077:dcedd32f06de

Run 2to3's print fixer over some places that had been missed.
author Collin Winter <collinw@gmail.com>
date Thu, 30 Aug 2007 18:39:28 +0000
parents cc992d75d5b3
children b5f535cf135f
comparison
equal deleted inserted replaced
43075:504c15f05df3 43077:dcedd32f06de
55 if i >= 0: 55 if i >= 0:
56 # Already fixed 56 # Already fixed
57 continue 57 continue
58 i = findline(lines, old) 58 i = findline(lines, old)
59 if i < 0: 59 if i < 0:
60 print 'fixapplepython23: Python installation not fixed (appears broken)' 60 print('fixapplepython23: Python installation not fixed (appears broken)')
61 print 'fixapplepython23: missing line:', old 61 print('fixapplepython23: missing line:', old)
62 return 2 62 return 2
63 lines[i] = new 63 lines[i] = new
64 fixed = True 64 fixed = True
65 65
66 if fixed: 66 if fixed:
67 if do_apply: 67 if do_apply:
68 print 'fixapplepython23: Fix to Apple-installed Python 2.3 applied' 68 print('fixapplepython23: Fix to Apple-installed Python 2.3 applied')
69 os.rename(makefile, makefile + '~') 69 os.rename(makefile, makefile + '~')
70 open(makefile, 'w').writelines(lines) 70 open(makefile, 'w').writelines(lines)
71 return 0 71 return 0
72 else: 72 else:
73 print 'fixapplepython23: Fix to Apple-installed Python 2.3 should be applied' 73 print('fixapplepython23: Fix to Apple-installed Python 2.3 should be applied')
74 return 1 74 return 1
75 else: 75 else:
76 print 'fixapplepython23: No fix needed, appears to have been applied before' 76 print('fixapplepython23: No fix needed, appears to have been applied before')
77 return 0 77 return 0
78 78
79 def makescript(filename, compiler): 79 def makescript(filename, compiler):
80 """Create a wrapper script for a compiler""" 80 """Create a wrapper script for a compiler"""
81 dirname = os.path.split(filename)[0] 81 dirname = os.path.split(filename)[0]
83 os.mkdir(dirname, 0755) 83 os.mkdir(dirname, 0755)
84 fp = open(filename, 'w') 84 fp = open(filename, 'w')
85 fp.write(SCRIPT % compiler) 85 fp.write(SCRIPT % compiler)
86 fp.close() 86 fp.close()
87 os.chmod(filename, 0755) 87 os.chmod(filename, 0755)
88 print 'fixapplepython23: Created', filename 88 print('fixapplepython23: Created', filename)
89 89
90 def main(): 90 def main():
91 # Check for -n option 91 # Check for -n option
92 if len(sys.argv) > 1 and sys.argv[1] == '-n': 92 if len(sys.argv) > 1 and sys.argv[1] == '-n':
93 do_apply = False 93 do_apply = False
94 else: 94 else:
95 do_apply = True 95 do_apply = True
96 # First check OS version 96 # First check OS version
97 if sys.byteorder == 'little': 97 if sys.byteorder == 'little':
98 # All intel macs are fine 98 # All intel macs are fine
99 print "fixapplypython23: no fix is needed on MacOSX on Intel" 99 print("fixapplypython23: no fix is needed on MacOSX on Intel")
100 sys.exit(0) 100 sys.exit(0)
101 101
102 if gestalt.gestalt('sysv') < 0x1030: 102 if gestalt.gestalt('sysv') < 0x1030:
103 print 'fixapplepython23: no fix needed on MacOSX < 10.3' 103 print('fixapplepython23: no fix needed on MacOSX < 10.3')
104 sys.exit(0) 104 sys.exit(0)
105 105
106 if gestalt.gestalt('sysv') >= 0x1040: 106 if gestalt.gestalt('sysv') >= 0x1040:
107 print 'fixapplepython23: no fix needed on MacOSX >= 10.4' 107 print('fixapplepython23: no fix needed on MacOSX >= 10.4')
108 sys.exit(0) 108 sys.exit(0)
109 109
110 # Test that a framework Python is indeed installed 110 # Test that a framework Python is indeed installed
111 if not os.path.exists(MAKEFILE): 111 if not os.path.exists(MAKEFILE):
112 print 'fixapplepython23: Python framework does not appear to be installed (?), nothing fixed' 112 print('fixapplepython23: Python framework does not appear to be installed (?), nothing fixed')
113 sys.exit(0) 113 sys.exit(0)
114 # Check that we can actually write the file 114 # Check that we can actually write the file
115 if do_apply and not os.access(MAKEFILE, os.W_OK): 115 if do_apply and not os.access(MAKEFILE, os.W_OK):
116 print 'fixapplepython23: No write permission, please run with "sudo"' 116 print('fixapplepython23: No write permission, please run with "sudo"')
117 sys.exit(2) 117 sys.exit(2)
118 # Create the shell scripts 118 # Create the shell scripts
119 if do_apply: 119 if do_apply:
120 if not os.access(GCC_SCRIPT, os.X_OK): 120 if not os.access(GCC_SCRIPT, os.X_OK):
121 makescript(GCC_SCRIPT, "gcc") 121 makescript(GCC_SCRIPT, "gcc")