#NEWLINE# def copy_template( template_name , copy_to , **options ) : #NEWLINE# #INDENT# 'copies the specified template directory to the copy_to location' #NEWLINE# import django_extensions #NEWLINE# style = color_style ( ) #NEWLINE# ERROR = getattr ( style , 'ERROR' , ( lambda x : x ) ) #NEWLINE# SUCCESS = getattr ( style , 'SUCCESS' , ( lambda x : x ) ) #NEWLINE# template_dir = os . path . join ( django_extensions . __path__ [ 0 ] , 'conf' , template_name ) #NEWLINE# for ( d , subdirs , files ) in os . walk ( template_dir ) : #NEWLINE# #INDENT# relative_dir = d [ ( len ( template_dir ) + 1 ) : ] #NEWLINE# if ( relative_dir and ( not os . path . exists ( os . path . join ( copy_to , relative_dir ) ) ) ) : #NEWLINE# #INDENT# os . mkdir ( os . path . join ( copy_to , relative_dir ) ) #NEWLINE# #UNINDENT# for ( i , subdir ) in enumerate ( subdirs ) : #NEWLINE# #INDENT# if subdir . startswith ( '.' ) : #NEWLINE# #INDENT# del subdirs [ i ] #NEWLINE# #UNINDENT# #UNINDENT# 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 ( copy_to , relative_dir , f ) . rstrip ( '.tmpl' ) #NEWLINE# if os . path . exists ( path_new ) : #NEWLINE# #INDENT# if ( options . get ( 'verbosity' , 1 ) > 1 ) : #NEWLINE# #INDENT# print ( ERROR ( ( '%s already exists' % path_new ) ) ) #NEWLINE# #UNINDENT# continue #NEWLINE# #UNINDENT# if ( options . get ( 'verbosity' , 1 ) > 1 ) : #NEWLINE# #INDENT# print ( SUCCESS ( ( '%s' % path_new ) ) ) #NEWLINE# #UNINDENT# with open ( path_old , 'r' ) as fp_orig : #NEWLINE# #INDENT# with open ( path_new , 'w' ) as fp_new : #NEWLINE# #INDENT# fp_new . write ( fp_orig . read ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# 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 ) )