Beispiel #1
0
	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)
Beispiel #2
0
def insertFile():
    global numberOfRecords
    global recordPtr
    tempFileName = tkFileDialog.askopenfilename(title="Insert XML File",
                                                filetypes=[
                                                    ("XML files", "*.xml"),
                                                    ("Text files", "*.txt"),
                                                    ("All Files", "*")
                                                ],
                                                initialdir="./")
    if len(tempFileName) == 0:
        #	catch the cancel/ESCAPE key entered
        updateStatusBar("No file selected")
    elif tempFileName:
        (newFileName, recordPtr, numRecordsAppened) = Mx.insert(tempFileName)
        listbox.delete(0, END)

        (status, recordPtr, numberOfRecords) = Mx.readFile(newFileName)
        for i in range(0, numberOfRecords):
            (title, author, pub, callnum) = Mx.marc2bib(recordPtr, i)
            string = str(i) + " " + author + " " + title + " " + pub
            listbox.insert(END, string)
        updateStatusBar(
            str(numRecordsAppened) + " records inserted from file " +
            tempFileName)
    else:
        updateStatusBar("There was an error selecting a file.")
Beispiel #3
0
def openFile():
    global numberOfRecords
    global recordPtr
    tempFileName = tkFileDialog.askopenfilename(title="Open New XML File",
                                                filetypes=[
                                                    ("XML files", "*.xml"),
                                                    ("Text files", "*.txt"),
                                                    ("All Files", "*")
                                                ],
                                                initialdir="./")
    #	send tempFileName as input parameter to review ( how to disable user interaction with review function? )
    #	the ordered records from review will populate the listbox in the main window
    if len(tempFileName) == 0:
        #	catch the cancel/ESCAPE key entered
        updateStatusBar("No file selected")
    elif tempFileName:
        (status, recordPtr, numberOfRecords) = Mx.readFile(tempFileName)
        for i in range(0, numberOfRecords):
            (title, author, pub, callnum) = Mx.marc2bib(recordPtr, i)
            string = str(i) + " " + author + " " + title + " " + pub
            listbox.insert(END, string)
        updateStatusBar(
            str(numberOfRecords) + " records found in file " + tempFileName)
    else:
        updateStatusBar("There was an error selecting a file.")
Beispiel #4
0
	def discardCommand(self):
		if self.regex.get() and self.var.get():
			self.regexString = '"'+str(self.var.get())+'='+self.regex.get()+'"'
			if (self.display.size() > 0):
				temp = tempfile.NamedTemporaryFile(delete=False)
				self.status = Mx.writeTemp(temp.file, self.collection)
				tempOutput = tempfile.NamedTemporaryFile(delete=False)
				temp.close()
				tempOutput.close()
				tstr = './mxtool'+' '+'-discard'+' '+self.regexString+' '+'<'+' '+temp.name+' '+'>'+' '+tempOutput.name
				os.system(tstr)
				self.tempCollection = 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)
						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 Remaining: "+str(self.nrecs2))
				else:
					self.label.config(text="Could not carry out regex operation")
				os.unlink(temp.name)
				os.unlink(tempOutput.name)
				self.undo.config(state=NORMAL)
			else:
				tkMessageBox.showerror("Error", "No XML File Open")
		else:
			tkMessageBox.showerror("Warning", "Make sure it is a proper regular expression and one of the buttons has been selected")
Beispiel #5
0
	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")
Beispiel #6
0
	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")
