コード例 #1
0
ファイル: altro.py プロジェクト: SameerAlmutairi/Altro
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.")
コード例 #2
0
ファイル: altro.py プロジェクト: kevintran1989/projects
	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")
コード例 #3
0
ファイル: altro.py プロジェクト: chadchabot/Altro
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 )
コード例 #4
0
ファイル: altro.py プロジェクト: kevintran1989/projects
	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")
コード例 #5
0
ファイル: altro.py プロジェクト: kevintran1989/projects
	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")
コード例 #6
0
ファイル: altro.py プロジェクト: SameerAlmutairi/Altro
def storeSelected():
    global numberOfRecords
    global recordPtr
    recordsWritten = 0
    #listCount = listbox.curselection()
    listCount = map(int, listbox.curselection())
    for i in listCount:
        #	grab records from the most current version of top
        (title, author, pubinfo, callnum) = Mx.marc2bib(recordPtr, i)
        #	sqlCommand = "INSERT INTO bibrec (author,title,pubinfo,callnum) VALUES ('" + author + "','" + title + "','" + pubinfo + "','" + callnum + "');"
        #	cur.execute( sqlCommand )
        cur.execute("SELECT * FROM bibrec WHERE author=%s AND title=%s;",
                    (author, title))
        results = cur.fetchall()
        if len(results) == 0:
            recordsWritten += 1
            pubCopy = pubinfo
            match = re.search(r"[0-9]{4}", pubCopy)
            if match:
                year = match.group(0)
            else:
                year = ""
            tempFileName = Mx.getRawXml(recordPtr, i)
            fp = open(tempFileName, "r")
            xml = fp.read()
            fp.close()
            os.system("rm -rf " + tempFileName)
            cur.execute(
                "INSERT INTO bibrec (author,title,pubinfo,callnum,year,xml) VALUES (%s,%s,%s,%s,%s,%s);",
                (author[:60], title[:120], pubinfo, callnum[:30], year, xml))
    updateStatusBar(str(recordsWritten) + " stored to database")
コード例 #7
0
ファイル: altro.py プロジェクト: SameerAlmutairi/Altro
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.")
コード例 #8
0
ファイル: altro.py プロジェクト: chadchabot/Altro
def storeSelected():
    global numberOfRecords
    global recordPtr
    recordsWritten = 0
    #listCount = listbox.curselection()
    listCount = map( int, listbox.curselection() )
    for i in listCount:
    #	grab records from the most current version of top
	( title, author, pubinfo, callnum ) = Mx.marc2bib( recordPtr, i )
#	sqlCommand = "INSERT INTO bibrec (author,title,pubinfo,callnum) VALUES ('" + author + "','" + title + "','" + pubinfo + "','" + callnum + "');"
#	cur.execute( sqlCommand )
	cur.execute( "SELECT * FROM bibrec WHERE author=%s AND title=%s;", (author,title) )
	results = cur.fetchall()
	if len(results) == 0:
	    recordsWritten += 1
	    pubCopy = pubinfo
	    match = re.search(r"[0-9]{4}", pubCopy )
	    if match:
		year = match.group(0)
	    else:
		year = ""
	    tempFileName = Mx.getRawXml( recordPtr, i )
	    fp = open( tempFileName, "r" )
	    xml = fp.read()
	    fp.close()
	    os.system( "rm -rf " + tempFileName )
	    cur.execute( "INSERT INTO bibrec (author,title,pubinfo,callnum,year,xml) VALUES (%s,%s,%s,%s,%s,%s);", (author[:60],title[:120],pubinfo,callnum[:30],year,xml) )
    updateStatusBar( str( recordsWritten ) + " stored to database" )
コード例 #9
0
ファイル: altro.py プロジェクト: kevintran1989/projects
	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
