comparison setup_posix.py @ 58:6732437eb2ac MySQLdb

Minor tidy of whitespace and extra import
author kylev
date Sat, 28 Feb 2009 08:03:32 +0000
parents 7c7a89123d65
children c9fd1a7932f4
comparison
equal deleted inserted replaced
57:9ea2b0e9302e 58:6732437eb2ac
1 from ConfigParser import SafeConfigParser 1 import os
2 2 import sys
3 # This dequote() business is required for some older versions
4 # of mysql_config
5 3
6 def dequote(s): 4 def dequote(s):
5 """This dequote() business is required for some older versions of
6 mysql_config.
7 """
7 if s[0] in "\"'" and s[0] == s[-1]: 8 if s[0] in "\"'" and s[0] == s[-1]:
8 s = s[1:-1] 9 s = s[1:-1]
9 return s 10 return s
10 11
11 def compiler_flag(f): 12 def compiler_flag(f):
12 return "-%s" % f 13 return "-%s" % f
13 14
14 def mysql_config(what): 15 def mysql_config(what):
15 from os import popen 16 f = os.popen("%s --%s" % (mysql_config.path, what))
16
17 f = popen("%s --%s" % (mysql_config.path, what))
18 data = f.read().strip().split() 17 data = f.read().strip().split()
19 ret = f.close() 18 ret = f.close()
20 if ret: 19 if ret:
21 if ret/256: 20 if ret/256:
22 data = [] 21 data = []
24 raise EnvironmentError, "%s not found" % mysql_config.path 23 raise EnvironmentError, "%s not found" % mysql_config.path
25 return data 24 return data
26 mysql_config.path = "mysql_config" 25 mysql_config.path = "mysql_config"
27 26
28 def get_config(): 27 def get_config():
29 import os, sys
30 from setup_common import get_metadata_and_options, enabled, create_release_file 28 from setup_common import get_metadata_and_options, enabled, create_release_file
31 29
32 metadata, options = get_metadata_and_options() 30 metadata, options = get_metadata_and_options()
33 31
34 if 'mysql_config' in options: 32 if 'mysql_config' in options:
35 mysql_config.path = options['mysql_config'] 33 mysql_config.path = options['mysql_config']
36 34
37 extra_objects = [] 35 extra_objects = []
38 static = enabled(options, 'static') 36 static = enabled(options, 'static')
39 if enabled(options, 'embedded'): 37 if enabled(options, 'embedded'):
40 libs = mysql_config("libmysqld-libs") 38 libs = mysql_config("libmysqld-libs")
41 client = "mysqld" 39 client = "mysqld"
49 libs = mysql_config("libs") 47 libs = mysql_config("libs")
50 client = "mysqlclient" 48 client = "mysqlclient"
51 49
52 library_dirs = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("L")) ] 50 library_dirs = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("L")) ]
53 libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ] 51 libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ]
54 52
55 removable_compile_args = [ compiler_flag(f) for f in "ILl" ] 53 removable_compile_args = [ compiler_flag(f) for f in "ILl" ]
56 extra_compile_args = [ i.replace("%", "%%") for i in mysql_config("cflags") 54 extra_compile_args = [ i.replace("%", "%%") for i in mysql_config("cflags")
57 if i[:2] not in removable_compile_args ] 55 if i[:2] not in removable_compile_args ]
58 include_dirs = [ dequote(i[2:]) 56 include_dirs = [ dequote(i[2:])
59 for i in mysql_config('include') 57 for i in mysql_config('include')
60 if i.startswith(compiler_flag('I')) ] 58 if i.startswith(compiler_flag('I')) ]
61 if not include_dirs: # fix for MySQL-3.23 59 if not include_dirs: # fix for MySQL-3.23
62 include_dirs = [ dequote(i[2:]) 60 include_dirs = [ dequote(i[2:])
63 for i in mysql_config('cflags') 61 for i in mysql_config('cflags')
64 if i.startswith(compiler_flag('I')) ] 62 if i.startswith(compiler_flag('I')) ]
65 63
66 if static: 64 if static:
67 extra_objects.append(os.path.join( 65 extra_objects.append(os.path.join(
68 library_dirs[0],'lib%s.a' % client)) 66 library_dirs[0],'lib%s.a' % client))
69 67
70 name = "MySQL-python" 68 name = "MySQL-python"
71 if enabled(options, 'embedded'): 69 if enabled(options, 'embedded'):
72 name = name + "-embedded" 70 name = name + "-embedded"
73 metadata['name'] = name 71 metadata['name'] = name
74 72
75 define_macros = [ 73 define_macros = [
76 ('version_info', metadata['version_info']), 74 ('version_info', metadata['version_info']),
77 ('__version__', metadata['version']), 75 ('__version__', metadata['version']),
78 ] 76 ]
79 create_release_file(metadata) 77 create_release_file(metadata)
89 ) 87 )
90 return metadata, ext_options 88 return metadata, ext_options
91 89
92 if __name__ == "__main__": 90 if __name__ == "__main__":
93 print """You shouldn't be running this directly; it is used by setup.py.""" 91 print """You shouldn't be running this directly; it is used by setup.py."""
94