#NEWLINE# def _make_tarball( base_name , base_dir , compress = 'gzip' , verbose = 0 , dry_run = 0 , owner = None , group = None , logger = None ) : #NEWLINE# #INDENT# 'Create a (possibly compressed) tar file from all the files under\n    \'base_dir\'.\n\n    \'compress\' must be "gzip" (the default), "bzip2", or None.\n\n    \'owner\' and \'group\' can be used to define an owner and a group for the\n    archive that is being built. If not provided, the current owner and group\n    will be used.\n\n    The output tar file will be named \'base_name\' +  ".tar", possibly plus\n    the appropriate compression extension (".gz", or ".bz2").\n\n    Returns the output filename.\n    ' #NEWLINE# tar_compression = { #NEWLINE# #INDENT# 'gzip' : 'gz' , #NEWLINE# None : '' , #NEWLINE# #UNINDENT# } #NEWLINE# compress_ext = { #NEWLINE# #INDENT# 'gzip' : '.gz' , #NEWLINE# #UNINDENT# } #NEWLINE# if _BZ2_SUPPORTED : #NEWLINE# #INDENT# tar_compression [ 'bzip2' ] = 'bz2' #NEWLINE# compress_ext [ 'bzip2' ] = '.bz2' #NEWLINE# #UNINDENT# if ( ( compress is not None ) and ( compress not in compress_ext ) ) : #NEWLINE# #INDENT# raise ValueError ( "bad value for 'compress', or compression format not supported : {0}" . format ( compress ) ) #NEWLINE# #UNINDENT# archive_name = ( ( base_name + '.tar' ) + compress_ext . get ( compress , '' ) ) #NEWLINE# archive_dir = os . path . dirname ( archive_name ) #NEWLINE# if ( not os . path . exists ( archive_dir ) ) : #NEWLINE# #INDENT# if ( logger is not None ) : #NEWLINE# #INDENT# logger . info ( 'creating %s' , archive_dir ) #NEWLINE# #UNINDENT# if ( not dry_run ) : #NEWLINE# #INDENT# os . makedirs ( archive_dir ) #NEWLINE# #UNINDENT# #UNINDENT# if ( logger is not None ) : #NEWLINE# #INDENT# logger . info ( 'Creating tar archive' ) #NEWLINE# #UNINDENT# uid = _get_uid ( owner ) #NEWLINE# gid = _get_gid ( group ) #NEWLINE# def _set_uid_gid( tarinfo ) : #NEWLINE# #INDENT# if ( gid is not None ) : #NEWLINE# #INDENT# tarinfo . gid = gid #NEWLINE# tarinfo . gname = group #NEWLINE# #UNINDENT# if ( uid is not None ) : #NEWLINE# #INDENT# tarinfo . uid = uid #NEWLINE# tarinfo . uname = owner #NEWLINE# #UNINDENT# return tarinfo #NEWLINE# #UNINDENT# if ( not dry_run ) : #NEWLINE# #INDENT# tar = tarfile . open ( archive_name , ( 'w|%s' % tar_compression [ compress ] ) ) #NEWLINE# try : #NEWLINE# #INDENT# tar . add ( base_dir , filter = _set_uid_gid ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# tar . close ( ) #NEWLINE# #UNINDENT# #UNINDENT# return archive_name