提交 dc397014 编写于 作者: L luxin

add keywords_must and keywords_forbid

上级 42c80544
{
"node_id": "pg-11d131b2d01b40be90b23f096d4852cc",
"keywords": ["关系型数据库", "database", "relational", "rdbms"],
"keywords": [
"关系型数据库",
"database",
"relational",
"rdbms"
],
"children": [],
"export": [
"relation.json"
]
],
"keywords_must": [
"关系型数据库",
"database",
"relational",
"rdbms"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-cf0e5cb243a247e2a0b812c5798cdba4",
"keywords": ["server", "client", "数据库服务器", "数据库客户端"],
"keywords": [
"server",
"client",
"数据库服务器",
"数据库客户端"
],
"children": [],
"export": [
"client.json",
"server.json"
]
],
"keywords_must": [
"服务器",
"客户端"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-1aad17890736469a8b2f61a36dfe41db",
"keywords": []
"keywords": [],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-940afa6d71af44f689011ded8fd91a98",
"keywords": ["安装", "PostgreSQL"],
"keywords": [
"安装",
"PostgreSQL"
],
"children": [],
"export": ["install.json"]
"export": [
"install.json"
],
"keywords_must": [
"安装"
],
"keywords_forbid": []
}
\ No newline at end of file
......@@ -9,5 +9,9 @@
"export": [
"login.json",
"rds.json"
]
],
"keywords_must": [
"登录"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-c252ff4b0e7f4163837c9b6f81678505",
"keywords": ["login", "connect"],
"keywords": [
"login",
"connect"
],
"children": [],
"export": ["develop.json"]
"export": [
"develop.json"
],
"keywords_must": [
"使用",
"基本用法",
"入门"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-d95edf2d942b45d781e112be785ce260",
"keywords": []
"keywords": [],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-ee5c6d4a073b45a7995ba351ab9de46e",
"keywords": ["sql", "psql", " 数据库客户端"],
"keywords": [
"sql",
"psql",
" 数据库客户端"
],
"children": [],
"export": ["psql.json"]
"export": [
"psql.json"
],
"keywords_must": [
"psql"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-dca8da7637f94ded91a1871daa51746e",
"keywords": ["语法", "select"],
"keywords": [
"语法",
"select"
],
"children": [],
"export": ["basic.json"]
"export": [
"basic.json"
],
"keywords_must": [
"语法",
"SQL"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-b0f366abe12e41b0a9672d317e556662",
"keywords": ["DML", "insert", "update", "delete"],
"keywords": [
"DML",
"insert",
"update",
"delete"
],
"children": [],
"export": [
"insert.json",
"update.json",
"delete.json",
"concept.json"
]
],
"keywords_must": [
"DML",
"DDL",
"insert",
"update",
"delete"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-30f905f73a574151994d6d7f58d8a20d",
"keywords": []
"keywords": [],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-f1c160affc45417a9c5fff7dc4be448a",
"keywords": []
"keywords": [],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
......@@ -9,5 +9,10 @@
"table.json",
"create_table.json",
"serial.json"
]
],
"keywords_must": [
"表",
"table"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-f371b91ef63a4ce08f80b92bc8580196",
"keywords": ["函数", "function"],
"keywords": [
"函数",
"function"
],
"children": [],
"export": ["function.json"]
"export": [
"function.json"
],
"keywords_must": [
"函数",
"function"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-cb942198b3a84d5398d73d558a241543",
"keywords": ["role", "login", "user", "用户", "角色", "权限", "privilege"],
"keywords": [
"role",
"login",
"user",
"用户",
"角色",
"权限",
"privilege"
],
"children": [],
"export": [
"grant.json",
"revoke.json",
"role.json"
]
],
"keywords_must": [
"role",
"login",
"user",
"用户",
"角色",
"权限",
"privilege"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-eeb777ca54434480a06bfe7fc5e7d3ca",
"keywords": ["索引", " 约束", "constraints", "index"],
"keywords": [
"索引",
" 约束",
"constraints",
"index"
],
"children": [],
"export": ["primary_key.json","unique.json", "unique_2.json"]
"export": [
"primary_key.json",
"unique.json",
"unique_2.json"
],
"keywords_must": [
"索引",
" 约束",
"constraints",
"index"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-a0cb78d68d814f5e935b41922b88e085",
"keywords": ["trigger", "触发器"],
"keywords": [
"trigger",
"触发器"
],
"children": [],
"export": ["trigger.json"]
"export": [
"trigger.json"
],
"keywords_must": [
"trigger",
"触发器"
],
"keywords_forbid": []
}
\ No newline at end of file
......@@ -9,5 +9,10 @@
"export": [
"language.json",
"extension.json"
]
],
"keywords_must": [
"数据库扩展",
"extension"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-100e256ddb2e43ea8d68558e73522819",
"keywords": []
"keywords": [],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
......@@ -7,5 +7,11 @@
"children": [],
"export": [
"salary.json"
]
],
"keywords_must": [
"group by",
"分组",
"聚合"
],
"keywords_forbid": []
}
\ No newline at end of file
......@@ -7,5 +7,10 @@
"children": [],
"export": [
"customer_order.json"
]
],
"keywords_must": [
"join",
"连接查询"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-55fd213f919d411c9b572241c4bb7807",
"keywords": ["子查询", "subquery"],
"keywords": [
"子查询",
"subquery"
],
"children": [],
"export": [
"subquery.json"
]
],
"keywords_must": [
"子查询",
"subquery"
],
"keywords_forbid": []
}
\ No newline at end of file
......@@ -8,5 +8,11 @@
"children": [],
"export": [
"paged.json"
]
],
"keywords_must": [
"分页",
"limit",
"offset"
],
"keywords_forbid": []
}
\ No newline at end of file
......@@ -8,5 +8,9 @@
"children": [],
"export": [
"to_root.json"
]
],
"keywords_must": [
"cte"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-eb4048b7dfd3469f8049330ba78427b5",
"keywords": ["plsql", "过程化"],
"keywords": [
"plsql",
"过程化"
],
"children": [],
"export": ["loop.json"]
"export": [
"loop.json"
],
"keywords_must": [
"过程化"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-0378bcd60ccd4dfebcfead92abbdd673",
"keywords": ["创建表", "授权", "ddl"],
"keywords": [
"创建表",
"授权",
"ddl"
],
"children": [],
"export": [
"create_table.json",
"analyze.json"
]
],
"keywords_must": [
"创建表",
"授权",
"ddl"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-c99d8673d47444988c37f6dd3abb1e63",
"keywords": []
"keywords": [],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-fc32585f4136497ea9be2d057d4aeada",
"keywords": []
"keywords": [],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-58e924e93b564a24abb1e6b9cdfbc094",
"keywords": ["standby", "热备份", "高可用", "流复制"],
"keywords": [
"standby",
"热备份",
"高可用",
"流复制"
],
"children": [],
"export": [
"standby.json",
"backup.json"
]
],
"keywords_must": [
"standby"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-7eff3dcf68644c23bd89f2a2abe4fac6",
"keywords": ["standby", "高可用", "流复制", "wal"],
"keywords": [
"standby",
"高可用",
"流复制",
"wal"
],
"children": [],
"export": ["stream.json"]
"export": [
"stream.json"
],
"keywords_must": [
"流式复制",
"流复制"
],
"keywords_forbid": []
}
\ No newline at end of file
......@@ -7,5 +7,10 @@
"children": [],
"export": [
"fdw.json"
]
],
"keywords_must": [
"外部数据连接",
"fdw"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-328b09c201b6414d83228970591910af",
"keywords": []
"keywords": [],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-3bbe12c0a19d4cb7a61dc0a20624ed89",
"keywords": ["gis", "地理信息"],
"keywords": [
"gis",
"地理信息"
],
"children": [],
"export": ["gis.json"]
"export": [
"gis.json"
],
"keywords_must": [
"gis",
"几何"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-69ad784e39c044d7a115cfd124e49ef1",
"keywords": ["json", "jsonb"],
"keywords": [
"json",
"jsonb"
],
"children": [],
"export": [
"json.json",
"match.json",
"tags.json"
]
],
"keywords_must": [
"json",
"jsonb"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-6dbbb44b41d347b58075a9155dfb8356",
"keywords": ["函数", "过程", "function", "produce"],
"keywords": [
"函数",
"过程",
"function",
"produce"
],
"children": [],
"export": ["distinct.json"]
"export": [
"distinct.json"
],
"keywords_must": [
"聚合函数",
"json函数",
[
"数组",
"函数"
],
""
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-532f8f84ea74493a9581e6bf720ebf78",
"keywords": ["视图", "view"],
"keywords": [
"视图",
"view"
],
"children": [],
"export": ["view.json"]
"export": [
"view.json"
],
"keywords_must": [
"视图",
"view"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-f80410c703044bfea61b2f3a4fbc5705",
"keywords": []
"keywords": [],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-2e691ed3a847424eb887b40aca750c4e",
"keywords": ["cte", "递归查询", "recursive"],
"keywords": [
"cte",
"递归查询",
"recursive"
],
"children": [],
"export": [
"continuous.json"
]
],
"keywords_must": [
"cte",
"递归查询",
"recursive"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"keywords": ["函数", "function"],
"keywords": [
"函数",
"function"
],
"children": [],
"node_id": "pg-cab66a558cda467eabd9587b5a8257bd",
"export": [
"salary.json"
]
],
"keywords_must": [
"函数",
"function",
"window"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-693a81467f444886a199bac681f238b8",
"keywords": ["透视表", "交叉透视表", "pivot"],
"keywords": [
"透视表",
"交叉透视表",
"pivot"
],
"children": [],
"export": ["pivot.json"]
"export": [
"pivot.json"
],
"keywords_must": [
"透视表",
"交叉透视表",
"pivot"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-6ce3520f7a67494a90378e7b194f8720",
"keywords": ["conflict", "冲突", "唯一约束"],
"keywords": [
"conflict",
"冲突",
"唯一约束"
],
"children": [],
"export": ["score.json"]
"export": [
"score.json"
],
"keywords_must": [
"conflict",
"冲突"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-2d547e778fc4453b84feb0a0c6341348",
"keywords": ["事务", "transaction"],
"keywords": [
"事务",
"transaction"
],
"children": [],
"export": ["transaction.json"]
"export": [
"transaction.json"
],
"keywords_must": [
"事务",
"transaction"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-79fe660f35f4469481db38509343c2b7",
"keywords": ["索引", "index", "performance", "优化"],
"keywords": [
"索引",
"index",
"performance",
"优化"
],
"children": [],
"export": [
"daily_payment.json",
"daily_payment_2.json"
]
],
"keywords_must": [
"索引",
"index",
"performance",
"优化"
],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-9e66230caa834cb99a2390c7f71fb582",
"keywords": []
"keywords": [],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
{
"node_id": "pg-c9c7629c52064d8780cbd4dc14dbe351",
"keywords": []
"keywords": [],
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
{
"tree_name": "pg",
"keywords": [],
"node_id": "pg-d8b0b9aded4c4cc0b2085d6a7c5611c7"
"node_id": "pg-d8b0b9aded4c4cc0b2085d6a7c5611c7",
"keywords_must": [],
"keywords_forbid": []
}
\ No newline at end of file
......@@ -22,7 +22,14 @@
"relational",
"rdbms"
],
"children": []
"children": [],
"keywords_must": [
"关系型数据库",
"database",
"relational",
"rdbms"
],
"keywords_forbid": []
}
},
{
......@@ -34,10 +41,17 @@
"数据库服务器",
"数据库客户端"
],
"children": []
"children": [],
"keywords_must": [
"服务器",
"客户端"
],
"keywords_forbid": []
}
}
]
],
"keywords_must": [],
"keywords_forbid": []
}
},
{
......@@ -52,7 +66,11 @@
"安装",
"PostgreSQL"
],
"children": []
"children": [],
"keywords_must": [
"安装"
],
"keywords_forbid": []
}
},
{
......@@ -63,7 +81,11 @@
"身份验证",
"授权"
],
"children": []
"children": [],
"keywords_must": [
"登录"
],
"keywords_forbid": []
}
},
{
......@@ -73,10 +95,18 @@
"login",
"connect"
],
"children": []
"children": [],
"keywords_must": [
"使用",
"基本用法",
"入门"
],
"keywords_forbid": []
}
}
]
],
"keywords_must": [],
"keywords_forbid": []
}
},
{
......@@ -92,7 +122,11 @@
"psql",
" 数据库客户端"
],
"children": []
"children": [],
"keywords_must": [
"psql"
],
"keywords_forbid": []
}
},
{
......@@ -102,7 +136,12 @@
"语法",
"select"
],
"children": []
"children": [],
"keywords_must": [
"语法",
"SQL"
],
"keywords_forbid": []
}
},
{
......@@ -114,13 +153,25 @@
"update",
"delete"
],
"children": []
"children": [],
"keywords_must": [
"DML",
"DDL",
"insert",
"update",
"delete"
],
"keywords_forbid": []
}
}
]
],
"keywords_must": [],
"keywords_forbid": []
}
}
]
],
"keywords_must": [],
"keywords_forbid": []
}
},
{
......@@ -140,7 +191,12 @@
"表",
"table"
],
"children": []
"children": [],
"keywords_must": [
"表",
"table"
],
"keywords_forbid": []
}
},
{
......@@ -150,7 +206,12 @@
"函数",
"function"
],
"children": []
"children": [],
"keywords_must": [
"函数",
"function"
],
"keywords_forbid": []
}
},
{
......@@ -165,7 +226,17 @@
"权限",
"privilege"
],
"children": []
"children": [],
"keywords_must": [
"role",
"login",
"user",
"用户",
"角色",
"权限",
"privilege"
],
"keywords_forbid": []
}
},
{
......@@ -177,7 +248,14 @@
"constraints",
"index"
],
"children": []
"children": [],
"keywords_must": [
"索引",
" 约束",
"constraints",
"index"
],
"keywords_forbid": []
}
},
{
......@@ -187,7 +265,12 @@
"trigger",
"触发器"
],
"children": []
"children": [],
"keywords_must": [
"trigger",
"触发器"
],
"keywords_forbid": []
}
},
{
......@@ -198,10 +281,17 @@
"数据库插件",
"extension"
],
"children": []
"children": [],
"keywords_must": [
"数据库扩展",
"extension"
],
"keywords_forbid": []
}
}
]
],
"keywords_must": [],
"keywords_forbid": []
}
},
{
......@@ -216,7 +306,13 @@
"group by",
"分组"
],
"children": []
"children": [],
"keywords_must": [
"group by",
"分组",
"聚合"
],
"keywords_forbid": []
}
},
{
......@@ -226,7 +322,12 @@
"join",
"连接查询"
],
"children": []
"children": [],
"keywords_must": [
"join",
"连接查询"
],
"keywords_forbid": []
}
},
{
......@@ -236,7 +337,12 @@
"子查询",
"subquery"
],
"children": []
"children": [],
"keywords_must": [
"子查询",
"subquery"
],
"keywords_forbid": []
}
},
{
......@@ -247,7 +353,13 @@
"limit",
"offset"
],
"children": []
"children": [],
"keywords_must": [
"分页",
"limit",
"offset"
],
"keywords_forbid": []
}
},
{
......@@ -258,7 +370,11 @@
"cte",
"recursive"
],
"children": []
"children": [],
"keywords_must": [
"cte"
],
"keywords_forbid": []
}
},
{
......@@ -268,7 +384,11 @@
"plsql",
"过程化"
],
"children": []
"children": [],
"keywords_must": [
"过程化"
],
"keywords_forbid": []
}
},
{
......@@ -279,13 +399,23 @@
"授权",
"ddl"
],
"children": []
"children": [],
"keywords_must": [
"创建表",
"授权",
"ddl"
],
"keywords_forbid": []
}
}
]
],
"keywords_must": [],
"keywords_forbid": []
}
}
]
],
"keywords_must": [],
"keywords_forbid": []
}
},
{
......@@ -307,7 +437,11 @@
"高可用",
"流复制"
],
"children": []
"children": [],
"keywords_must": [
"standby"
],
"keywords_forbid": []
}
},
{
......@@ -319,7 +453,12 @@
"流复制",
"wal"
],
"children": []
"children": [],
"keywords_must": [
"流式复制",
"流复制"
],
"keywords_forbid": []
}
},
{
......@@ -329,10 +468,17 @@
"外部数据连接",
"fdw"
],
"children": []
"children": [],
"keywords_must": [
"外部数据连接",
"fdw"
],
"keywords_forbid": []
}
}
]
],
"keywords_must": [],
"keywords_forbid": []
}
},
{
......@@ -347,7 +493,12 @@
"gis",
"地理信息"
],
"children": []
"children": [],
"keywords_must": [
"gis",
"几何"
],
"keywords_forbid": []
}
},
{
......@@ -357,7 +508,12 @@
"json",
"jsonb"
],
"children": []
"children": [],
"keywords_must": [
"json",
"jsonb"
],
"keywords_forbid": []
}
},
{
......@@ -369,7 +525,17 @@
"function",
"produce"
],
"children": []
"children": [],
"keywords_must": [
"聚合函数",
"json函数",
[
"数组",
"函数"
],
""
],
"keywords_forbid": []
}
},
{
......@@ -379,10 +545,17 @@
"视图",
"view"
],
"children": []
"children": [],
"keywords_must": [
"视图",
"view"
],
"keywords_forbid": []
}
}
]
],
"keywords_must": [],
"keywords_forbid": []
}
},
{
......@@ -398,7 +571,13 @@
"递归查询",
"recursive"
],
"children": []
"children": [],
"keywords_must": [
"cte",
"递归查询",
"recursive"
],
"keywords_forbid": []
}
},
{
......@@ -408,7 +587,13 @@
"函数",
"function"
],
"children": []
"children": [],
"keywords_must": [
"函数",
"function",
"window"
],
"keywords_forbid": []
}
},
{
......@@ -419,7 +604,13 @@
"交叉透视表",
"pivot"
],
"children": []
"children": [],
"keywords_must": [
"透视表",
"交叉透视表",
"pivot"
],
"keywords_forbid": []
}
},
{
......@@ -430,7 +621,12 @@
"冲突",
"唯一约束"
],
"children": []
"children": [],
"keywords_must": [
"conflict",
"冲突"
],
"keywords_forbid": []
}
},
{
......@@ -440,7 +636,12 @@
"事务",
"transaction"
],
"children": []
"children": [],
"keywords_must": [
"事务",
"transaction"
],
"keywords_forbid": []
}
},
{
......@@ -452,15 +653,28 @@
"performance",
"优化"
],
"children": []
"children": [],
"keywords_must": [
"索引",
"index",
"performance",
"优化"
],
"keywords_forbid": []
}
}
]
],
"keywords_must": [],
"keywords_forbid": []
}
}
]
],
"keywords_must": [],
"keywords_forbid": []
}
}
]
],
"keywords_must": [],
"keywords_forbid": []
}
}
\ No newline at end of file
......@@ -2,10 +2,11 @@ import json
import logging
import os
import re
import subprocess
import sys
import uuid
import re
import git
id_set = set()
logger = logging.getLogger(__name__)
......@@ -14,10 +15,20 @@ handler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
repo = git.Repo(".")
def user_name():
return repo.config_reader().get_value("user", "name")
def user_name(md_file, author_dict):
ret = subprocess.Popen([
"git", "log", md_file
], stdout=subprocess.PIPE)
lines = list(map(lambda l: l.decode(), ret.stdout.readlines()))
author_lines = []
for line in lines:
if line.startswith('Author'):
author_lines.append(line.split(' ')[1])
author_nick_name = author_lines[-1]
return author_dict.get(author_nick_name, "")
def load_json(p):
with open(p, 'r') as f:
......@@ -75,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
......@@ -87,7 +109,9 @@ class TreeWalker:
root_node = {
"node_id": root["node_id"],
"keywords": root["keywords"],
"children": []
"children": [],
"keywords_must": root["keywords_must"],
"keywords_forbid": root["keywords_forbid"]
}
self.tree[root["tree_name"]] = root_node
self.load_levels(root_node)
......@@ -100,11 +124,13 @@ class TreeWalker:
for index, chapter in enumerate(level_node["children"]):
chapter_title = list(chapter.keys())[0]
chapter_node = list(chapter.values())[0]
chapter_path = os.path.join(level_path, f"{index + 1}.{chapter_title}")
chapter_path = os.path.join(
level_path, f"{index + 1}.{chapter_title}")
self.load_sections(chapter_path, chapter_node)
for index, section_node in enumerate(chapter_node["children"]):
section_title = list(section_node.keys())[0]
full_path = os.path.join(chapter_path, f"{index + 1}.{section_title}")
full_path = os.path.join(
chapter_path, f"{index + 1}.{section_title}")
if os.path.isdir(full_path):
self.check_section_keywords(full_path)
self.ensure_exercises(full_path)
......@@ -140,6 +166,8 @@ class TreeWalker:
"node_id": config["node_id"],
"keywords": config["keywords"],
"children": [],
"keywords_must": config["keywords_must"],
"keywords_forbid": config["keywords_forbid"]
}
}
......@@ -191,6 +219,8 @@ class TreeWalker:
"tree_name": self.name,
"keywords": [],
"node_id": self.gen_node_id(),
"keywords_must": [],
"keywords_forbid": []
}
dump_json(config_path, config, exist_ok=True, override=True)
else:
......@@ -220,7 +250,9 @@ class TreeWalker:
if not os.path.exists(config_path):
config = {
"node_id": self.gen_node_id(),
"keywords": []
"keywords": [],
"keywords_must": [],
"keywords_forbid": []
}
dump_json(config_path, config, exist_ok=True, override=True)
else:
......@@ -286,6 +318,8 @@ class TreeWalker:
"node_id": config["node_id"],
"keywords": config["keywords"],
"children": [],
"keywords_must": config["keywords_must"],
"keywords_forbid": config["keywords_forbid"]
}
}
return num, result
......@@ -297,7 +331,9 @@ class TreeWalker:
name: {
"node_id": config["node_id"],
"keywords": config["keywords"],
"children": config.get("children", [])
"children": config.get("children", []),
"keywords_must": config["keywords_must"],
"keywords_forbid": config["keywords_forbid"]
}
}
# if "children" in config:
......@@ -314,7 +350,8 @@ class TreeWalker:
continue
mfile = base + ".json"
meta_path = os.path.join(section_path, mfile)
self.ensure_exercises_meta(meta_path, source)
md_file = os.path.join(section_path, e)
self.ensure_exercises_meta(meta_path, source, md_file)
export = config.get("export", [])
if mfile not in export and self.name != "algorithm":
export.append(mfile)
......@@ -322,7 +359,8 @@ class TreeWalker:
config["export"] = export
if flag:
dump_json(os.path.join(section_path, "config.json"), config, True, True)
dump_json(os.path.join(section_path, "config.json"),
config, True, True)
for e in config.get("export", []):
full_name = os.path.join(section_path, e)
......@@ -334,7 +372,7 @@ class TreeWalker:
else:
id_set.add(exercise["exercise_id"])
def ensure_exercises_meta(self, meta_path, source):
def ensure_exercises_meta(self, meta_path, source, md_file):
_, mfile = os.path.split(meta_path)
meta = None
if os.path.exists(meta_path):
......@@ -349,26 +387,31 @@ class TreeWalker:
if "source" not in meta:
meta["source"] = source
if "author" not in meta:
meta["author"] = user_name()
meta["author"] = user_name(md_file, self.authors)
if "type" not in meta:
meta["type"] = "code_options"
if meta is None:
meta = {
"type": "code_options",
"author": user_name(),
"source": source,
"notebook_enable": self.default_notebook(),
"exercise_id": uuid.uuid4().hex
}
if meta is None:
meta = {
"type": "code_options",
"author": user_name(md_file, self.authors),
"source": source,
"notebook_enable": self.default_notebook(),
"exercise_id": uuid.uuid4().hex
}
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}] 的关键字为空,请修改配置文件写入关键字")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册