def openCommand(self): if (self.nrecs > 0): result = tkMessageBox.askokcancel("Warning", "Opening a new file will result in loss of current data") if result is True: filename = askopenfilename(filetypes=[("XML Files","*.xml")]) if filename: Mx.freeFile(self.collection) #free old collection for new file to be opened self.display.delete(0, END) #read MARCXML file and return status, C-pointer to top XmElem, and no. of records (self.status, self.collection, self.nrecs) = Mx.readFile(filename) if (self.status == 0): for x in range(0, self.nrecs): self.bibdata = Mx.marc2bib(self.collection, x) #extract 4 string from subelem[recno] self.tempstring = str(x+1)+self.bibdata[0]+self.bibdata[1]+self.bibdata[2]+self.bibdata[3] self.display.insert(END,self.tempstring) elif (self.nrecs == 0): filename = askopenfilename(filetypes=[("XML Files","*.xml")]) if filename: (self.status, self.collection, self.nrecs) = Mx.readFile(filename) if (self.status == 0): self.display.delete(0, END) for x in range (0, self.nrecs): self.bibdata = Mx.marc2bib(self.collection, x) #extract 4 string from subelem[recno] self.tempstring = str(x+1)+self.bibdata[0]+self.bibdata[1]+self.bibdata[2]+self.bibdata[3] self.display.insert(END,self.tempstring) if (self.status == 0): self.label.config(text="Records: " +str(self.nrecs)) else: self.label.config(text="Could not open XML File") if (self.display.size() > 0): self.dbmenu.entryconfig(0, state=NORMAL)
def appendCommand(self): #exactly the same as above except switches order of files being concat'd if (self.display.size() > 0): temp = tempfile.NamedTemporaryFile(delete=False) self.status = Mx.writeTemp(temp.file, self.collection) self.newfile = askopenfilename(filetypes=[("XML Files", "*.xml")]) tempOutput = tempfile.NamedTemporaryFile(delete=False) temp.close() tempOutput.close() tstr = './mxtool'+' '+'-cat'+' '+self.newfile+' '+'<'+' '+temp.name+' '+'>'+' '+tempOutput.name os.system(tstr) Mx.freeFile(self.collection) self.status, self.collection, self.nrecs2 = Mx.readFile(tempOutput.name) if (self.status == 0): self.display.delete(0, END) for x in range (0, self.nrecs2): self.bibdata = Mx.marc2bib(self.collection, x) #extract 4 string from subelem[recno] self.tempstring = str(x+1)+self.bibdata[0]+self.bibdata[1]+self.bibdata[2]+self.bibdata[3] self.display.insert(END,self.tempstring) self.label.config(text="Records Added: "+str(self.nrecs2-self.nrecs)+ " Total Records: " +str(self.nrecs2)) else: self.label.config(text="Could not concatenate XML Files") os.unlink(temp.name) os.unlink(tempOutput.name) else: tkMessageBox.showerror("Error", "No XML File Open")
def insertCommand(self): if (self.display.size() > 0): temp = tempfile.NamedTemporaryFile(delete=False) #tempfile for current display to be written to self.status = Mx.writeTemp(temp.file, self.collection) self.newfile = askopenfilename(filetypes=[("XML Files", "*.xml")]) tempOutput = tempfile.NamedTemporaryFile(delete=False) temp.close() tempOutput.close() tstr = './mxtool'+' '+'-cat'+' '+temp.name+' '+'<'+' '+self.newfile+' '+'>'+' '+tempOutput.name os.system(tstr) #command line execution: calls above statement Mx.freeFile(self.collection) self.status, self.collection, self.nrecs2 = Mx.readFile(tempOutput.name) #reads new file to update display if (self.status == 0): self.display.delete(0, END) for x in range (0, self.nrecs2): self.bibdata = Mx.marc2bib(self.collection, x) #extract 4 string from subelem[recno] self.tempstring = str(x+1)+self.bibdata[0]+self.bibdata[1]+self.bibdata[2]+self.bibdata[3] self.display.insert(END,self.tempstring) self.label.config(text="Records Added: "+str(self.nrecs2-self.nrecs)+ " Total Records: " +str(self.nrecs2)) else: self.label.config(text="Could not concatenate XML Files") os.unlink(temp.name) #removes temporary files now incase user decides to insert multiple times os.unlink(tempOutput.name) #in one session so as to not lose track of all files being created else: tkMessageBox.showerror("Error", "No XML File Open")
def undoCommand(self): self.display.delete(0, END) Mx.freeFile(self.collection) #frees collection because the user wishes to undo self.collection = self.tempCollection #have the empty collection point to the old collection for x in range (0, self.nrecs): #update display with old data self.bibdata = Mx.marc2bib(self.collection, x) self.tempstring = str(x+1)+self.bibdata[0]+self.bibdata[1]+self.bibdata[2]+self.bibdata[3] self.display.insert(END,self.tempstring) self.nrecs2 = self.nrecs self.label.config(text="Records: "+str(self.nrecs2)) self.undo.config(state=DISABLED) #disable undo key to not be abused and not crash
def quit(self): self.result = tkMessageBox.askyesno("Warning", "Do you wish to exit?") if self.result is True: if (self.collection != 0): Mx.freeFile(self.collection) Mx.term() #terminate libxml2 processing and release storage #os.system("make clean") cursor.close() conn.close() root root.destroy()