提交 a0ad53cd 编写于 作者: M Mars Liu

new pipeline

上级 7fcc033f
......@@ -7,9 +7,12 @@ import sys
import re
id_set = set()
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):
with open(p, 'r') as f:
......@@ -71,11 +74,12 @@ def gen_node_id():
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.root = root
self.title = tree_name if title is None else title
self.tree = {}
self.logger = logger if log is None else log
def walk(self):
root = self.load_root()
......@@ -184,12 +188,12 @@ class TreeWalker:
config = {
"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:
config = load_json(config_path)
flag, result = self.ensure_node_id(config)
if flag:
dump_json(path, config, exist_ok=True, override=True)
dump_json(config_path, config, exist_ok=True, override=True)
return config
def ensure_chapter_config(self, path):
......@@ -199,12 +203,12 @@ class TreeWalker:
"node_id": self.gen_node_id(),
"keywords": []
}
dump_json(path, config, exist_ok=True, override=True)
dump_json(config_path, config, exist_ok=True, override=True)
else:
config = load_json(config_path)
flag, result = self.ensure_node_id(config)
if flag:
dump_json(path, config, exist_ok=True, override=True)
dump_json(config_path, config, exist_ok=True, override=True)
return config
def ensure_section_config(self, path):
......@@ -235,9 +239,14 @@ class TreeWalker:
return f"{self.name}-{uuid.uuid4().hex}"
def extract_node_env(self, path):
_, dir = os.path.split(path)
number, title = dir.split(".", 1)
return int(number), title
try:
_, dir = os.path.split(path)
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):
config = self.ensure_chapter_config(full_name)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册