#NEWLINE# def pack_turret( turret , temp_files , base_config_path , path = None ) : #NEWLINE# #INDENT# 'pack a turret into a tar file based on the turret configuration\n\n    :param dict turret_config: the turret configuration to pack\n    :param str tmp_config_file: the path of the temp config file\n    :param str base_config_path: the base directory of the main configuration file\n    ' #NEWLINE# file_name = turret [ 'name' ] #NEWLINE# files = temp_files [ : ] #NEWLINE# for fname in turret . get ( 'extra_files' , [ ] ) : #NEWLINE# #INDENT# if ( os . path . isabs ( fname ) or ( path is None ) ) : #NEWLINE# #INDENT# files . append ( fname ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# files . append ( os . path . join ( path , fname ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( path is not None ) : #NEWLINE# #INDENT# file_name = os . path . join ( path , file_name ) #NEWLINE# #UNINDENT# tar_file = tarfile . open ( ( file_name + '.tar.gz' ) , 'w:gz' ) #NEWLINE# for f in files : #NEWLINE# #INDENT# tar_file . add ( os . path . abspath ( f ) , arcname = os . path . basename ( f ) ) #NEWLINE# #UNINDENT# script_path = os . path . join ( os . path . abspath ( base_config_path ) , turret [ 'script' ] ) #NEWLINE# tar_file . add ( script_path , arcname = turret [ 'script' ] ) #NEWLINE# for f in tar_file . getnames ( ) : #NEWLINE# #INDENT# print ( ( 'Added %s' % f ) ) #NEWLINE# #UNINDENT# tar_file . close ( ) #NEWLINE# print ( ( 'Archive %s created' % tar_file . name ) ) #NEWLINE# print ( '=========================================' )