def appendButton(): if len(cardList) != 0: filename = askopenfilename(filetypes = [("All Files", "*.*"), ("Vcard Files", "*.vcf")]) tempCard = [] if filename == "": return else: status = Vcf.readFile(filename) if status[0] == 'OK': if status[2] == 0: top = Toplevel() top.title("Error") top.geometry('250x100+500+360') top.bind('<Escape>', lambda e: closeWindow(top)) msg = Message(top, text = 'No Cards found in file', width = 200) msg.pack(expand = YES) button = Button(top, text = "Cancel", command = top.destroy) button.pack() noCardString = "File " + filename + " opened successfully but has no Vcards\n" insertText(noCardString) else: for i in range(status[2]): tempCard = Vcf.getCard() cardList.append(tempCard) backupList.append(tempCard) updateFileView() mlb.selection_set(0) updateCardView() else: fileError = "Error reading file " + filename + " with the following errors " + str(status) insertText(fileError)
def canon(self): bashcommand = "./vcftool -canon < " + self.currentFile + " | cat > temp.vcf" os.system(bashcommand) #reload the file status = Vcf.readFile("temp.vcf") self.cardList = [] if (status == "OK"): while(True): card = [] status = Vcf.getCard(card) if (status == "OK"): self.cardList.append(card) else: break; else: self.addToLog("Error opening the file") #free the shared object now if len(self.cardList) > 1: Vcf.freeFile() #clear FVP and CVP self.loadFVP() self.fileList.selection_set(0) self.loadCVP("") mainWindow.addToLog(self,"canon")
def appendingFile(self,theFile): status = Vcf.readFile(theFile) if (status == "OK"): while(True): card = [] status = Vcf.getCard(card) if (status == "OK"): self.cardList.append(card) else: break; else: self.addToLog(self,"Error opening the file you selected") if len(self.cardList) > 1: Vcf.freeFile() #clear FVP and CVP self.loadFVP() self.fileList.selection_set(0) event = Event() self.loadCVP(event)
def saveProg(): global cards if (filepath): Vcf.writeFile(filename, cards) else: saveAsProg()
def save(self): if(self.currentFile == ""): self.addToLog("Please choose the Save As option") else: #self.commit() Vcf.writeFile(self.currentFile,self.cardList) self.saveWin.destroy()
def openingFile(self, theFile): status = Vcf.readFile(theFile) self.currentFile = theFile self.cardList = [] if (status == "OK"): while(True): card = [] status = Vcf.getCard(card) if (status == "OK"): self.cardList.append(card) else: break; else: self.addToLog("Error opening the file you selected") root.title(os.path.basename(theFile)) #free the shared object now #there's a bug somewhere, files of size one segfault when being freed if len(self.cardList) > 1: Vcf.freeFile() #Enable menu items self.filemenu.entryconfig(1,state = NORMAL) self.filemenu.entryconfig(2,state = NORMAL) self.filemenu.entryconfig(3,state = NORMAL) self.orgmenu.entryconfig(0, state = NORMAL, command = self.sort) self.orgmenu.entryconfig(1, state = NORMAL, command = self.canon) self.orgmenu.entryconfig(2, state = NORMAL, command = self.select) self.datamenu.entryconfig(1, state = NORMAL) self.datamenu.entryconfig(0,state = NORMAL) self.datamenu.entryconfig(3, state = NORMAL) #clear FVP and CVP self.loadFVP() self.fileList.selection_set(0) event = Event() self.loadCVP(event) bashcommand = "./vcftool -info < " + self.currentFile + " | cat > info.txt" os.system(bashcommand) file = open("info.txt","r") self.addToLog(file.read()) file.close()
def openFile(self,append="FALSE"): if not self.upToDate: if not askyesno("Continue?","Discard uncommitted changes?"): return else: self.revertChanges() if self.filename == "xvcf" and append != "FALSE": return openFile = filedialog.askopenfilename() if not openFile: self.writeLogBox("No file selected.\n") return self.filename = openFile status = Vcf.readFile(openFile) if (status != 0): showerror("Error.","No cards could be found in that file."); self.writeLogBox("Failed to read file, error: ") self.writeLogBox(str(status) + '\n') self.writeLogBox(openFile + '\n') return else: if append == "FALSE": self.writeLogBox("Succesfully opened file.\n") else: self.writeLogBox("Succesfully appended file.\n") self.writeLogBox(openFile + '\n') self.filemenu.entryconfig(2,state=NORMAL) self.datamenu.entryconfig(0,state=NORMAL) self.datamenu.entryconfig(1,state=NORMAL) self.upToDate = 1 self.fvp_mlb.delete(0,END) #clearfvp self.cvp_mlb.delete(0,END) #clearcvp self.mainArea.title(openFile) if append == "FALSE": self.cardList = [] card = [] p = 0 i = 0 while (p == 0): p = Vcf.getCard(card) if (p == 0): self.cardList.append(card) i = i + 1 card = [] self.revert = copy.deepcopy(self.cardList) self.fileIndex = 0 self.writeFVP() self.writeCVP(self.cardList[0]) self.fvp_mlb.selection_set(0) self.cvp_mlb.selection_set(0)
def saveandquit(self): if(self.currentFile == ""): self.addToLog("Please choose the Save As option") else: if self.currentFile == "Database": self.storeAll() else: #self.commit() Vcf.writeFile(self.currentFile,self.cardList) os.remove("temp.vcf") self.db.close() killServers() sys.exit()
def openFile(): global cardList global filen global fileIndex global revert global com if not com: if not askyesno("Continue?","Discard uncommitted changes?"): return openFile = filedialog.askopenfilename() filen = openFile if not openFile: writeLogBox("No file selected.\n") return status = Vcf.readFile(openFile) if (status != 0): showerror("Error.","No cards could be found in that file."); writeLogBox("Failed to read file, error: ") writeLogBox(status) writeLogBox("\n") writeLogBox(openFile) writeLogBox("\n") return writeLogBox("Succesfully opened file.\n") writeLogBox(openFile) writeLogBox("\n") menubar.entryconfig(1,state=NORMAL) mlb.delete(0,END) ml2.delete(0,END) tk.title(openFile) cardList = [] card = [] p = 0 i = 0 while (p == 0): p = Vcf.getCard(card) if (p == 0): cardList.append(card) i = i + 1 card = [] revert = list(cardList) fileIndex = 0 writeFVP(cardList) writeCVP(cardList[0]) com = 1
def openButton(): global backupList if os.path.exists("output.txt"): os.remove("output.txt") filename = askopenfilename(filetypes=[("All Files", "*.*"), ("Vcard Files", "*.vcf")]) tempCard = [] if filename == "": return else: status = Vcf.readFile(filename) if status[0] == "OK": if status[2] == 0: top = Toplevel() top.title("Error") top.geometry("250x100+500+360") top.bind("<Escape>", lambda e: closeWindow(top)) msg = Message(top, text="No Cards found in file", width=200) msg.pack(expand=YES) button = Button(top, text="Cancel", command=top.destroy) button.pack() noCardString = "File " + filename + " opened successfully but has no Vcards\n" insertText(noCardString) else: info = "INFO:\n" + str(status[1]) insertText(info) root.title(filename) if cardList != []: del cardList[:] for i in range(status[2]): tempCard = Vcf.getCard() cardList.append(tempCard) backupList.append(tempCard) updateFileView() mlb.selection_set(0) updateCardView() else: fileError = "Error reading file " + filename + " with the following errors " + str(status) insertText(fileError)
def saveFile(): global cardList global com if not com: if not askyesno("Continue?","Discard uncommitted changes?"): return out = Vcf.writeFile(filen,cardList) if not out: writeLogBox("Can not save empty file.\n") else: writeLogBox("Saved file.\n") writeLogBox(filen) writeLogBox("\n")
def getsavename(): saven = entry.get() if not saven: writeLogBox("Please enter a file name.\n") return if os.path.isfile(saven): if not askokcancel("Overwrite?","Are you sure you want to overwrite the selected file?"): return global cardList global filen global com out = Vcf.writeFile(saven,cardList) if not out: writeLogBox("Can not save empty file.\n") else: writeLogBox("Saved file.\n") writeLogBox(saven) writeLogBox("\n") tk.title(saven) filen = saven savewin.destroy()
def saveFile(self,saveAs = "FALSE"): if not self.upToDate: if not askyesno("Continue?","Discard uncommitted changes?"): return else: self.revertChanges() if not self.cardList: self.writeLogBox("Can not save empty file.\n") return self.filemenu.entryconfig(2,state=NORMAL) if saveAs == "TRUE": oldfilename = self.filename self.filename = filedialog.asksaveasfilename() if not self.filename: self.filename = oldfilename self.writeLogBox("No file selected.\n") return self.mainArea.title(self.filename) out = Vcf.writeFile(self.filename,self.cardList) #print (out) self.writeLogBox("Saved file.\n") self.writeLogBox(self.filename + "\n")
def selectProg(): global filename global filepath global cards selectionWindow = Toplevel(root) selectionWindow.title("Select") pSel = IntVar() gSel = IntVar() uSel = IntVar() selButton = IntVar() photoSel = Checkbutton(selectionWindow, text="Photo", variable=pSel, onvalue= 1, offvalue=0) geoSel = Checkbutton(selectionWindow, text="Geo", variable=gSel, onvalue= 1, offvalue=0) urlSel = Checkbutton(selectionWindow, text="Url", variable=uSel, onvalue= 1, offvalue=0) photoSel.pack() geoSel.pack() urlSel.pack() selButton = Button(selectionWindow, text="Ok", command=lambda:selectionWindow.destroy(),width=10) selButton.pack() selectionWindow.geometry('200x150+300+300') selectionWindow.grab_set() selectionWindow.transient(root) selectionWindow.wait_window() #print("got psel, gsel, usel as:", pSel.get(), gSel.get(), uSel.get()) selOptions = "" if (pSel.get() == 1): selOptions += "p" if (uSel.get() == 1): selOptions += "u" if (gSel.get() == 1): selOptions += "g" #print("sel options are", selOptions) openF = open(filepath) #print("./vcftool -select " + selOptions + " < " + filepath + " > selectFile.vcf 2> logfile.txt") #sort the cards os.system("./vcftool -select " + selOptions + " < " + filepath + " > selectFile.vcf 2> logfile.txt") selectPath = os.getcwd() selectPath += "/selectFile.vcf" #get the path name logText.insert(tkinter.INSERT, "Selecting cards\n") #delete hlists of old list of cards filePanel.delete_all() cardPanel.delete_all() readSelect = Vcf.readFile(selectPath)#call reading the file from its path #print(readSelect) os.system("./vcftool -info < " + selectPath + " > log.txt")#call the info on the cards #read log text into the log window with open('log.txt', 'r') as content_file: content = content_file.read() logText.insert(END, content) #insert it logText.see(END) sCard = [] sCards = [] i = 0 while sCard != None: #get the cards in a loop sCard = [] #reset the card list sCard = Vcf.getCard(sCard) #print("Scard = ", sCard) if sCard != None: sCards.append(sCard) i = i + 1 snumCards = i i = 0 for cursCard in sCards: j = 0 name = 0 adr = 0 tel = 0 uid = 0 photo = 0 geo = 0 url = 0 flagText = "" if cursCard != None: #FIXTAG, added this to avoid a traceback for sprop in cursCard: if (j == 0): filePanel.add(i, itemtype=tkinter.tix.TEXT, data=i+1, text=i+1) if sprop[0] == 3 and name == 0: #3 means name #place the value into the proper column filePanel.item_create(i, 1, itemtype=tkinter.tix.TEXT, text=sprop[3]) name += 1 elif sprop[0] == 3: name += 1 if sprop[0] == 8: #8 means adr whole = sprop[3].split(";") region = "" if len(whole) > 4: region = sprop[3].split(";")[4] #get region if len(region) == 0: #if not region set to none region = "None" country = "" if len(whole) > 6: country = sprop[3].split(";")[6] #get country if len(country) == 0: #if no country set to NOne country = "None" filePanel.item_create(i, 2, itemtype=tkinter.tix.TEXT, text=region) filePanel.item_create(i, 3, itemtype=tkinter.tix.TEXT, text=country) adr += 1; if sprop[0] == 10: #10 means telephone tel += 1; if sprop[0] == 16: #16 means uid uid = 1; if sprop[0] == 6:#got photo photo = 1; if sprop[0] == 12: #got geo geo = 1; if sprop[0] == 17: #got url url = 1; j += 1 #increment property position filePanel.item_create(i, 4, itemtype=tkinter.tix.TEXT, text=adr) filePanel.item_create(i, 5, itemtype=tkinter.tix.TEXT, text=tel) if uid == 1: flagText += "C" else: flagText += "-" if name > 1: flagText += "M" else: flagText += "-" if url == 1: flagText += "U" else: flagText += "-" if photo == 1: flagText += "P" else: flagText += "-" if geo == 1: flagText += "G" else: flagText += "-" filePanel.item_create(i, 6, itemtype=tkinter.tix.TEXT, text=flagText) i += 1 #increment card position revertPath = filepath #make a backup orgmenu.entryconfig(3, state=NORMAL) filepath = selectPath #set this as the new file were working with cards = sCards
def canonProg(): global filename global filepath global cards openF = open(filepath) #sort the cards os.system("./vcftool -canon < " + filepath + " > canonFile.vcf 2> logfile.txt") canonPath = os.getcwd() canonPath += "/canonFile.vcf" #get the path name logText.insert(tkinter.INSERT, "Canonicalizing cards\n") #delete hlists of old list of cards filePanel.delete_all() cardPanel.delete_all() readCanon = Vcf.readFile(canonPath)#call reading the file from its path #print("read status = ", readCanon) os.system("./vcftool -info < " + canonPath + " > log.txt")#call the info on the cards #read log text into the log window with open('log.txt', 'r') as content_file: content = content_file.read() logText.insert(END, content) #insert it logText.see(END) sCard = [] sCards = [] i = 0 while sCard != None: #get the cards in a loop sCard = [] #reset the card list sCard = Vcf.getCard(sCard) #print("Scard = ", sCard) if sCard != None: sCards.append(sCard) i = i + 1 snumCards = i i = 0 for cursCard in sCards: j = 0 name = 0 adr = 0 tel = 0 uid = 0 photo = 0 geo = 0 url = 0 flagText = "" if cursCard != None: #FIXTAG, added this to avoid a traceback for sprop in cursCard: if (j == 0): filePanel.add(i, itemtype=tkinter.tix.TEXT, data=i+1, text=i+1) if sprop[0] == 3 and name == 0: #3 means name #place the value into the proper column filePanel.item_create(i, 1, itemtype=tkinter.tix.TEXT, text=sprop[3]) name += 1 elif sprop[0] == 3: name += 1 if sprop[0] == 8: #8 means adr whole = sprop[3].split(";") region = "" if len(whole) > 4: region = sprop[3].split(";")[4] #get region if len(region) == 0: #if not region set to none region = "None" country = "" if len(whole) > 6: country = sprop[3].split(";")[6] #get country if len(country) == 0: #if no country set to NOne country = "None" filePanel.item_create(i, 2, itemtype=tkinter.tix.TEXT, text=region) filePanel.item_create(i, 3, itemtype=tkinter.tix.TEXT, text=country) adr += 1; if sprop[0] == 10: #10 means telephone tel += 1; if sprop[0] == 16: #16 means uid uid = 1; if sprop[0] == 6:#got photo photo = 1; if sprop[0] == 12: #got geo geo = 1; if sprop[0] == 17: #got url url = 1; j += 1 #increment property position filePanel.item_create(i, 4, itemtype=tkinter.tix.TEXT, text=adr) filePanel.item_create(i, 5, itemtype=tkinter.tix.TEXT, text=tel) if uid == 1: flagText += "C" else: flagText += "-" if name > 1: flagText += "M" else: flagText += "-" if url == 1: flagText += "U" else: flagText += "-" if photo == 1: flagText += "P" else: flagText += "-" if geo == 1: flagText += "G" else: flagText += "-" filePanel.item_create(i, 6, itemtype=tkinter.tix.TEXT, text=flagText) i += 1 #increment card position revertPath = filepath #make a backup orgmenu.entryconfig(3, state=NORMAL) filepath = canonPath cards = sCards
def saveAsProg(): savepath = filedialog.asksaveasfilename(initialfile = filename) Vcf.writeFile(savepath, cards);
def savingFile(self,theFile): self.currentFile = theFile Vcf.writeFile(self.currentFile,self.cardList)
def openProg(): global filepath global filename global cards global reverting if (reverting == 0): filepath = filedialog.askopenfilename(parent=root)#get filepath fileList = re.findall('[^/]*$', filepath) #find the file name specifically filename = fileList[0] #place filename in variable else: reverting = 0 orgmenu.entryconfig(3, state=DISABLED) numCards = 0 filePanel.delete_all() cardPanel.delete_all() readF = Vcf.readFile(filepath)#call reading the file from its path #print(readF) #this updates the log Display openF = open(filepath) #execute the vcftool -info command to the file we are reading cmd = subprocess.Popen(["./vcftool", "-info"], stdin=openF, stdout=subprocess.PIPE) cmd_out, cmd_err = cmd.communicate() #get the stdout openF.close() #close the filepath logText.insert(tkinter.INSERT, cmd_out) #insert the output to the log text #enable save, save as and append options filemenu.entryconfig(1, state=NORMAL) filemenu.entryconfig(2, state=NORMAL) filemenu.entryconfig(3, state=NORMAL) #enable organization buttons orgmenu.entryconfig(0, state=NORMAL) orgmenu.entryconfig(1, state=NORMAL) orgmenu.entryconfig(2, state=NORMAL) #this populates the file view card = [] cards = [] i = 0 while card != None: #get the cards in a loop card = [] #reset the card list card = Vcf.getCard(card) #print("card = ", card) if card != None: cards.append(card) i = i + 1 numCards = i #print("num cards = ", numCards) i = 0 for curCard in cards: j = 0 name = 0 adr = 0 tel = 0 uid = 0 photo = 0 geo = 0 url = 0 flagText = "" if curCard != None: #FIXTAG, added this to avoid a traceback for prop in curCard: if (j == 0): filePanel.add(i, itemtype=tkinter.tix.TEXT, data=i+1, text=i+1) if prop[0] == 3 and name == 0: #3 means name #place the value into the proper column filePanel.item_create(i, 1, itemtype=tkinter.tix.TEXT, text=prop[3]) name += 1 elif prop[0] == 3: name += 1 if prop[0] == 8: #8 means adr whole = prop[3].split(";") region = "" if len(whole) > 4: region = prop[3].split(";")[4] #get region if len(region) == 0: #if not region set to none region = "None" country = "" if len(whole) > 6: country = prop[3].split(";")[6] #get country if len(country) == 0: #if no country set to NOne country = "None" filePanel.item_create(i, 2, itemtype=tkinter.tix.TEXT, text=region) filePanel.item_create(i, 3, itemtype=tkinter.tix.TEXT, text=country) adr += 1; if prop[0] == 10: #10 means telephone tel += 1; if prop[0] == 16: #16 means uid uid = 1; if prop[0] == 6:#got photo photo = 1; if prop[0] == 12: #got geo geo = 1; if prop[0] == 17: #got url url = 1; j += 1 #increment property position filePanel.item_create(i, 4, itemtype=tkinter.tix.TEXT, text=adr) filePanel.item_create(i, 5, itemtype=tkinter.tix.TEXT, text=tel) if uid == 1: flagText += "C" else: flagText += "-" if name > 1: flagText += "M" else: flagText += "-" if url == 1: flagText += "U" else: flagText += "-" if photo == 1: flagText += "P" else: flagText += "-" if geo == 1: flagText += "G" else: flagText += "-" filePanel.item_create(i, 6, itemtype=tkinter.tix.TEXT, text=flagText) i += 1 #increment card position Vcf.freeFile()
def getoptions(self): options = "" if self.photoChecked.get() == 1: options = options + "p" if self.geocheck.get() == 1: options = options + "g" if self.urlcheck.get() == 1: options = options + "u" bashcommand = "./vcftool -select " + options + " < " + self.currentFile + " | cat > temp.vcf" os.system(bashcommand) #Check if temp.vcf is empty check = os.stat("temp.vcf").st_size if check == 0: self.nope = Toplevel() self.nope.title("Warning") self.nope.bind("<Escape>", lambda e: self.destroyWin(e.widget)) self.nope.geometry("300x100") Label(self.nope,text="Selection will not return any results").pack(side=TOP) Button(self.nope,text="OK", command = self.nope.destroy).pack(side=TOP) self.nope.focus_set() self.nope.transient(root) self.nope.grab_set() root.wait_window(self.nope) return "break" else: #reload the file status = Vcf.readFile("temp.vcf") self.cardList = [] if (status == "OK"): while(True): card = [] status = Vcf.getCard(card) if (status == "OK"): self.cardList.append(card) else: break; else: self.addToLog("Error opening the file") if len(self.cardList) > 1: Vcf.freeFile() #clear FVP and CVP self.loadFVP() self.fileList.selection_set(0) self.loadCVP("") self.selwin.destroy()