def make_file(src_name, render_tmpl, fullpath, final_path): """If src_name is a template, render it and place it at final_path, otherwise just copy the file to the final_path. """ if src_name.endswith('.tmpl'): content = render_tmpl(fullpath) create_file(final_path, content) else: copy_file(fullpath, final_path)
def render_file(dst_path, rel_folder, folder, src_name, dst_name, render_tmpl, pretend=False, force=False, skip=False, quiet=False): """Process or copy a file of the skeleton. """ fullpath = os.path.join(folder, src_name) created_path = os.path.join(rel_folder, dst_name).lstrip('.').lstrip('/') if pretend: final_path = os.path.join(dst_path, rel_folder, dst_name) else: final_path = make_dirs(dst_path, rel_folder, dst_name) if not os.path.exists(final_path): if not quiet: print_format('create', created_path, color=COLOR_OK) if not pretend: make_file(src_name, render_tmpl, fullpath, final_path) return # A file with this name already exists content = None if src_name.endswith('.tmpl'): content = render_tmpl(fullpath) identical = file_has_this_content(final_path, content) else: identical = files_are_identical(fullpath, final_path) # The existing file is identical. if identical: if not quiet: print_format('identical', created_path, color=COLOR_IGNORE, bright=None) return # The existing file is different. if not quiet: print_format('conflict', created_path, color=COLOR_DANGER) if force: overwrite = True elif skip: overwrite = False else: msg = ' Overwrite %s? (y/n)' % final_path overwrite = prompt_bool(msg, default=True) if not quiet: print_format('force' if overwrite else 'skip', created_path, color=COLOR_WARNING) if overwrite and not pretend: if content is None: copy_file(fullpath, final_path) else: create_file(final_path, content)