Source

pygame / config.py

Diff from to

File config.py

 #!/usr/bin/env python
+# For MinGW build requires Python 2.4 or better and win32api.
 
 """Quick tool to help setup the needed paths and flags
 in your Setup file. This will call the appropriate sub-config
 cflags: extra compile flags
 """
 
-import sys, os, shutil, string
+import msysio
+import mingwcfg
+import sys, os, shutil
 
-def is_msys_mingw():
-    if os.environ.has_key("MSYSTEM"):
-        if os.environ["MSYSTEM"] == "MINGW32":
-            return 1
-    return 0
-
-if sys.platform == 'win32' and not is_msys_mingw():
-    print 'Using WINDOWS configuration...\n'
-    import config_win
-    CFG = config_win
-elif sys.platform == 'win32' and is_msys_mingw():
-    print 'Using WINDOWS mingw/msys configuration...\n'
-    import config_msys
-    CFG = config_msys
-elif sys.platform == 'darwin':
-    print 'Using Darwin configuration...\n'
-    import config_darwin
-    CFG = config_darwin
-else:
-    print 'Using UNIX configuration...\n'
-    import config_unix
-    CFG = config_unix
+def print_(*args, **kwds):
+    """Simular to the Python 3.0 print function"""
+    # This not only supports MSYS but is also a head start on the move to
+    # Python 3.0. Also, this function can be overridden for testing.
+    msysio.print_(*args, **kwds)
 
 def confirm(message):
     "ask a yes/no question, return result"
-    #The output must be flushed for the prompt to be visible on MSYS bash
-    sys.stdout.write("\n%s [Y/n]:" % message)
-    sys.stdout.flush()
-    reply = raw_input()
-    if reply and string.lower(reply[0]) == 'n':
-        return 0
-    return 1
+    reply = msysio.raw_input_("\n%s [Y/n]:" % message)
+    if reply and reply[0].lower() == 'n':
+        return False
+    return True
+
+def is_msys_mingw():
+    """Return true if this in an MinGW/MSYS build
+
+    The user may prompted for confirmation so only call this function
+    once.
+    """
+    if msysio.is_msys():
+        return 1
+    if ('MINGW_ROOT_DIRECTORY' in os.environ or
+        os.path.isfile(mingwcfg.path)):
+        return confirm("Is this an mingw/msys build")
+    return 0
 
 def prepdep(dep, basepath):
     "add some vars to a dep"
     else:
         dep.line = dep.name+' =' + inc + lid + ' ' + dep.cflags + libs
 
-def writesetupfile(deps, basepath):
+def writesetupfile(deps, basepath, additional_lines):
     "create a modified copy of Setup.in"
     origsetup = open('Setup.in', 'r')
     newsetup = open('Setup', 'w')
     for d in deps:
         newsetup.write(d.line + '\n')
 
-    while line:
-        line = origsetup.readline()
+    lines = origsetup.readlines()
+    lines.extend(additional_lines)
+    for line in lines:
         useit = 1
         if not line.startswith('COPYLIB'):
             for d in deps:
                     newsetup.write('#'+line)
                     break
         if useit:
-            newsetup.write(line)
+            newsetup.write(line)        
 
 def main():
+    additional_platform_setup = []
+    if (sys.platform == 'win32' and
+        # Note that msys builds supported for 2.6 and greater. Use prebuilt.
+        (sys.version_info >= (2, 6) or not is_msys_mingw())):
+        print_('Using WINDOWS configuration...\n')
+        import config_win as CFG
+    elif sys.platform == 'win32':
+        print_('Using WINDOWS mingw/msys configuration...\n')
+        import config_msys as CFG
+    elif sys.platform == 'darwin':
+        print_('Using Darwin configuration...\n')
+        import config_darwin as CFG
+        additional_platform_setup = file("Setup_Darwin.in", "r").readlines()
+    else:
+        print_('Using UNIX configuration...\n')
+        import config_unix as CFG
+    
     if os.path.isfile('Setup'):
         if "-auto" in sys.argv or confirm('Backup existing "Setup" file'):
             shutil.copyfile('Setup', 'Setup.bak')
         basepath = None
         for d in deps:
             prepdep(d, basepath)
-        writesetupfile(deps, basepath)
-        print """\nIf you get compiler errors during install, doublecheck
-the compiler flags in the "Setup" file.\n"""
+        writesetupfile(deps, basepath, additional_platform_setup)
+        print_("""\nIf you get compiler errors during install, doublecheck
+the compiler flags in the "Setup" file.\n""")
     else:
-        print """\nThere was an error creating the Setup file, check for errors
-or make a copy of "Setup.in" and edit by hand."""
+        print_("""\nThere was an error creating the Setup file, check for errors
+or make a copy of "Setup.in" and edit by hand.""")
 
 if __name__ == '__main__': main()