コード例 #10
0
ファイル: altro.py プロジェクト: chadchabot/Altro
def exitApp():
	userResponse = tkMessageBox.askyesno("Exit?", "Are you sure you would like to quit?")
	if userResponse:
		#	check for all open/temp files, close any that are open.
		#	free any open data structures by calling appropriate mxutil functions.
		#	then quit the python program.
		os.system( "rm -rf " + tempFolder + "/" )
		Mx.term()
		cur.close()
		connection.close()
		root.quit()
コード例 #11
0
ファイル: altro.py プロジェクト: kevintran1989/projects
	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()
コード例 #12
0
ファイル: altro.py プロジェクト: chadchabot/Altro
def bibOutput():
	outputFilename = tkFileDialog.asksaveasfilename(title="Save Bibliography format to file:", filetypes=[("Text files", "*.txt"), ("All Files", "*")], initialdir="./")
	#print "saving file as: " + outputFilename
	if len( outputFilename) == 0:
		#	catch the cancel/ESCAPE key entered
		updateStatusBar( "no file selected" )
	elif outputFilename:
		Mx.libOrBib( outputFilename, 0 )
		updateStatusBar( str( listbox.size() ) + " records written to file\n" + outputFilename + "\nin bibliography format" )
	else:
		updateStatusBar( "error selecting file." )
コード例 #13
0
ファイル: altro.py プロジェクト: SameerAlmutairi/Altro
def exitApp():
    userResponse = tkMessageBox.askyesno(
        "Exit?", "Are you sure you would like to quit?")
    if userResponse:
        #	check for all open/temp files, close any that are open.
        #	free any open data structures by calling appropriate mxutil functions.
        #	then quit the python program.
        os.system("rm -rf " + tempFolder + "/")
        Mx.term()
        cur.close()
        connection.close()
        root.quit()
コード例 #14
0
ファイル: altro.py プロジェクト: kevintran1989/projects
	def storeSelected(self):
		self.uniqueInserts = 0
		self.index = self.display.curselection()	#gets the index of elements user wishes to keep
		for x in range (0, len(self.index)):
			self.bibdata = Mx.marc2bib(self.collection, int(self.index[x]))	#extracts data
			self.xmlText = Mx.makeElem(self.collection, int(self.index[x]))	#gets xml text for corresponding xml element
			self.year = re.search("([0-9][0-9][0-9][0-9])", self.bibdata[2])	#regex to extract just the year
			cursor.execute("SELECT * FROM bibrec WHERE title=%s and author=%s", (self.bibdata[0], self.bibdata[1]))
			if (cursor.rowcount == 0):	
				self.uniqueInserts += 1
				if self.year is None:
					self.nYear = "NULL"
					cursor.execute("INSERT INTO bibrec (author, title, pubinfo, callnum, year, xml) VALUES (%s, %s, %s, %s, %s, %s)", (self.bibdata[1], self.bibdata[0], self.bibdata[2], self.bibdata[3], self.nYear, self.xmlText))
				else:
					cursor.execute("INSERT INTO bibrec (author, title, pubinfo, callnum, year, xml) VALUES (%s, %s, %s, %s, %s, %s)", (self.bibdata[1], self.bibdata[0], self.bibdata[2], self.bibdata[3], self.year.group(), self.xmlText))
		self.label.config(text="Records inserted to DB: "+str(self.uniqueInserts))
