PageRenderTime 25ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

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

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