添加关联题目后进行试编译
This commit is contained in:
parent
8f794f547a
commit
ac94e78ab3
|
|
@ -452,12 +452,14 @@ def CreateRelatedProblems(links,thedict,filepath,editor): # 根据links关联生
|
||||||
def ImportRelatedProblems(new_json,main_json): # 导入编辑过的关联题目json文件到主数据库
|
def ImportRelatedProblems(new_json,main_json): # 导入编辑过的关联题目json文件到主数据库
|
||||||
pro_dict = load_dict(main_json)
|
pro_dict = load_dict(main_json)
|
||||||
new_dict = load_dict(new_json)
|
new_dict = load_dict(new_json)
|
||||||
|
edited = []
|
||||||
for id in new_dict:
|
for id in new_dict:
|
||||||
new_id = new_dict[id]["id"].replace("待替换","") #新题号后需要跟"待替换"字样
|
new_id = new_dict[id]["id"].replace("待替换","") #新题号后需要跟"待替换"字样
|
||||||
if new_id in pro_dict:
|
if new_id in pro_dict:
|
||||||
print("题号有重复")
|
print("题号有重复")
|
||||||
return 1
|
return 1 #异常返回1
|
||||||
else:
|
else:
|
||||||
|
edited.append(new_id)
|
||||||
pro_dict[new_id] = new_dict[id].copy()
|
pro_dict[new_id] = new_dict[id].copy()
|
||||||
pro_dict[new_id]["id"] = new_id
|
pro_dict[new_id]["id"] = new_id
|
||||||
pro_dict[id]["related"] += [new_id]
|
pro_dict[id]["related"] += [new_id]
|
||||||
|
|
@ -474,7 +476,7 @@ def ImportRelatedProblems(new_json,main_json): # 导入编辑过的关联题目j
|
||||||
pro_dict[new_id]["genre"] = "4em"
|
pro_dict[new_id]["genre"] = "4em"
|
||||||
print("导入关联题目 %s -> %s 信息成功."%(id,new_id))
|
print("导入关联题目 %s -> %s 信息成功."%(id,new_id))
|
||||||
save_dict(SortDict(pro_dict),main_json) #保存至目标pro_dict文件
|
save_dict(SortDict(pro_dict),main_json) #保存至目标pro_dict文件
|
||||||
return 0 #正常返回0
|
return generate_exp(edited) #正常返回新题号list
|
||||||
|
|
||||||
|
|
||||||
def strip_suffix(originalString, suf_words_list): # 字符串去除指定后缀
|
def strip_suffix(originalString, suf_words_list): # 字符串去除指定后缀
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,23 @@ from database_tools import *
|
||||||
tempfilepath = "临时文件/problem_edit.json"
|
tempfilepath = "临时文件/problem_edit.json"
|
||||||
|
|
||||||
pro_dict = load_dict("../题库0.3/problems.json")
|
pro_dict = load_dict("../题库0.3/problems.json")
|
||||||
|
obj_dict = load_dict("../题库0.3/LessonObj.json")
|
||||||
|
pro_dict_raw_string = ReadTextFile("../题库0.3/problems.json")
|
||||||
|
configjson = load_dict("文本文件/config.json")["默认完整编译题目模式"]
|
||||||
|
|
||||||
|
|
||||||
links = CreateIDLinks(generate_number_set(old_ids),generate_number_set(NextSpareIDBlock(starting_id,pro_dict)),pro_dict)
|
links = CreateIDLinks(generate_number_set(old_ids),generate_number_set(NextSpareIDBlock(starting_id,pro_dict)),pro_dict)
|
||||||
CreateRelatedProblems(links,pro_dict,tempfilepath,editor)
|
CreateRelatedProblems(links,pro_dict,tempfilepath,editor)
|
||||||
|
|
||||||
print("编辑完毕后, 保存关闭文件继续.")
|
print("编辑完毕后, 保存关闭文件继续.")
|
||||||
os.system("code -w -g "+tempfilepath) #-w表示关闭窗口后继续下一步
|
os.system("code -w -g "+tempfilepath) #-w表示关闭窗口后继续下一步
|
||||||
|
|
||||||
ImportRelatedProblems(tempfilepath,"../题库0.3/problems.json")
|
editedid_list = ImportRelatedProblems(tempfilepath,"../题库0.3/problems.json")
|
||||||
|
|
||||||
|
pro_dict = load_dict("../题库0.3/problems.json")
|
||||||
|
|
||||||
|
if not XeLaTeXTest(editedid_list,pro_dict,obj_dict,configjson,templatepath="模板文件/讲义模板.txt",outdir = "临时文件",outfile = "problems_test.tex"):
|
||||||
|
SaveTextFile(pro_dict_raw_string,"../题库0.3/Problems.json")
|
||||||
|
print("编译失败, 题库文件退回原状")
|
||||||
|
else:
|
||||||
|
print("编译成功, 已汇入题库")
|
||||||
Reference in New Issue