#NEWLINE# def install_source( resolved ) : #NEWLINE# #INDENT# import shutil #NEWLINE# import tarfile #NEWLINE# import tempfile #NEWLINE# tempdir = tempfile . mkdtemp ( ) #NEWLINE# rd_debug ( ( 'created tmpdir [%s]' % tempdir ) ) #NEWLINE# rd_debug ( ( 'Fetching tarball %s' % resolved . tarball ) ) #NEWLINE# filename = os . path . join ( tempdir , os . path . basename ( resolved . tarball ) ) #NEWLINE# f = urlretrieve ( resolved . tarball , filename ) #NEWLINE# assert ( f [ 0 ] == filename ) #NEWLINE# if resolved . tarball_md5sum : #NEWLINE# #INDENT# rd_debug ( 'checking md5sum on tarball' ) #NEWLINE# hash1 = get_file_hash ( filename ) #NEWLINE# if ( resolved . tarball_md5sum != hash1 ) : #NEWLINE# #INDENT# if resolved . alternate_tarball : #NEWLINE# #INDENT# f = urlretrieve ( resolved . alternate_tarball ) #NEWLINE# filename = f [ 0 ] #NEWLINE# hash2 = get_file_hash ( filename ) #NEWLINE# if ( resolved . tarball_md5sum != hash2 ) : #NEWLINE# #INDENT# failure = ( SOURCE_INSTALLER , ( 'md5sum check on %s and %s failed.  Expected %s got %s and %s' % ( resolved . tarball , resolved . alternate_tarball , resolved . tarball_md5sum , hash1 , hash2 ) ) ) #NEWLINE# raise InstallFailed ( failure = failure ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise InstallFailed ( ( SOURCE_INSTALLER , ( 'md5sum check on %s failed.  Expected %s got %s ' % ( resolved . tarball , resolved . tarball_md5sum , hash1 ) ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# rd_debug ( 'No md5sum defined for tarball, not checking.' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# if ( not filename . endswith ( '.dmg' ) ) : #NEWLINE# #INDENT# rd_debug ( 'Extracting tarball' ) #NEWLINE# tarf = tarfile . open ( filename ) #NEWLINE# tarf . extractall ( tempdir ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# rd_debug ( 'Bypassing tarball extraction as it is a dmg' ) #NEWLINE# #UNINDENT# rd_debug ( 'Running installation script' ) #NEWLINE# success = create_tempfile_from_string_and_execute ( resolved . install_command , os . path . join ( tempdir , resolved . exec_path ) ) #NEWLINE# if success : #NEWLINE# #INDENT# rd_debug ( 'successfully executed script' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise InstallFailed ( ( SOURCE_INSTALLER , 'installation script returned with error code' ) ) #NEWLINE# #UNINDENT# #UNINDENT# finally : #NEWLINE# #INDENT# rd_debug ( ( 'cleaning up tmpdir [%s]' % tempdir ) ) #NEWLINE# shutil . rmtree ( tempdir )