#NEWLINE# def import_upstream( tarball_path , patches_path , version , name , replace ) : #NEWLINE# #INDENT# url = urlparse ( tarball_path ) #NEWLINE# if url . scheme : #NEWLINE# #INDENT# tmp_dir = tempfile . mkdtemp ( ) #NEWLINE# try : #NEWLINE# #INDENT# info ( "Fetching file from url: '{0}'" . format ( tarball_path ) ) #NEWLINE# req = load_url_to_file_handle ( tarball_path ) #NEWLINE# tarball_path = os . path . join ( tmp_dir , os . path . basename ( url . path ) ) #NEWLINE# with open ( tarball_path , 'wb' ) as f : #NEWLINE# #INDENT# chunk_size = ( 16 * 1024 ) #NEWLINE# while True : #NEWLINE# #INDENT# chunk = req . read ( chunk_size ) #NEWLINE# if ( not chunk ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# f . write ( chunk ) #NEWLINE# #UNINDENT# #UNINDENT# return import_upstream ( tarball_path , patches_path , version , name , replace ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# shutil . rmtree ( tmp_dir ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not os . path . exists ( tarball_path ) ) : #NEWLINE# #INDENT# error ( "Specified archive does not exists: '{0}'" . format ( tarball_path ) , exit = True ) #NEWLINE# #UNINDENT# if ( ( not version ) or ( not name ) ) : #NEWLINE# #INDENT# tarball_file = os . path . basename ( tarball_path ) #NEWLINE# ending = None #NEWLINE# if tarball_file . endswith ( '.tar.gz' ) : #NEWLINE# #INDENT# ending = '.tar.gz' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if tarball_file . endswith ( '.zip' ) : #NEWLINE# #INDENT# ending = '.zip' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# error ( "Cannot detect type of archive: '{0}'" . format ( tarball_file ) , exit = True ) #NEWLINE# #UNINDENT# #UNINDENT# tarball_file = tarball_file [ : ( - len ( ending ) ) ] #NEWLINE# split_tarball_file = tarball_file . split ( '-' ) #NEWLINE# if ( ( ( len ( split_tarball_file ) < 2 ) and ( not version ) ) or ( len ( split_tarball_file ) < 1 ) ) : #NEWLINE# #INDENT# error ( "Cannot detect name and/or version from archive: '{0}'" . format ( tarball_file ) , exit = True ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( not name ) and ( len ( split_tarball_file ) == 1 ) ) : #NEWLINE# #INDENT# name = split_tarball_file [ 0 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( not name ) and ( len ( split_tarball_file ) == 1 ) ) : #NEWLINE# #INDENT# name = '-' . join ( split_tarball_file [ : ( - 1 ) ] ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( not version ) and ( len ( split_tarball_file ) < 2 ) ) : #NEWLINE# #INDENT# error ( ( "Cannot detect version from archive: '{0}'" . format ( tarball_file ) + ' and the version was not spcified.' ) , exit = True ) #NEWLINE# #UNINDENT# version = ( version if version else split_tarball_file [ ( - 1 ) ] ) #NEWLINE# patches_path_dict = None #NEWLINE# if patches_path : #NEWLINE# #INDENT# patches_path_dict = ls_tree ( BLOOM_CONFIG_BRANCH , patches_path ) #NEWLINE# if ( not patches_path_dict ) : #NEWLINE# #INDENT# error ( "Given patches path '{0}' does not exist in bloom branch." . format ( patches_path ) , exit = True ) #NEWLINE# #UNINDENT# #UNINDENT# version_check ( version ) #NEWLINE# upstream_tag = 'upstream/{0}' . format ( version ) #NEWLINE# if tag_exists ( upstream_tag ) : #NEWLINE# #INDENT# if ( not replace ) : #NEWLINE# #INDENT# error ( "Tag '{0}' already exists, use --replace to override it." . format ( upstream_tag ) , exit = True ) #NEWLINE# #UNINDENT# warning ( "Removing tag: '{0}'" . format ( upstream_tag ) ) #NEWLINE# delete_tag ( upstream_tag ) #NEWLINE# if ( not get_git_clone_state ( ) ) : #NEWLINE# #INDENT# delete_remote_tag ( upstream_tag ) #NEWLINE# #UNINDENT# #UNINDENT# name_tag = '{0}/{1}' . format ( ( name or 'upstream' ) , version ) #NEWLINE# if ( ( name_tag != upstream_tag ) and tag_exists ( name_tag ) ) : #NEWLINE# #INDENT# if ( not replace ) : #NEWLINE# #INDENT# error ( "Tag '{0}' already exists, use --replace to override it." . format ( name_tag ) , exit = True ) #NEWLINE# #UNINDENT# warning ( "Removing tag: '{0}'" . format ( name_tag ) ) #NEWLINE# delete_tag ( name_tag ) #NEWLINE# if ( not get_git_clone_state ( ) ) : #NEWLINE# #INDENT# delete_remote_tag ( name_tag ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not branch_exists ( 'upstream' ) ) : #NEWLINE# #INDENT# info ( 'Creating upstream branch.' ) #NEWLINE# create_branch ( 'upstream' , orphaned = True ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# track_branches ( [ 'upstream' ] ) #NEWLINE# #UNINDENT# info ( 'Importing archive into upstream branch...' ) #NEWLINE# import_tarball ( tarball_path , 'upstream' , version , name ) #NEWLINE# if patches_path : #NEWLINE# #INDENT# import_patches ( patches_path , patches_path_dict , 'upstream' , version ) #NEWLINE# #UNINDENT# with inbranch ( 'upstream' ) : #NEWLINE# #INDENT# ( _ , actual_version , _ ) = get_package_data ( 'upstream' ) #NEWLINE# if ( actual_version != version ) : #NEWLINE# #INDENT# error ( "The package(s) in upstream are version '{0}', but the version to be released is '{1}', aborting." . format ( actual_version , version ) , exit = True ) #NEWLINE# #UNINDENT# info ( "Creating tag: '{0}'" . format ( upstream_tag ) ) #NEWLINE# create_tag ( upstream_tag ) #NEWLINE# if ( name_tag != upstream_tag ) : #NEWLINE# #INDENT# info ( "Creating tag: '{0}'" . format ( name_tag ) ) #NEWLINE# create_tag ( name_tag )