提交 68889b1e 编写于 作者: F feilong

重构脚本

上级 60703b7b
{
"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
......@@ -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')
......
......@@ -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)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册