Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
_小猫_
code-generator
提交
998ef837
C
code-generator
项目概览
_小猫_
/
code-generator
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
2
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
code-generator
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
2
合并请求
2
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
998ef837
编写于
7月 08, 2020
作者:
W
wjmcat
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update args_config
上级
378e16fb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
12 addition
and
8 deletion
+12
-8
src/code_generator/main.py
src/code_generator/main.py
+11
-8
tests/test_render.py
tests/test_render.py
+1
-0
未找到文件。
src/code_generator/main.py
浏览文件 @
998ef837
...
...
@@ -29,7 +29,7 @@ from .loader import TemplateLoader, PluginLoader
# pylint: disable=invalid-name
log
=
get_logger
()
# pylint: disable=invalid-name
args
:
dict
=
{}
args
_config
:
dict
=
{}
def
run_server
():
...
...
@@ -46,7 +46,9 @@ def _save_to_file(template_dir: str, file_name: str, content: str):
def
_read_to_json
(
file
:
str
)
->
dict
:
"""read json file to json data"""
"""
read json file to json data
"""
file_path
=
os
.
path
.
join
(
os
.
getcwd
(),
file
)
print
(
file_path
)
if
not
os
.
path
.
exists
(
file_path
):
...
...
@@ -55,16 +57,17 @@ def _read_to_json(file: str) -> dict:
return
json
.
load
(
f
)
def
render_by_config
():
def
render_by_config
(
params
:
dict
):
"""render the template with config file mode"""
global
args_config
args
=
args_config
.
update
(
params
)
config
=
_read_to_json
(
args
[
'config'
])
plugins
=
PluginLoader
(
args
[
'plugins'
]).
load_to_file
()
log
.
info
(
plugins
)
templates
=
TemplateLoader
(
args
[
'templates'
]).
load_templates
(
plugins
)
for
name
,
template
in
templates
.
items
():
result
=
template
.
render
(
**
config
)
base
_name
=
os
.
path
.
basename
(
args
[
'templates'
])
+
'_result'
_save_to_file
(
base
_name
,
name
,
result
)
dir
_name
=
os
.
path
.
basename
(
args
[
'templates'
])
+
'_result'
_save_to_file
(
dir
_name
,
name
,
result
)
def
main
():
...
...
@@ -84,8 +87,8 @@ def main():
config_parser
.
set_defaults
(
func
=
render_by_config
)
local_args
=
parser
.
parse_args
()
log
.
info
(
args
)
args
.
update
(
local_args
.
__dict__
)
log
.
info
(
args
_config
)
args
_config
.
update
(
local_args
.
__dict__
)
local_args
.
func
()
...
...
tests/test_render.py
浏览文件 @
998ef837
...
...
@@ -4,3 +4,4 @@ import pytest
def
test_loader
():
"""tests template loader"""
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录