#NEWLINE# def create( self , template ) : #NEWLINE# #INDENT# if os . path . exists ( self . name ) : #NEWLINE# #INDENT# raise ProjectException ( "The specified name '{name}' already exists" . format ( name = self . name ) ) #NEWLINE# #UNINDENT# if ( not template . validated ) : #NEWLINE# #INDENT# template . validate ( ) #NEWLINE# #UNINDENT# self . log . info ( ( "Creating a new project named '{name}' " + "using '{template}' as the template..." ) . format ( name = self . name , template = template . name ) ) #NEWLINE# template . copy_to ( self . name ) #NEWLINE# render_context = { #NEWLINE# #INDENT# 'name' : self . name , #NEWLINE# 'project' : self , #NEWLINE# 'template' : template , #NEWLINE# #UNINDENT# } #NEWLINE# jinja = JinjaInterface ( globals = render_context , file_loader_paths = [ os . path . abspath ( self . name ) ] ) #NEWLINE# def path( * parts ) : #NEWLINE# #INDENT# return os . path . abspath ( os . path . join ( self . name , * parts ) ) #NEWLINE# #UNINDENT# def render_in_place( * parts ) : #NEWLINE# #INDENT# source = path ( * parts ) #NEWLINE# data = unicode ( open ( source ) . read ( ) , 'utf8' ) #NEWLINE# with open ( source , 'w' ) as f : #NEWLINE# #INDENT# f . write ( jinja . render_string ( data ) ) #NEWLINE# #UNINDENT# #UNINDENT# self . log . debug ( 'Loading template metadata...' ) #NEWLINE# metadata = yaml . load ( jinja . render_file ( 'stackstrap.yml' ) ) #NEWLINE# self . log . debug ( 'Processing cleanup...' ) #NEWLINE# cleanup_paths = metadata . get ( 'cleanup' , [ ] ) #NEWLINE# for p in cleanup_paths : #NEWLINE# #INDENT# self . log . debug ( p ) #NEWLINE# cleanup_path = path ( p ) #NEWLINE# if os . path . isdir ( cleanup_path ) : #NEWLINE# #INDENT# shutil . rmtree ( cleanup_path ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if os . path . exists ( cleanup_path ) : #NEWLINE# #INDENT# os . remove ( cleanup_path ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . log . error ( ( 'Unable to cleanup: %s' % cleanup_path ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# self . log . debug ( 'Processing file templates...' ) #NEWLINE# file_template_paths = metadata . get ( 'file_templates' , [ ] ) #NEWLINE# for p in file_template_paths : #NEWLINE# #INDENT# self . log . debug ( p ) #NEWLINE# render_in_place ( p ) #NEWLINE# #UNINDENT# self . log . debug ( 'Processing path templates...' ) #NEWLINE# path_templates = metadata . get ( 'path_templates' , [ ] ) #NEWLINE# for path_template in path_templates : #NEWLINE# #INDENT# for orig_path in path_template : #NEWLINE# #INDENT# self . log . debug ( ( '%s -> %s' % ( orig_path , path_template [ orig_path ] ) ) ) #NEWLINE# os . rename ( path ( orig_path ) , path ( path_template [ orig_path ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# self . log . info ( 'Done! The project {name} has been created' . format ( name = self . name ) )