Source

pygame / config_unix.py

Diff from to

File config_unix.py

 """Config on Unix"""
 
-import os, sys, string
+import os, sys
 from glob import glob
 from distutils.sysconfig import get_python_inc
 
+# Python 2.x/3.x compatibility
+try:
+    raw_input
+except NameError:
+    raw_input = input
+
 configcommand = os.environ.get('SDL_CONFIG', 'sdl-config',)
 configcommand = configcommand + ' --version --cflags --libs'
 localbase = os.environ.get('LOCALBASE', '')
 def confirm(message):
     "ask a yes/no question, return result"
     reply = raw_input('\n' + message + ' [Y/n]:')
-    if reply and string.lower(reply[0]) == 'n':
+    if reply and (reply[0].lower()) == 'n':
         return 0
     return 1
 
         self.cflags = ''
         try:
             config = os.popen(command + ' --version --cflags --libs').readlines()
-            flags = string.split(string.join(config[1:], ' '))
+            flags = ' '.join(config[1:]).split()
 
             # remove this GNU_SOURCE if there... since python has it already,
             #   it causes a warning.
             if '-D_GNU_SOURCE=1' in flags:
                 flags.remove('-D_GNU_SOURCE=1')
-            self.ver = string.strip(config[0])
+            self.ver = config[0].strip()
             if minver and self.ver < minver:
                 err= 'WARNING: requires %s version %s (%s found)' % (self.name, self.ver, minver)
-                raise ValueError, err
+                raise ValueError(err)
             self.found = 1
             self.cflags = ''
             for f in flags:
                 elif f[:3] == '-Wl':
                     self.cflags += '-Xlinker ' + f + ' '
             if self.name == 'SDL':
-		inc = '-I' + '/usr/X11R6/include'
-		self.cflags = inc + ' ' + self.cflags
+                inc = '-I' + '/usr/X11R6/include'
+                self.cflags = inc + ' ' + self.cflags
         except:
-            print 'WARNING: "%s" failed!' % command    
+            print ('WARNING: "%s" failed!' % command)
             self.found = 0
             self.ver = '0'
             self.libs = defaultlibs
 
     def configure(self, incdirs, libdir):
         if self.found:
-            print self.name + '        '[len(self.name):] + ': found ' + self.ver
+            print (self.name + '        '[len(self.name):] + ': found ' + self.ver)
             self.found = 1
         else:
-            print self.name + '        '[len(self.name):] + ': not found'
+            print (self.name + '        '[len(self.name):] + ': not found')
 
 class Dependency:
     def __init__(self, name, checkhead, checklib, libs):
     
     def configure(self, incdirs, libdirs):
         incname = self.checkhead
-        libnames = self.checklib, string.lower(self.name)
+        libnames = self.checklib, self.name.lower()
         
         if incname:
             for dir in incdirs:
                     self.lib_dir = dir
 
         if (incname and self.lib_dir and self.inc_dir) or (not incname and self.lib_dir):
-            print self.name + '        '[len(self.name):] + ': found'
+            print (self.name + '        '[len(self.name):] + ': found')
             self.found = 1
         else:
-            print self.name + '        '[len(self.name):] + ': not found'
+            print (self.name + '        '[len(self.name):] + ': not found')
 
 class DependencyPython:
     def __init__(self, name, module, header):
             else:
                 self.inc_dir = os.path.split(fullpath)[0]
         if self.found:
-            print self.name + '        '[len(self.name):] + ': found', self.ver
+            print (self.name + '        '[len(self.name):] + ': found', self.ver)
         else:
-            print self.name + '        '[len(self.name):] + ': not found'
+            print (self.name + '        '[len(self.name):] + ': not found')
 
 sdl_lib_name = 'SDL'
 
 def main():
-    print '\nHunting dependencies...'
+    print ('\nHunting dependencies...')
     DEPS = [
         DependencyProg('SDL', 'SDL_CONFIG', 'sdl-config', '1.2', ['sdl']),
         Dependency('FONT', 'SDL_ttf.h', 'libSDL_ttf.so', ['SDL_ttf']),
         Dependency('PORTTIME', 'porttime.h', 'libporttime.so', ['porttime']),
         #Dependency('GFX', 'SDL_gfxPrimitives.h', 'libSDL_gfx.so', ['SDL_gfx']),
     ]
-
     if not DEPS[0].found:
-        print 'Unable to run "sdl-config". Please make sure a development version of SDL is installed.'
+        print ('Unable to run "sdl-config". Please make sure a development version of SDL is installed.')
         raise SystemExit
 
     if localbase:
     incdirs += ["/usr/local"+d for d in origincdirs]
     libdirs += ["/usr/local"+d for d in origlibdirs]
 
-    for arg in string.split(DEPS[0].cflags):
+    for arg in DEPS[0].cflags.split():
         if arg[:2] == '-I':
             incdirs.append(arg[2:])
         elif arg[:2] == '-L':
     return DEPS
 
 if __name__ == '__main__':
-    print """This is the configuration subscript for Unix.
-Please run "config.py" for full configuration."""
+    print ("""This is the configuration subscript for Unix.
+Please run "config.py" for full configuration.""")