コード例 #15
0
ファイル: altro.py プロジェクト: kevintran1989/projects
	def storeAll(self):
		self.uniqueInserts = 0
		for x in range (0, self.nrecs):	#loops through each record
			self.bibdata = Mx.marc2bib(self.collection, x)	#extracts data
			self.xmlText = Mx.makeElem(self.collection, x)	#gets xml text for corresponding xml element
			self.year = re.search("([0-9][0-9][0-9][0-9])", self.bibdata[2])	#regex to extract just the year
			#0 = title, 1 = author, 2 = pubinfo, 3 = callnum - date should be in 2
			cursor.execute("SELECT * FROM bibrec WHERE title=%s and author=%s", (self.bibdata[0], self.bibdata[1]))
			if (cursor.rowcount == 0):	
				self.uniqueInserts += 1
				if self.year is None:
					self.nYear = "NULL"
					cursor.execute("INSERT INTO bibrec (author, title, pubinfo, callnum, year, xml) VALUES (%s, %s, %s, %s, %s, %s)", (self.bibdata[1], self.bibdata[0], self.bibdata[2], self.bibdata[3], self.nYear, self.xmlText))
				else:
					cursor.execute("INSERT INTO bibrec (author, title, pubinfo, callnum, year, xml) VALUES (%s, %s, %s, %s, %s, %s)", (self.bibdata[1], self.bibdata[0], self.bibdata[2], self.bibdata[3], self.year.group(), self.xmlText))
		self.label.config(text="Records inserted to DB: "+str(self.uniqueInserts))
コード例 #16
0
ファイル: altro.py プロジェクト: SameerAlmutairi/Altro
def bibOutput():
    outputFilename = tkFileDialog.asksaveasfilename(
        title="Save Bibliography format to file:",
        filetypes=[("Text files", "*.txt"), ("All Files", "*")],
        initialdir="./")
    #print "saving file as: " + outputFilename
    if len(outputFilename) == 0:
        #	catch the cancel/ESCAPE key entered
        updateStatusBar("no file selected")
    elif outputFilename:
        Mx.libOrBib(outputFilename, 0)
        updateStatusBar(
            str(listbox.size()) + " records written to file\n" +
            outputFilename + "\nin bibliography format")
    else:
        updateStatusBar("error selecting file.")
コード例 #17
0
ファイル: altro.py プロジェクト: chadchabot/Altro
def getEnvVar():
	tempFileName = os.environ[ 'MXTOOL_XSD' ]
	if len( tempFileName ) == 0:
		xsdFile = tkFileDialog.askopenfilename( title="Open XSD schema file", filetypes=[ ("XSD file", "*.xsd"), ("All files", "*")], initialdir="./" )
		os.environ[ 'MXTOOL_XSD' ] = str( xsdFile )
		print os.environ[ 'MXTOOL_XSD' ]
		updateStatusBar( Mx.getEnvVar( str( xsdFile ) ) )
コード例 #18
0
ファイル: altro.py プロジェクト: chadchabot/Altro
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." )
コード例 #19
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)
コード例 #20
0
ファイル: altro.py プロジェクト: chadchabot/Altro
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." )
コード例 #21
0
ファイル: altro.py プロジェクト: kevintran1989/projects
	def saveasCommand(self):
		if (self.display.size() > 0):
			newfile = asksaveasfilename(defaultextension=".xml")
			self.status = Mx.writeFile(newfile, self.collection, self.index)
			if (self.nrecs2 != 0):
				self.label.config(text="Records Saved: " +str(self.nrecs2))
			else:
				self.label.config(text="Records Saved: "+str(self.nrecs))
		else:
			tkMessageBox.showerror("Error", "Display is empty - No XML File is open")
コード例 #22
0
ファイル: altro.py プロジェクト: chadchabot/Altro
def saveAs():
	outputFilename = tkFileDialog.asksaveasfilename(title="Save file as:", filetypes=[("XML files", "*.xml"), ("All Files", "*")], initialdir="./")
	if len( outputFilename) == 0:
		#	catch the cancel/ESCAPE key entered
		updateStatusBar( "no file selected" )
	elif outputFilename:
		reclist = [ 0, 1 ]
		recordsWritten = Mx.writeFile( outputFilename, reclist )
		updateStatusBar( str( recordsWritten ) + " records written to file " + outputFilename)
	else:
		updateStatusBar( "error selecting file." )
