#NEWLINE# def copy_template( app_template , copy_to , project_name , app_name ) : #NEWLINE# #INDENT# 'copies the specified template directory to the copy_to location' #NEWLINE# import shutil #NEWLINE# copy_migrations = ( True if ( VERSION [ : 2 ] >= ( 1 , 7 ) ) else False ) #NEWLINE# app_template = os . path . normpath ( app_template ) #NEWLINE# for ( d , subdirs , files ) in os . walk ( app_template ) : #NEWLINE# #INDENT# relative_dir = d [ ( len ( app_template ) + 1 ) : ] #NEWLINE# d_new = os . path . join ( copy_to , relative_dir ) . replace ( 'app_name' , app_name ) #NEWLINE# if ( relative_dir and ( not os . path . exists ( d_new ) ) ) : #NEWLINE# #INDENT# os . mkdir ( d_new ) #NEWLINE# #UNINDENT# for ( i , subdir ) in enumerate ( subdirs ) : #NEWLINE# #INDENT# if subdir . startswith ( '.' ) : #NEWLINE# #INDENT# del subdirs [ replacements ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( subdir . startswith ( 'migrations' ) and ( not copy_migrations ) ) : #NEWLINE# #INDENT# del subdirs [ i ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# replacements = { #NEWLINE# #INDENT# 'app_name' : app_name , #NEWLINE# 'project_name' : project_name , #NEWLINE# #UNINDENT# } #NEWLINE# replacements . update ( REPLACEMENTS ) #NEWLINE# for f in files : #NEWLINE# #INDENT# if ( f . endswith ( '.pyc' ) or f . startswith ( '.DS_Store' ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# path_old = os . path . join ( d , f ) #NEWLINE# path_new = os . path . join ( d_new , f . replace ( 'app_name' , app_name ) ) #NEWLINE# if os . path . exists ( path_new ) : #NEWLINE# #INDENT# path_new = os . path . join ( d_new , f ) #NEWLINE# if os . path . exists ( path_new ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# if path_new . endswith ( '.tmpl' ) : #NEWLINE# #INDENT# path_new = path_new [ : ( - 5 ) ] #NEWLINE# #UNINDENT# fp_old = open ( path_old , 'r' ) #NEWLINE# fp_new = open ( path_new , 'w' ) #NEWLINE# fp_new . write ( Template ( fp_old . read ( ) ) . render ( Context ( replacements ) ) ) #NEWLINE# fp_old . close ( ) #NEWLINE# fp_new . close ( ) #NEWLINE# try : #NEWLINE# #INDENT# shutil . copymode ( path_old , path_new ) #NEWLINE# _make_writeable ( path_new ) #NEWLINE# #UNINDENT# except OSError : #NEWLINE# #INDENT# sys . stderr . write ( ( "Notice: Couldn't set permission bits on %s. You're probably using an uncommon filesystem setup. No problem.\n" % path_new ) )