diff --git a/工具v4/database_tools_2.py b/工具v4/database_tools_2.py index 18a382ef..f1e4e992 100644 --- a/工具v4/database_tools_2.py +++ b/工具v4/database_tools_2.py @@ -542,6 +542,7 @@ def AddRelatedProblemToDB(id,content,oid,editor,database): def AddProblemstoDict2024nocommit(startingid,raworigin,problems,editor,indexed,cursor): #将来自GenerateProblemListFromString的列表中的题目添加到thedict字典, 返回题号列表(包括用老题号替代的题目) mycursor = cursor idlist = [] + problemlist = [] id = int(startingid) currentsuffix = problems[0][1] problemindex = 0 @@ -549,6 +550,7 @@ def AddProblemstoDict2024nocommit(startingid,raworigin,problems,editor,indexed,c try: p, suffix, meta = p_and_suffix_and_meta p = re.sub(r"\n\s+","\n",p) + problemlist.append(p) pid = str(id).zfill(6) if suffix == currentsuffix: problemindex += 1 @@ -610,7 +612,7 @@ def AddProblemstoDict2024nocommit(startingid,raworigin,problems,editor,indexed,c print(f"错误的题目: {p_and_suffix_and_meta}") idlist = [] break - return idlist + return (idlist,problemlist) def CreateIDLinks(old_id_list,new_id_list): #建立已有id和新id之间的联系, thedict为可选, 选中的话即为当前字典, 会从new_id_list中排除当前字典中有的项 if len(old_id_list)>len(new_id_list): diff --git a/工具v4/批量收录新题.py b/工具v4/批量收录新题.py index 77709fce..18ed9f2a 100644 --- a/工具v4/批量收录新题.py +++ b/工具v4/批量收录新题.py @@ -21,6 +21,7 @@ class MyWindow_bdsl(QWidget,Ui_Form): self.pushButton_step2.clicked.connect(self.execstep2) self.pushButton_commit.clicked.connect(self.commitchange) self.plainTextEdit_compared.textChanged.connect(self.commitdisable) + self.problemstoimport = [] def togglesuffix(self): self.suffix_checked = self.checkBox_suffix.isChecked() if self.suffix_checked: @@ -99,7 +100,15 @@ class MyWindow_bdsl(QWidget,Ui_Form): self.db = connect(hostname = db_host, port= db_port, username= db_user, pwd = db_pwd, db= self.database_name) self.cursor = self.db.cursor() rolled_back = False - idlist = AddProblemstoDict2024nocommit(nextspareid,raworigin,problems,editor,Indexed,self.cursor) + idlist,newproblemlist = AddProblemstoDict2024nocommit(nextspareid,raworigin,problems,editor,Indexed,self.cursor) + for p in newproblemlist: + if p in self.problemstoimport: + print("有重复导入的题目, 改变已回滚!!!\n"*5) + self.db.rollback() + rolled_back = True + break + else: + self.problemstoimport.append(p) if idlist == []: print("有错误, 改变已回滚.") self.db.rollback() @@ -108,6 +117,8 @@ class MyWindow_bdsl(QWidget,Ui_Form): AppendTextFile(f"{GetDate()}-{GetTime()}\n{generate_exp(idlist)}",idlistpath) os.system(f"code {idlistpath}") self.pushButton_commit.setEnabled(True) + else: + self.pushButton_commit.setDisabled(True) def commitdisable(self): self.pushButton_commit.setDisabled(True)