コード例 #23
0
ファイル: altro.py プロジェクト: SameerAlmutairi/Altro
def getEnvVar():
    tempFileName = os.environ['MXTOOL_XSD']
    if len(tempFileName) == 0:
        xsdFile = tkFileDialog.askopenfilename(title="Open XSD schema file",
                                               filetypes=[("XSD file",
                                                           "*.xsd"),
                                                          ("All files", "*")],
                                               initialdir="./")
        os.environ['MXTOOL_XSD'] = str(xsdFile)
        print os.environ['MXTOOL_XSD']
        updateStatusBar(Mx.getEnvVar(str(xsdFile)))
コード例 #24
0
def append(): #same as insert, but adds records to the end of the display
  status('Inserting more record files to the end')
  global recPtr
  global numRecs
  fileName = tkinter.filedialog.askopenfilename(title="Open XML File", filetypes=[("XML files", "*.xml")])
  
  if len(fileName) != 0:
    beforeAppend = numRecs
    value, recPtr, numRecs = Mx.append(fileName, recPtr)
    
    if numRecs > 0:
      status( str(numRecs - beforeAppend) + ' records appended. ' + str(numRecs) + ' total records')
    else:
      status( 'Failed to append xml file' )  
      
    display.delete(0, END)
    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)  
コード例 #25
0
def insert():
  global recPtr
  global numRecs
  status('Inserting more record files to the beginning')
  fileName = tkinter.filedialog.askopenfilename(title="Open XML File", filetypes=[("XML files", "*.xml")])
  
  if len(fileName) != 0: #check if a file was actually selected to prevent empty calls
    beforeInsert = numRecs
    value, recPtr, numRecs = Mx.insert(fileName, recPtr)
    
    if numRecs > 0:
      status( str(numRecs - beforeInsert) + ' records inserted. ' + str(numRecs) + ' total records')
    else:
      status( 'Failed to insert xml file' )
    
    display.delete(0, END)
    
    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)   
コード例 #26
0
ファイル: altro.py プロジェクト: kevintran1989/projects
	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)
コード例 #27
0
ファイル: altro.py プロジェクト: SameerAlmutairi/Altro
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)
コード例 #28
0
ファイル: altro.py プロジェクト: kevintran1989/projects
	def bibCommand(self):
		if (self.display.size() > 0):
			self.newfile = asksaveasfilename(defaultextension=".txt")
			temp = tempfile.NamedTemporaryFile(delete=False)
			self.status = Mx.writeTemp(temp.file, self.collection)
			temp.close()
			tstr = './mxtool'+' '+'-bib'+' '+'<'+' '+temp.name+' '+'>'+' '+self.newfile
			os.system(tstr)
			if (self.nrecs2 != 0):
				self.label.config(text="Records saved as -lib format: " +str(self.nrecs2))
			else:
				self.label.config(text="Records saved as -lib format: "+str(self.nrecs))
			os.unlink(temp.name)
		else:
			tkMessageBox.showerror("Error", "No XML File Open")
コード例 #29
0
ファイル: altro.py プロジェクト: SameerAlmutairi/Altro
def saveAs():
    outputFilename = tkFileDialog.asksaveasfilename(title="Save file as:",
                                                    filetypes=[
                                                        ("XML files", "*.xml"),
                                                        ("All Files", "*")
                                                    ],
                                                    initialdir="./")
    if len(outputFilename) == 0:
        #	catch the cancel/ESCAPE key entered
        updateStatusBar("no file selected")
    elif outputFilename:
        reclist = [0, 1]
        recordsWritten = Mx.writeFile(outputFilename, reclist)
        updateStatusBar(
            str(recordsWritten) + " records written to file " + outputFilename)
    else:
        updateStatusBar("error selecting file.")
