(src, dest, replace=None)
Copy a source file to a new destination file.
    
    To replace boilerplate strings in the source data, pass a dictionary to the
    ``replace`` argument where each key is the boilerplate string and the
    corresponding value is the string which should replace it.
Copy a source file to a new destination file.
    
    To replace boilerplate strings in the source data, pass a dictionary to the
    ``replace`` argument where each key is the boilerplate string and the
    corresponding value is the string which should replace it.
Copy a source file to a new destination file . To replace boilerplate strings in the source data pass a dictionary to the replace argument where each key is the boilerplate string and the corresponding value is the string which should replace it .
def copy_template_file(src, dest, replace=None):
    """
    Copy a source file to a new destination file.
    
    To replace boilerplate strings in the source data, pass a dictionary to the
    ``replace`` argument where each key is the boilerplate string and the
    corresponding value is the string which should replace it.
    
    """
    replace = replace or {}
    # Read the data from the source file.
    src_file = open(src, 'r')
    data = src_file.read()
    src_file.close()
    # Replace boilerplate strings.
    for old_val, new_val in replace.items():
        data = data.replace(old_val, new_val)

    # Generate SECRET_KEY for settings file
    secret_key = ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)])
    data = re.sub(r"(?<=SECRET_KEY = ')'", secret_key + "'", data)

    # Write the data to the destination file.
    dest_file = open(dest, 'w')
    dest_file.write(data)
    dest_file.close()
    # Copy permissions from source file.
    shutil.copymode(src, dest)
    # Make new file writable.
    if os.access(dest, os.W_OK):
        st = os.stat(dest)
        new_permissions = stat.S_IMODE(st.st_mode) | stat.S_IWUSR
        os.chmod(dest, new_permissions)
def copy_template_file ( src , dest , replace = None ) : replace = replace or { } # Read the data from the source file. src_file = open ( src , 'r' ) data = src_file . read ( ) src_file . close ( ) # Replace boilerplate strings. for old_val , new_val in replace . items ( ) : data = data . replace ( old_val , new_val ) # Generate SECRET_KEY for settings file secret_key = '' . join ( [ choice ( 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)' ) for i in range ( 50 ) ] ) data = re . sub ( r"(?<=SECRET_KEY = ')'" , secret_key + "'" , data ) # Write the data to the destination file. dest_file = open ( dest , 'w' ) dest_file . write ( data ) dest_file . close ( ) # Copy permissions from source file. shutil . copymode ( src , dest ) # Make new file writable. if os . access ( dest , os . W_OK ) : st = os . stat ( dest ) new_permissions = stat . S_IMODE ( st . st_mode ) | stat . S_IWUSR os . chmod ( dest , new_permissions )