def To(self):
        categolies, tpl_var_dict = Command().Analize(self.__commands)
        path_tpl = self.__cmdfile.TemplateDir / self.__CommandToTemplatePath(categolies)
        path_target = PathIni()['work_flow_pj'] / ProjectName().Generate(self.__commands)
        shutil.copytree(path_tpl, path_target)
        if (path_target / '__TEMPLATE__').is_file(): os.remove(path_target / '__TEMPLATE__')
        if (path_target / '__DEFAULT__').is_file(): os.remove(path_target / '__DEFAULT__')

        if 'filename' in tpl_var_dict: filename = tpl_var_dict['filename']
        elif '_1' in tpl_var_dict: filename = tpl_var_dict['_1']
        elif '_0' in tpl_var_dict: filename = tpl_var_dict['_0']
        else: filename = '{{filename}}'
        
        # パス名 {{filename}}置換
        for p in path_target.glob('**/*{{filename}}*'):
            fn = p.name.replace('{{filename}}', filename)
            p.rename(p.parent / fn)

        for p in path_target.glob('**/*'):
            if p.is_file() and not p.is_symlink():
                res = TemplateRenderer().Render(p, filename=filename)
                with p.open(mode='w') as f:
                    f.write(res)
        """       
        # ファイル内容 {{filename}}置換
        for p in path_target.glob('**/*'):
            if p.is_file() and not p.is_symlink():
                env = Environment(loader=FileSystemLoader(str(path_target)))
                template = env.get_template(p.relative_to(path_target), p)
                template.globals['now'] = datetime.datetime.now()
                with p.open(mode='w') as f:
                    f.write(template.render(filename=filename))
        """
        return path_target
        """
Esempio n. 2
0
 def __GetPathCache(self):
     for path in [
             PathIni()['root_db_template_command_repo'],
             pathlib.Path(__file__).parent,
             pathlib.Path(__file__).parent.parent / 'res'
     ]:
         filepath = path / 'url_cache.tsv'
         if filepath.is_file(): return filepath
Esempio n. 3
0
 def __LoadDefaultFile(self):
     if not self.FilePath.is_file():
         for p in [
                 pathlib.Path(PathIni()['root_meta_command_do']) /
                 self.FilePath.name, self.DefaultFilePath
         ]:
             if self.__Copy(p): return
         # コピーできるファイルがないなら空ファイル作成
         with self.FilePath.open('x'):
             pass
 def __LoadTemplateDir(self):
     self.__path_dir_template = pathlib.Path(
         PathIni()['root_db_template_command_pj']) / self.__file_name
     if not self.__path_dir_template.is_dir():
         self.__path_dir_template = pathlib.Path(
             '/tmp/work/Python.ProjectMaker.20180402173000/res')
     if not self.__path_dir_template.is_dir():
         self.__path_dir_template = pathlib.Path(
             '/tmp/work/.meta/command/pj/template/')
     if not self.__path_dir_template.is_dir():
         self.__path_dir_template = self.__path_dir_res
Esempio n. 5
0
 def __LoadTemplateDir(self):
     self.__path_dir_template = pathlib.Path(
         PathIni()['root_db_template']) / self.__file_name
     if not self.__path_dir_template.is_dir():
         self.__path_dir_template = pathlib.Path(
             '/tmp/work/Python.TemplateFileMaker.20180314204216/res')
     if not self.__path_dir_template.is_dir():
         self.__path_dir_template = pathlib.Path(
             '/tmp/work/.meta/command/do/template/')
     if not self.__path_dir_template.is_dir():
         self.__path_dir_template = self.__path_dir_res
 def __LoadFilePath(self):
     self.__path_file_this = pathlib.Path(
         PathIni()['work_meta_command_pj']) / self.__file_name
     self.__path_file_this.parent.mkdir(parents=True, exist_ok=True)
Esempio n. 7
0
 def __init__(self):
     super().__init__('command_replace')
     self.__path_file_this = pathlib.Path(
         PathIni()['work_meta_command_do']) / self.FilePath.name
     self.__path_dir_template = pathlib.Path(
         PathIni()['root_db_template']) / self.FilePath.name
Esempio n. 8
0
 def __init__(self, args: list):
     self.__args = args
     self.__path_dir_target = PathIni()['work_flow_pj']
     pathlib.Path(self.__path_dir_target).mkdir(parents=True, exist_ok=True)