PageRenderTime 20ms CodeModel.GetById 12ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/scripts/scramble/scripts/psycopg2-linux.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 80 lines | 64 code | 10 blank | 6 comment | 5 complexity | d09e9ce359e20bdb1646730c4e265e6c MD5 | raw file
 1import os, sys, shutil
 2from distutils.sysconfig import get_config_var
 3
 4def prep_postgres( prepped, args ):
 5
 6    pg_version = args['version']
 7    pg_srcdir = os.path.join( os.getcwd(), "postgresql-%s" % pg_version )
 8
 9    # set up environment
10    os.environ['CC'] = get_config_var('CC')
11    os.environ['CFLAGS'] = get_config_var('CFLAGS')
12    os.environ['LDFLAGS'] = get_config_var('LDFLAGS')
13
14    if '-fPIC' not in os.environ['CFLAGS']:
15        os.environ['CFLAGS'] += ' -fPIC'
16
17    # run configure
18    run( "./configure --prefix=%s/postgres --disable-dependency-tracking --enable-static --disable-shared --without-readline --with-thread-safety" % os.getcwd(),
19        os.path.join( os.getcwd(), "postgresql-%s" % pg_version ),
20        "Configuring postgres (./configure)" )
21
22    # compile
23    run( "make ../../src/include/utils/fmgroids.h", os.path.join( pg_srcdir, 'src', 'backend' ), "Compiling fmgroids.h (cd src/backend; make ../../src/include/utils/fmgroids.h)" )
24    run( "make", os.path.join( pg_srcdir, 'src', 'interfaces', 'libpq' ), "Compiling libpq (cd src/interfaces/libpq; make)" )
25    run( "make", os.path.join( pg_srcdir, 'src', 'bin', 'pg_config' ), "Compiling pg_config (cd src/bin/pg_config; make)" )
26
27    # install
28    run( "make install", os.path.join( pg_srcdir, 'src', 'interfaces', 'libpq' ), "Compiling libpq (cd src/interfaces/libpq; make install)" )
29    run( "make install", os.path.join( pg_srcdir, 'src', 'bin', 'pg_config' ), "Compiling pg_config (cd src/bin/pg_config; make install)" )
30    run( "make install", os.path.join( pg_srcdir, 'src', 'include' ), "Compiling pg_config (cd src/include; make install)" )
31
32    # create prepped archive
33    print "%s(): Creating prepped archive for future builds at:" % sys._getframe().f_code.co_name
34    print " ", prepped
35    compress( prepped,
36           'postgres/bin',
37           'postgres/include',
38           'postgres/lib' )
39
40if __name__ == '__main__':
41
42    # change back to the build dir
43    if os.path.dirname( sys.argv[0] ) != "":
44        os.chdir( os.path.dirname( sys.argv[0] ) )
45
46    # find setuptools
47    sys.path.append( os.path.abspath( os.path.join( '..', '..', '..', 'lib' ) ) )
48    from scramble_lib import *
49
50    tag = get_tag()
51
52    pg_version = ( tag.split( "_" ) )[1]
53    pg_archive_base = os.path.join( archives, "postgresql-%s" % pg_version )
54    pg_archive = get_archive( pg_archive_base )
55    pg_archive_prepped = os.path.join( archives, "postgresql-%s-%s.tar.gz" % ( pg_version, platform_noucs ) )
56
57    # clean up any existing stuff (could happen if you run scramble.py by hand)
58    clean( [ 'postgresql-%s' % pg_version ] )
59
60    # unpack postgres
61    unpack_dep( pg_archive, pg_archive_prepped, prep_postgres, dict( version=pg_version ) )
62
63    # localize setup.cfg
64    if not os.path.exists( 'setup.cfg.orig' ):
65        shutil.copy( 'setup.cfg', 'setup.cfg.orig' )
66        f = open( 'setup.cfg', 'a' )
67        f.write( '\npg_config=postgres/bin/pg_config\n' )
68        f.write( '\nlibraries=crypt\n' )
69        f.close()
70
71    # tag
72    me = sys.argv[0]
73    sys.argv = [ me ]
74    if tag is not None:
75        sys.argv.append( "egg_info" )
76        sys.argv.append( "--tag-build=%s" %tag )
77    sys.argv.append( "bdist_egg" )
78
79    # go
80    execfile( "setup.py", globals(), locals() )