diff --git a/assets/author.json b/assets/author.json deleted file mode 100644 index 4640a90b05ff10cbaa41a5bd9b3a49bccf4059e3..0000000000000000000000000000000000000000 --- a/assets/author.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "Python小白进阶":"youcans", - "youcans": "youcans", - "AI浩":"hhhhhhhhhhwwwwwwwwww", - "hhhhhhhhhhwwwwwwwwww": "hhhhhhhhhhwwwwwwwwww", - "吴佳WuJia":"yvettewu", - "yvettewu": "yvettewu", - "幻灰龙":"huanhuilong", - "feilong":"huanhuilong", - "huanhuilong": "huanhuilong", - "xiaozhi_5638": "xiaozhi_5638", - "请叫我卷福": "xiaozhi_5638" -} \ No newline at end of file diff --git a/main.py b/main.py index 24fdf1f228f069ff54e3323231f4785d1690dcd0..c1f1a6ec899d861d6390b538233b10dffbf0f620 100644 --- a/main.py +++ b/main.py @@ -4,7 +4,24 @@ from src.doc import DocWalker from src.img import ImgWalker if __name__ == '__main__': - walker = TreeWalker("data", "opencv", "OpenCV") + walker = TreeWalker( + "data", "opencv", "OpenCV", + ignore_keywords=True, + enable_notebook=False, + authors={ + "Python小白进阶": "youcans", + "youcans": "youcans", + "AI浩": "hhhhhhhhhhwwwwwwwwww", + "hhhhhhhhhhwwwwwwwwww": "hhhhhhhhhhwwwwwwwwww", + "吴佳WuJia": "yvettewu", + "yvettewu": "yvettewu", + "幻灰龙": "huanhuilong", + "feilong": "huanhuilong", + "huanhuilong": "huanhuilong", + "xiaozhi_5638": "xiaozhi_5638", + "请叫我卷福": "xiaozhi_5638" + } + ) walker.walk() # doc = DocWalker('doc') diff --git a/src/tree.py b/src/tree.py index 6405ceff0d460729969a2291b0561c4c457bd51a..3891238fd1b41faded6fb6daa63b6898d6bb7a02 100644 --- a/src/tree.py +++ b/src/tree.py @@ -6,12 +6,6 @@ import subprocess import sys import uuid import re -import git - - -def load_json(p): - with open(p, 'r') as f: - return json.loads(f.read()) id_set = set() @@ -21,11 +15,9 @@ handler = logging.StreamHandler(sys.stdout) formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') handler.setFormatter(formatter) logger.addHandler(handler) -repo = git.Repo(".") -author_dict = load_json('assets/author.json') -def user_name(md_file): +def user_name(md_file, author_dict): ret = subprocess.Popen([ "git", "log", md_file ], stdout=subprocess.PIPE) @@ -36,7 +28,11 @@ def user_name(md_file): author_lines.append(line.split(' ')[1]) author_nick_name = author_lines[-1] return author_dict.get(author_nick_name, "") - # return repo.config_reader().get_value("user", "name") + + +def load_json(p): + with open(p, 'r') as f: + return json.loads(f.read()) def dump_json(p, j, exist_ok=False, override=False): @@ -90,7 +86,18 @@ def check_export(base, cfg): class TreeWalker: - def __init__(self, root, tree_name, title=None, log=None): + def __init__( + self, root, + tree_name, + title=None, + log=None, + authors=None, + enable_notebook=None, + ignore_keywords=False + ): + self.ignore_keywords = ignore_keywords + self.authors = authors if authors else {} + self.enable_notebook = enable_notebook self.name = tree_name self.root = root self.title = tree_name if title is None else title @@ -369,7 +376,7 @@ class TreeWalker: if "source" not in meta: meta["source"] = source if "author" not in meta: - meta["author"] = user_name(md_file) + meta["author"] = user_name(md_file, self.authors) if "type" not in meta: meta["type"] = "code_options" except: @@ -377,7 +384,7 @@ class TreeWalker: if meta is None: meta = { "type": "code_options", - "author": user_name(md_file), + "author": user_name(md_file, self.authors), "source": source, "notebook_enable": self.default_notebook(), "exercise_id": uuid.uuid4().hex @@ -385,13 +392,17 @@ class TreeWalker: dump_json(meta_path, meta, True, True) def default_notebook(self): + if self.enable_notebook is not None: + return self.enable_notebook if self.name in ["python", "java", "c"]: return True else: return False def check_section_keywords(self, full_path): + if self.ignore_keywords: + return config = self.ensure_section_config(full_path) - # if not config.get("keywords", []): - # self.logger.error(f"节点 [{full_path}] 的关键字为空,请修改配置文件写入关键字") - # sys.exit(1) + if not config.get("keywords", []): + self.logger.error(f"节点 [{full_path}] 的关键字为空,请修改配置文件写入关键字") + sys.exit(1)