#NEWLINE# def copy_template_file( src , dest , replace = None ) : #NEWLINE# #INDENT# '\n    Copy a source file to a new destination file.\n    \n    To replace boilerplate strings in the source data, pass a dictionary to the\n    ``replace`` argument where each key is the boilerplate string and the\n    corresponding value is the string which should replace it.\n    \n    ' #NEWLINE# replace = ( replace or { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# src_file = open ( src , 'r' ) #NEWLINE# data = src_file . read ( ) #NEWLINE# src_file . close ( ) #NEWLINE# for ( old_val , new_val ) in replace . items ( ) : #NEWLINE# #INDENT# data = data . replace ( old_val , new_val ) #NEWLINE# #UNINDENT# secret_key = '' . join ( [ choice ( 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' ) for i in range ( 50 ) ] ) #NEWLINE# data = re . sub ( "(?<=SECRET_KEY = ')'" , ( secret_key + "'" ) , data ) #NEWLINE# dest_file = open ( dest , 'w' ) #NEWLINE# dest_file . write ( data ) #NEWLINE# dest_file . close ( ) #NEWLINE# shutil . copymode ( dest , dest ) #NEWLINE# if os . access ( dest , os . W_OK ) : #NEWLINE# #INDENT# st = os . stat ( dest ) #NEWLINE# new_permissions = ( stat . S_IMODE ( st . st_mode ) | stat . S_IWUSR ) #NEWLINE# os . chmod ( dest , new_permissions )