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

new pipeline

上级 7fcc033f
...@@ -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.
先完成此消息的编辑!
想要评论请 注册