From 444ce6789385c663adacd223e2ca3997c1290c78 Mon Sep 17 00:00:00 2001 From: Mars Liu Date: Mon, 8 Nov 2021 15:18:37 +0800 Subject: [PATCH] new pipeline --- .../config.json" | 4 +++ .../config.json" | 4 +++ .../config.json" | 4 +++ .../config.json" | 4 +++ .../config.json" | 4 +++ .../config.json" | 4 +++ .../config.json" | 4 +++ src/tree.py | 29 ++++++++++++------- 8 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257-\345\237\272\347\241\200/config.json" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/config.json" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/config.json" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/4.\350\223\235\346\241\245\346\235\257-\345\240\206\346\240\210\351\230\237\345\210\227\351\223\276\350\241\250/config.json" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\250\241\346\213\237/config.json" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/7.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/config.json" create mode 100644 "data/1.\347\256\227\346\263\225\345\210\235\351\230\266/9.\350\223\235\346\241\245\346\235\257-\345\212\250\346\200\201\350\247\204\345\210\222/config.json" diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257-\345\237\272\347\241\200/config.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257-\345\237\272\347\241\200/config.json" new file mode 100644 index 000000000..173961dbd --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/1.\350\223\235\346\241\245\346\235\257-\345\237\272\347\241\200/config.json" @@ -0,0 +1,4 @@ +{ + "node_id": "algorithm-707bc3b2034f4c639a7e1e8828fb22ac", + "keywords": [] +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/config.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/config.json" new file mode 100644 index 000000000..da6930476 --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/2.\350\223\235\346\241\245\346\235\257-\345\255\227\347\254\246\344\270\262/config.json" @@ -0,0 +1,4 @@ +{ + "node_id": "algorithm-11bdcd7166984a0fa8187e33caec82e2", + "keywords": [] +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/config.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/config.json" new file mode 100644 index 000000000..eb928e364 --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/3.\350\223\235\346\241\245\346\235\257-\351\200\222\345\275\222/config.json" @@ -0,0 +1,4 @@ +{ + "node_id": "algorithm-96856f29bdaa4370b2bc29820d7999bb", + "keywords": [] +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/4.\350\223\235\346\241\245\346\235\257-\345\240\206\346\240\210\351\230\237\345\210\227\351\223\276\350\241\250/config.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/4.\350\223\235\346\241\245\346\235\257-\345\240\206\346\240\210\351\230\237\345\210\227\351\223\276\350\241\250/config.json" new file mode 100644 index 000000000..e7206343a --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/4.\350\223\235\346\241\245\346\235\257-\345\240\206\346\240\210\351\230\237\345\210\227\351\223\276\350\241\250/config.json" @@ -0,0 +1,4 @@ +{ + "node_id": "algorithm-74e89b5553f243698b3542dc6b54ec06", + "keywords": [] +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\250\241\346\213\237/config.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\250\241\346\213\237/config.json" new file mode 100644 index 000000000..5adea2b87 --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/6.\350\223\235\346\241\245\346\235\257-\346\250\241\346\213\237/config.json" @@ -0,0 +1,4 @@ +{ + "node_id": "algorithm-1f5b7166096d434eb8857a95a8b5676b", + "keywords": [] +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/7.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/config.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/7.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/config.json" new file mode 100644 index 000000000..486e27086 --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/7.\350\223\235\346\241\245\346\235\257-\346\220\234\347\264\242/config.json" @@ -0,0 +1,4 @@ +{ + "node_id": "algorithm-74bf3d495948453abda2db6fb53aca60", + "keywords": [] +} \ No newline at end of file diff --git "a/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/9.\350\223\235\346\241\245\346\235\257-\345\212\250\346\200\201\350\247\204\345\210\222/config.json" "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/9.\350\223\235\346\241\245\346\235\257-\345\212\250\346\200\201\350\247\204\345\210\222/config.json" new file mode 100644 index 000000000..baeb2c7e0 --- /dev/null +++ "b/data/1.\347\256\227\346\263\225\345\210\235\351\230\266/9.\350\223\235\346\241\245\346\235\257-\345\212\250\346\200\201\350\247\204\345\210\222/config.json" @@ -0,0 +1,4 @@ +{ + "node_id": "algorithm-59898084a79e4312893ce184653b879b", + "keywords": [] +} \ No newline at end of file diff --git a/src/tree.py b/src/tree.py index c36a946fc..9e6a5cf92 100644 --- a/src/tree.py +++ b/src/tree.py @@ -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) -- GitLab