#NEWLINE# def __place_template_folder( group , src , dst , gbp = False ) : #NEWLINE# #INDENT# template_files = pkg_resources . resource_listdir ( group , src ) #NEWLINE# for template_file in template_files : #NEWLINE# #INDENT# if ( ( not gbp ) and ( os . path . basename ( template_file ) == 'gbp.conf.em' ) ) : #NEWLINE# #INDENT# debug ( "Skipping template '{0}'" . format ( template_file ) ) #NEWLINE# continue #NEWLINE# #UNINDENT# template_path = os . path . join ( src , template_file ) #NEWLINE# template_dst = os . path . join ( dst , template_file ) #NEWLINE# if pkg_resources . resource_isdir ( group , template_path ) : #NEWLINE# #INDENT# debug ( "Recursing on folder '{0}'" . format ( template_path ) ) #NEWLINE# __place_template_folder ( group , template_path , template_dst , gbp ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# debug ( "Placing template '{0}'" . format ( template_path ) ) #NEWLINE# template = pkg_resources . resource_string ( group , template_path ) #NEWLINE# template_abs_path = pkg_resources . resource_filename ( group , template_path ) #NEWLINE# #UNINDENT# except IOError as err : #NEWLINE# #INDENT# error ( "Failed to load template '{0}': {1}" . format ( template_file , str ( err ) ) , exit = True ) #NEWLINE# #UNINDENT# if ( not os . path . exists ( dst ) ) : #NEWLINE# #INDENT# os . makedirs ( dst ) #NEWLINE# #UNINDENT# if os . path . exists ( template_dst ) : #NEWLINE# #INDENT# debug ( "Removing existing file '{0}'" . format ( template_dst ) ) #NEWLINE# os . remove ( template_dst ) #NEWLINE# #UNINDENT# with open ( template_dst , 'w' ) as f : #NEWLINE# #INDENT# if ( not isinstance ( template , str ) ) : #NEWLINE# #INDENT# template = template . decode ( 'utf-8' ) #NEWLINE# #UNINDENT# f . write ( template ) #NEWLINE# #UNINDENT# shutil . copystat ( template_file , template_dst )