Beispiel #7
0
def dbAppend():
    #
    tempFileName = tempFolder + "/dbOpenTemp.xml"
    tempFp = open( tempFileName, "w" )
    cur.execute( "SELECT xml FROM bibrec ORDER BY author, title;" )
    results = cur.fetchall()
    for rec in results:
	tempFp.write( rec[0] )
    #	for line in file, preface each line with "\t"
    tempFp.close()
    outFpName = tempFolder + "/dbtemp.xml"
    outFp = open( outFpName, "w+" )
    outFp.write( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" )
    outFp.write( "<!-- Output by mxutil library ( Chad Chabot ) -->\r\n" )
    outFp.write( "<marc:collection xmlns:marc=\"http://www.loc.gov/MARC21/slim\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.loc.gov/MARC21/slim\nhttp://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd\">\n" )

    tempFp = open( tempFileName,"r")
    tempLines = tempFp.readlines()
    for line in tempLines:
	#	get line and append "\t"
	outFp.write( "\t" + line )

    outFp.write( "</marc:collection>\n" )
    outFp.close()

    ( status, recordPtr, numberOfRecords ) = Mx.readFile( outFpName )
    for i in range( 0, numberOfRecords ):
	( title, author, pub, callnum ) = Mx.marc2bib( recordPtr, i )
	string = str( listbox.size() + 1 ) + " " + author + " " +  title + " " + pub
	listbox.insert( END, string )
	listbox.itemconfig( listbox.size() - 1, bg='red', fg='white')
    updateStatusBar( str( numberOfRecords ) + " records loaded from db" )

    os.system( "rm -f " + tempFileName )
    os.system( "rm -f " + outFpName )
Beispiel #8
0
def select(option):
    global numberOfRecords
    global recordPtr
    value = radioSelect.get()
    if value == 1:
        field = 'a'
    elif value == 2:
        field = 't'
    else:
        field = 'p'

    pattern = field + "=" + regexString.get()
    prevNumRecords = listbox.size()
    if option == 1:
        #	keep matches
        (status, newFileName) = Mx.select("k", pattern)

        (status, recordPtr, numberOfRecords) = Mx.readFile(newFileName)
        listbox.delete(0, END)
        for i in range(0, numberOfRecords):
            (title, author, pub, callnum) = Mx.marc2bib(recordPtr, i)
            string = str(i) + " " + author + " " + title + " " + pub
            listbox.insert(END, string)
        updateStatusBar(
            str(numberOfRecords) + " records kept, " +
            str(prevNumRecords - numberOfRecords) + " remain from file " +
            newFileName)
    elif option == 0:
        #	keep matches
        (status, newFileName) = Mx.select("d", pattern)

        (status, recordPtr, numberOfRecords) = Mx.readFile(newFileName)
        listbox.delete(0, END)
        for i in range(0, numberOfRecords):
            (title, author, pub, callnum) = Mx.marc2bib(recordPtr, i)
            string = str(i) + " " + author + " " + title + " " + pub
            listbox.insert(END, string)
        updateStatusBar(
            str(prevNumRecords - numberOfRecords) + " records discarded, " +
            str(numberOfRecords) + "remain from file " + newFileName)
    else:
        #	wtf?
        i = 1
Beispiel #9
0
def Open():
  #global variables needed for append/insert
  global recPtr
  global numRecs 
  global openedFlag
  status("Opening a file..")
  fileName = tkinter.filedialog.askopenfilename(title="Open XML File", filetypes=[("XML files", "*.xml"), ("All Files", "*")])
  
  if openedFlag == 1: 
    choice = tkinter.messagebox.askyesno(title="", message = 'Overwrite data currently open?')
    if choice == 1:
      display.delete(0,END) #clear listbox to insert more records on top
      if len(fileName) != 0:
        openedFlag = 1
        value, recPtr, numRecs = Mx.readFile(fileName)
        
        if numRecs > 0:
          status( str(numRecs) + ' records opened')
        elif value == 1:
          status( 'No records found in the xml file' )
        else:
          status( 'Failed to validate xml file' )
        #display the records in the listbox
        for i in range(0, numRecs):
          (author, title, pubinfo, callnum) = Mx.marc2bib(recPtr,i)
          bibData = str(i+1) + '. ' + author + '. ' + title + '. ' + pubinfo
          display.insert(END, bibData)
    
  else:
    if len(fileName) != 0:
      openedFlag = 1
      value, recPtr, numRecs = Mx.readFile(fileName)
      if numRecs > 0:
        status( str(numRecs) + ' records opened')
      elif value == 1:
        status( 'No records found in the xml file' )
      else:
        status( 'Failed to validate xml file' )

      for i in range(0, numRecs):
        (author, title, pubinfo, callnum) = Mx.marc2bib(recPtr,i)
        bibData = str(i+1) + '. ' + author + '. ' + title + '. ' + pubinfo
        display.insert(END, bibData)
Beispiel #10
0
def select( option ):
	global numberOfRecords
	global recordPtr
	value = radioSelect.get()
	if value == 1:
		field = 'a'
	elif value == 2:
		field = 't'
	else:
		field = 'p'
	
	pattern = field+"="+regexString.get()
	prevNumRecords = listbox.size()
	if option == 1:
		#	keep matches
		( status, newFileName ) = Mx.select( "k", pattern );
		
		( status, recordPtr, numberOfRecords ) = Mx.readFile( newFileName )
		listbox.delete( 0, END )
		for i in range( 0, numberOfRecords ):
			( title, author, pub, callnum ) = Mx.marc2bib( recordPtr, i )
			string = str( i ) + " " + author + " " +  title + " " + pub
			listbox.insert( END, string )
		updateStatusBar( str( numberOfRecords ) + " records kept, " + str( prevNumRecords - numberOfRecords ) +" remain from file " + newFileName )
	elif option == 0:
		#	keep matches
		( status, newFileName ) = Mx.select( "d", pattern );
		
		( status, recordPtr, numberOfRecords ) = Mx.readFile( newFileName )
		listbox.delete( 0, END )
		for i in range( 0, numberOfRecords ):
			( title, author, pub, callnum ) = Mx.marc2bib( recordPtr, i )
			string = str( i ) + " " + author + " " +  title + " " + pub
			listbox.insert( END, string )
		updateStatusBar( str( prevNumRecords - numberOfRecords ) + " records discarded, " + str( numberOfRecords ) + "remain from file " + newFileName )
	else:
		#	wtf?
		i = 1
Beispiel #11
0
def openFile():
	global numberOfRecords
	global recordPtr
	tempFileName =  tkFileDialog.askopenfilename(title="Open New XML File", filetypes=[("XML files", "*.xml"), ("Text files", "*.txt"), ("All Files", "*")], initialdir="./")
	#	send tempFileName as input parameter to review ( how to disable user interaction with review function? )
	#	the ordered records from review will populate the listbox in the main window
	if len( tempFileName ) == 0:
		#	catch the cancel/ESCAPE key entered
		updateStatusBar( "No file selected" )
	elif tempFileName:
		( status, recordPtr, numberOfRecords ) = Mx.readFile( tempFileName )
		for i in range( 0, numberOfRecords ):
			( title, author, pub, callnum ) = Mx.marc2bib( recordPtr, i )
			string = str( i ) + " " + author + " " +  title + " " + pub
			listbox.insert( END, string )
		updateStatusBar( str( numberOfRecords ) + " records found in file " + tempFileName )
	else:
		updateStatusBar( "There was an error selecting a file." )
Beispiel #12
0
def insertFile():
	global numberOfRecords
	global recordPtr
	tempFileName =  tkFileDialog.askopenfilename(title="Insert XML File", filetypes=[("XML files", "*.xml"), ("Text files", "*.txt"), ("All Files", "*")], initialdir="./")
	if len( tempFileName ) == 0:
		#	catch the cancel/ESCAPE key entered
		updateStatusBar( "No file selected" )
	elif tempFileName:
		( newFileName, recordPtr, numRecordsAppened ) = Mx.insert( tempFileName )
		listbox.delete( 0, END )
		
		( status, recordPtr, numberOfRecords ) = Mx.readFile( newFileName )
		for i in range( 0, numberOfRecords ):
			( title, author, pub, callnum ) = Mx.marc2bib( recordPtr, i )
			string = str( i ) + " " + author + " " +  title + " " + pub
			listbox.insert( END, string )
		updateStatusBar( str( numRecordsAppened ) + " records inserted from file " + tempFileName )
	else:
		updateStatusBar( "There was an error selecting a file." )
Beispiel #13
0
def dbAppend():
    #
    tempFileName = tempFolder + "/dbOpenTemp.xml"
    tempFp = open(tempFileName, "w")
    cur.execute("SELECT xml FROM bibrec ORDER BY author, title;")
    results = cur.fetchall()
    for rec in results:
        tempFp.write(rec[0])
    #	for line in file, preface each line with "\t"
    tempFp.close()
    outFpName = tempFolder + "/dbtemp.xml"
    outFp = open(outFpName, "w+")
    outFp.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n")
    outFp.write("<!-- Output by mxutil library ( Chad Chabot ) -->\r\n")
    outFp.write(
        "<marc:collection xmlns:marc=\"http://www.loc.gov/MARC21/slim\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.loc.gov/MARC21/slim\nhttp://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd\">\n"
    )

    tempFp = open(tempFileName, "r")
    tempLines = tempFp.readlines()
    for line in tempLines:
        #	get line and append "\t"
        outFp.write("\t" + line)

    outFp.write("</marc:collection>\n")
    outFp.close()

    (status, recordPtr, numberOfRecords) = Mx.readFile(outFpName)
    for i in range(0, numberOfRecords):
        (title, author, pub, callnum) = Mx.marc2bib(recordPtr, i)
        string = str(listbox.size() +
                     1) + " " + author + " " + title + " " + pub
        listbox.insert(END, string)
        listbox.itemconfig(listbox.size() - 1, bg='red', fg='white')
    updateStatusBar(str(numberOfRecords) + " records loaded from db")

    os.system("rm -f " + tempFileName)
    os.system("rm -f " + outFpName)