コード例 #1
0
 def create_initial_structure(self):
     if not os.path.exists(self.project_name):
         os.mkdir(self.project_name)
         report_info("[Create] ./{}/\n".format(self.project_name))
     else:
         error = "Ops! Directory already exists\n"
         error_description = "We cannot create {} structure.\n"
         report_error(error + error_description.format(self.project_name))
         sys.exit(1)
コード例 #2
0
    def create_template_config(self):
        template_config_dir = '{}/template_config'.format(self.theme)
        template_file = os.path.join(TEMPLATES_DIR, template_config_dir)
        template = self.get_template(template_file)
        rendered = template.render({'project_name': self.project_name,
                                    'template_vars': self.variables})

        with open(os.path.join(self.project_name, 'config.yml'), "w") as f:
            f.write(rendered)
            report_info("[Create] ./{}/config.yml\n".format(self.project_name))
コード例 #3
0
    def create_templates(self, structure, config):
        project_dir = "./"
        template_dir = os.path.join(TEMPLATES_DIR, self.theme)
        for directory in structure:
            if directory == "root":
                project_template_dir = project_dir
            else:
                project_template_dir = os.path.join(project_dir, directory)

            templates = structure.get(directory)
            templates = [] if templates is None else templates

            for file in templates:
                file_dir = os.path.join(project_template_dir, file)
                template = self.get_template(os.path.join(template_dir, file))
                rendered = template.render(config)

                with codecs.open(file_dir, "w", encoding='utf-8') as f:
                    f.write(rendered)
                    report_info("[Create] {}\n".format(file_dir))
コード例 #4
0
 def create_directory_structure(self):
     for directory in self.structure:
         if directory != "root":
             os.mkdir(os.path.join(self.project_name, directory))
             report_info("[Create] ./{}/{}\n".format(self.project_name,
                                                     directory))