示例#1
0
    def templating(self):
        path = os.path.join(self.answers["project_name"],
                            self.answers["project_name"] + ".yml")
        with open(path, "w") as f:
            project_yaml = deepcopy(self.answers)
            project_yaml.pop("now")  # is not required
            dump_yaml(project_yaml, f)
        utils.color_print(
            f"\u2713 Your answers are saved in [info]{path}[/info]!")

        moban_file = utils.load_yaml(MOBAN_FILE_FOR_COOKIE_CUTTER)
        moban_file["configuration"]["configuration"] = (
            self.answers["project_name"] + ".yml")
        moban_file["targets"] = self.directives["moban"]

        if "://" in self.template_dir:
            moban_file["configuration"]["template_dir"][0] = (
                self.template_dir + "!/" + self.cookie_cutter_dir)
        else:
            moban_file["configuration"]["template_dir"][0] = (
                os.path.abspath(self.template_dir) + "/" +
                self.cookie_cutter_dir)
        moban_file_path = os.path.join(self.answers["project_name"],
                                       ".moban.yml")
        with open(moban_file_path, "w") as f:
            dump_yaml(moban_file, f)
        utils.color_print(f"\u2713 [info]{moban_file_path}[/info]! l" +
                          "inks your project with the template.")
示例#2
0
 def inflate_all_by_moban(self):
     current = os.getcwd()
     project_name = self.answers["project_name"]
     os.chdir(project_name)
     cmd = "moban"
     _run_command(cmd)
     os.chdir(current)
     utils.color_print(
         f"\u2713 Files are generated under [info]{project_name}[/info]")
示例#3
0
 def initialize_git_and_add_all(self, project_files):
     project_name = self.answers["project_name"]
     current = os.getcwd()
     os.chdir(project_name)
     cmd = "git init"
     _run_command(cmd)
     for file_name in project_files:
         _run_command(f"git add {file_name}")
     os.chdir(current)
     utils.color_print(
         f"\u2713 Git repo initialized under [info]{project_name}[/info]" +
         " and is ready to commit")
示例#4
0
 def _ask_questions(self):
     content = read_unicode(self.project_file)
     first_stage = utils.load_yaml(content)
     utils.color_print(first_stage["introduction"])
     base_path = fs.path.dirname(self.project_file)
     with fs.open_fs(base_path) as the_fs:
         self.template_dir = os.path.join(
             the_fs._root_path,
             first_stage["configuration"]["template_path"],
         )
         self.static_dir = os.path.join(
             the_fs._root_path, first_stage["configuration"]["static_path"])
     self.answers = get_user_inputs(first_stage["questions"])
示例#5
0
    def _ask_questions(self):
        first_stage = utils.load_yaml(self.project_content)
        utils.color_print(first_stage["introduction"])
        self.answers = get_user_inputs(first_stage["questions"])

        my_dict = {"cookiecutter": deepcopy(self.answers)}
        my_dict["project_name"] = self.cookie_cutter_dir

        tmp_env = Environment(keep_trailing_newline=True,
                              trim_blocks=True,
                              lstrip_blocks=True)

        template = tmp_env.from_string(my_dict["project_name"])

        renderred_content = template.render(**my_dict)
        my_dict["project_name"] = renderred_content
        self.answers = my_dict
示例#6
0
 def end(self):
     utils.color_print("All done!! project [info]%s[/info] is created." %
                       self.project_name)
     utils.color_print(
         "In the future, " +
         "run [info]moban[/info] to synchronize with the project template")