コード例 #30
0
ファイル: altro.py プロジェクト: SameerAlmutairi/Altro
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
コード例 #31
0
ファイル: altro.py プロジェクト: chadchabot/Altro
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
コード例 #32
0
  global numRecs
  status('Deleting Selected Records')
  items = display.curselection() #get indexes of selected items
  offset = 0
  deleted = 0
  #loop through selected items and delete
  for i in items:  
    index = int(i) - offset
    display.delete(index,index)
    offset = offset + 1
    deleted = deleted + 1
    numRecs = numRecs - 1
  status( str(deleted) + ' records deleted.' + str(numRecs) + ' left in total')	
	  
  
value = Mx.init()
if value == 0:
  status('Schema Validated')
else:
  status('Failed to Validate Schema')

menu = Menu(root)
root.config(menu = menu)

# Adding 'File' tab
menuBar = Menu(menu)
menu.add_cascade(label= 'File', menu = menuBar)

menuBar.add_command(label = 'Open', command = Open)
menuBar.add_command(label = 'Insert', command = insert)
menuBar.add_command(label = 'Append', command = append)
コード例 #33
0
def exit():
  choice = tkinter.messagebox.askyesno(title="", message = 'Exit? All unsaved data will be lost.')
  if choice == 1:	
    value = Mx.term()
    quit()
コード例 #34
0
ファイル: altro.py プロジェクト: chadchabot/Altro
		#	show query window
		queryWindow.deiconify()


#-------------------    start the GUI code  -------------------#
min_x = 475
min_y = 380

#root = Tk()
root.title( "altro" )
root.minsize( min_x, min_y )
#           width, height, x-pos, y-pos
root.geometry( "1024x768+10+10" )


Mx.init()

# create a toolbar
toolbar = Frame(root)

menubar = Menu( root )

#   this creates a menu tied to the top of the screen
#   FILE menubar item
filemenu = Menu( menubar, tearoff = 0 )
filemenu.add_command ( label = "Open", command = openFile )
filemenu.add_command ( label = "Insert", command = insertFile )
filemenu.add_command ( label = "Append", command = appendFile )
filemenu.add_command ( label = "Save as…", command = saveAs )
filemenu.add_separator()
filemenu.add_command ( label = "Exit", command = exitApp )
コード例 #35
0
ファイル: altro.py プロジェクト: kevintran1989/projects
	except:
	  print "Could Not Connect to Database"
else:
	print "No Username Provided"

if (dbConnect == 1):
	root = Tk()
	root.minsize(width=740, height=270)
	root.title(string="Altro")
	root.option_add('*font', 'Helvetica -12')
	m = MainWindow(root, QueryWindow(root))
	root.config(menu=m)

	MXTOOL_XSD = os.getenv("MXTOOL_XSD")
	while True:
		status = Mx.init()	#initilize libxml2
		if (status != 0):
			result = tkMessageBox.askyesno("Warning!", "No XSD environment variable found. Do you wish to set a variable?", icon="warning")
			if result is True:
				schema = askopenfilename(filetypes=[("XSD Files",".xsd")])
				os.putenv("MXTOOL_XSD", schema)
				os.system("make mxtool")
			else: 
				break
		else:
			break
	if (status != 0):
		quit()
		
	#try: create table bibrec - will throw exception if table is already created make sure to commit
	conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
コード例 #36
0
ファイル: altro.py プロジェクト: SameerAlmutairi/Altro
    if queryWindow.state() == "withdrawn":
        #	show query window
        queryWindow.deiconify()


#-------------------    start the GUI code  -------------------#
min_x = 475
min_y = 380

#root = Tk()
root.title("altro")
root.minsize(min_x, min_y)
#           width, height, x-pos, y-pos
root.geometry("1024x768+10+10")

Mx.init()

# create a toolbar
toolbar = Frame(root)

menubar = Menu(root)

#   this creates a menu tied to the top of the screen
#   FILE menubar item
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Open", command=openFile)
filemenu.add_command(label="Insert", command=insertFile)
filemenu.add_command(label="Append", command=appendFile)
filemenu.add_command(label="Save as…", command=saveAs)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=exitApp)