Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN 技术社区
skill_tree_web_in_action
提交
36fae6c2
S
skill_tree_web_in_action
项目概览
CSDN 技术社区
/
skill_tree_web_in_action
通知
8
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
skill_tree_web_in_action
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
36fae6c2
编写于
11月 08, 2021
作者:
M
Mars Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new pipeline
上级
2cf5ff40
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
19 addition
and
10 deletion
+19
-10
src/tree.py
src/tree.py
+19
-10
未找到文件。
src/tree.py
浏览文件 @
36fae6c2
...
@@ -7,9 +7,12 @@ import sys
...
@@ -7,9 +7,12 @@ import sys
import
re
import
re
id_set
=
set
()
id_set
=
set
()
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
logger
.
setLevel
(
logging
.
INFO
)
handler
=
logging
.
StreamHandler
(
sys
.
stdout
)
formatter
=
logging
.
Formatter
(
'%(asctime)s - %(levelname)s - %(message)s'
)
handler
.
setFormatter
(
formatter
)
logger
.
addHandler
(
handler
)
def
load_json
(
p
):
def
load_json
(
p
):
with
open
(
p
,
'r'
)
as
f
:
with
open
(
p
,
'r'
)
as
f
:
...
@@ -71,11 +74,12 @@ def gen_node_id():
...
@@ -71,11 +74,12 @@ def gen_node_id():
class
TreeWalker
:
class
TreeWalker
:
def
__init__
(
self
,
root
,
tree_name
,
title
=
None
):
def
__init__
(
self
,
root
,
tree_name
,
title
=
None
,
log
=
None
):
self
.
name
=
tree_name
self
.
name
=
tree_name
self
.
root
=
root
self
.
root
=
root
self
.
title
=
tree_name
if
title
is
None
else
title
self
.
title
=
tree_name
if
title
is
None
else
title
self
.
tree
=
{}
self
.
tree
=
{}
self
.
logger
=
logger
if
log
is
None
else
log
def
walk
(
self
):
def
walk
(
self
):
root
=
self
.
load_root
()
root
=
self
.
load_root
()
...
@@ -184,12 +188,12 @@ class TreeWalker:
...
@@ -184,12 +188,12 @@ class TreeWalker:
config
=
{
config
=
{
"node_id"
:
self
.
gen_node_id
()
"node_id"
:
self
.
gen_node_id
()
}
}
dump_json
(
path
,
config
,
exist_ok
=
True
,
override
=
True
)
dump_json
(
config_
path
,
config
,
exist_ok
=
True
,
override
=
True
)
else
:
else
:
config
=
load_json
(
config_path
)
config
=
load_json
(
config_path
)
flag
,
result
=
self
.
ensure_node_id
(
config
)
flag
,
result
=
self
.
ensure_node_id
(
config
)
if
flag
:
if
flag
:
dump_json
(
path
,
config
,
exist_ok
=
True
,
override
=
True
)
dump_json
(
config_
path
,
config
,
exist_ok
=
True
,
override
=
True
)
return
config
return
config
def
ensure_chapter_config
(
self
,
path
):
def
ensure_chapter_config
(
self
,
path
):
...
@@ -199,12 +203,12 @@ class TreeWalker:
...
@@ -199,12 +203,12 @@ class TreeWalker:
"node_id"
:
self
.
gen_node_id
(),
"node_id"
:
self
.
gen_node_id
(),
"keywords"
:
[]
"keywords"
:
[]
}
}
dump_json
(
path
,
config
,
exist_ok
=
True
,
override
=
True
)
dump_json
(
config_
path
,
config
,
exist_ok
=
True
,
override
=
True
)
else
:
else
:
config
=
load_json
(
config_path
)
config
=
load_json
(
config_path
)
flag
,
result
=
self
.
ensure_node_id
(
config
)
flag
,
result
=
self
.
ensure_node_id
(
config
)
if
flag
:
if
flag
:
dump_json
(
path
,
config
,
exist_ok
=
True
,
override
=
True
)
dump_json
(
config_
path
,
config
,
exist_ok
=
True
,
override
=
True
)
return
config
return
config
def
ensure_section_config
(
self
,
path
):
def
ensure_section_config
(
self
,
path
):
...
@@ -235,9 +239,14 @@ class TreeWalker:
...
@@ -235,9 +239,14 @@ class TreeWalker:
return
f
"
{
self
.
name
}
-
{
uuid
.
uuid4
().
hex
}
"
return
f
"
{
self
.
name
}
-
{
uuid
.
uuid4
().
hex
}
"
def
extract_node_env
(
self
,
path
):
def
extract_node_env
(
self
,
path
):
_
,
dir
=
os
.
path
.
split
(
path
)
try
:
number
,
title
=
dir
.
split
(
"."
,
1
)
_
,
dir
=
os
.
path
.
split
(
path
)
return
int
(
number
),
title
self
.
logger
.
info
(
path
)
number
,
title
=
dir
.
split
(
"."
,
1
)
return
int
(
number
),
title
except
Exception
as
error
:
self
.
logger
.
error
(
f
"目录 [
{
path
}
] 解析失败,结构不合法,可能是缺少序号"
)
sys
.
exit
(
1
)
def
load_chapter_node
(
self
,
full_name
):
def
load_chapter_node
(
self
,
full_name
):
config
=
self
.
ensure_chapter_config
(
full_name
)
config
=
self
.
ensure_chapter_config
(
full_name
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录