3 =\>@s~ddlZddlZddlmZddlmZddlmZdZdZddZ d d Z ed d Z ej Z Gd ddZGdddZdS)N) namedtuple)Template)pathZproject_templatesz.jinjacCs|tj|S)N)ossep)rootresourcer r/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/taskcat/taskcat/project_generator.py full_path sr csfdd|DS)Ncs$g|]}|jtrtj|qSr )endswithTEMPLATE_FILE_EXTENSIONrr).0t) template_dirr r sz"template_paths..r )rZ templatesr )rr template_pathss rProjectConfigurationz:owner_email, project_name, project_type, supported_regionsc@sTeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ dS)ProjectGeneratorcCs@tjdtjdj|tjdj|||_||_||_dS)NzInitializing with...zProject configuration: {}zProject destination: {})loggerinfoformatconfig destination filesystem)selfrZdestination_directoryZfilesystem_servicer r r __init__ s  zProjectGenerator.__init__cCsDx>|jD]2\}}}|j|}|j|t||}|j|q WdS)N)_traverse_templates_full_destination_path_make_project_directoryr_generate_project_files)r directory_files project_pathtemplate_filepathsr r r generate(s    zProjectGenerator.generatecCs|jj|jjS)N)rtraverse_templatesr project_type)rr r r r0sz$ProjectGenerator._traverse_templatescCs(|jj|jj}|j|d}t|j|S)N)rproject_templates_rootrr(replacer r)rdestination_pathZtemplates_rootr r r r3s  z'ProjectGenerator._full_destination_pathcCsXy tjdj||jj|Wn2tk rR}ztjdj|WYdd}~XnXdS)Nz creating {}z{} - skipping...)rrrrcreate_project_directoryFileExistsErrorloggingwarning)rZproject_directoryer r r r:s z(ProjectGenerator._make_project_directorycCsVtjdxF|D]>}|jj|}|j|}|jj|j||tjdj|qWdS)Nzgenerating files...z generated {})rrr load_template_destination_filepath generate_file_render_template_contentr)rr%filepathtemplateZdestination_filepathr r r r As    z(ProjectGenerator._generate_project_filescCs|j|}|j|S)N)r_remove_template_extension)rr6rr r r r3Ls z&ProjectGenerator._destination_filepathcCstjj|dS)Nr)rrsplitext)rfilenamer r r r8Psz+ProjectGenerator._remove_template_extensioncCs|j|jdS)N)r)renderr)rr7r r r r5Ssz)ProjectGenerator._render_template_contentN) __name__ __module__ __qualname__rr&rrrr r3r8r5r r r r rs rc@s<eZdZddZddZddZddZd d Zd d Zd S)FilesystemServicecCs|jtj|tj}|S)N)_templates_root_pathrr)rr(rr r r r*Xsz(FilesystemService.project_templates_rootcCstj|j|S)zq A wrapper around os.walk that returns the generator to traverse the templates directory )rwalkr*)rr(r r r r'\sz$FilesystemService.traverse_templatescCstj|dS)N)rmkdir)rr$r r r r-csz*FilesystemService.create_project_directoryc Cs$t|d}|j|WdQRXdS)z Given the generated content and a destination path, it will write that content to a file in that path. wN)openwrite)rcontentr,fr r r r4fs zFilesystemService.generate_filec Cs t|}t|jSQRXdS)z Give a full path to a template file it will return a jinja2 Template object that responds to `render` method taking the template parameters N)rDrread)rZ template_pathrGr r r r2ns zFilesystemService.load_templatecCstjtjttjtS)N)rdirnamerealpath__file__rrTEMPLATES_ROOT_DIR)rr r r r@wsz&FilesystemService._templates_root_pathN) r<r=r>r*r'r-r4r2r@r r r r r?Ws  r?)r/r collectionsrZjinja2rrrLr r rr getLoggerrrr?r r r r s   8