|
From: Stas Z. <sta...@us...> - 2005-06-14 14:39:27
|
Update of /cvsroot/gmailagent/GA-libgmail2/frontend In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3009 Modified Files: GuiQTgcm.py Qgcm.py Log Message: Restore some errors Index: Qgcm.py =================================================================== RCS file: /cvsroot/gmailagent/GA-libgmail2/frontend/Qgcm.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Qgcm.py 14 Jun 2005 14:22:19 -0000 1.1 --- Qgcm.py 14 Jun 2005 14:39:01 -0000 1.2 *************** *** 20,28 **** import sys from qt import * ! import GuiQTgmc app = QApplication(sys.argv) ! w = GuiQTgmc.MainWin(application=app) app.setMainWidget(w) w.show() --- 20,28 ---- import sys from qt import * ! import GuiQTgcm app = QApplication(sys.argv) ! w = GuiQTgcm.MainWin(application=app) app.setMainWidget(w) w.show() Index: GuiQTgcm.py =================================================================== RCS file: /cvsroot/gmailagent/GA-libgmail2/frontend/GuiQTgcm.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GuiQTgcm.py 14 Jun 2005 14:22:19 -0000 1.1 --- GuiQTgcm.py 14 Jun 2005 14:39:00 -0000 1.2 *************** *** 3,7 **** # Copyright (c) 2005 Stas Zykiewicz <st...@li...> # ! # Contrgmc.py # # This program is free software; you can redistribute it and/or modify --- 3,7 ---- # Copyright (c) 2005 Stas Zykiewicz <st...@li...> # ! # GuiQTgmc.py # # This program is free software; you can redistribute it and/or modify *************** *** 20,197 **** ! CG_DEBUG = 1 ! import libgmail2,pickle ! def upload_local_contacts(addrfile,ga): ! """Returns the contacts from the local file which don't have a ID entry. ! Contacts without an ID are considered local only and must be added to the Gmail ! contacts list. ! This function is called whenever the user logs into Gmail. ! Returns error message on faillure, None on succes.""" ! if CG_DEBUG: logging.debug("\n>>>>>>>> Function: upload_local_contacts") ! contacts = load_addressfile(addrfile) ! for line in contacts: ! if CG_DEBUG: logging.debug("Found local contact %s %s %s %s" % line) ! if not line[3]: ! logging.debug("Adding %s %s %s %s to Gmail" % line) ! if not ga.addContact(line[0],line[1],line[2]):#libgmail2 checks for exception ! return ("Unable to add contact %s %s %s %s" % line) ! # Now we reload the contacts to create a new local contacts list ! #import_contacts(addrfile,ga) ! ! def store_address(addrfile,name,addr,notes='',id='',ga=None): ! """The contacts will be stored in the local copy on disk. ! If the id is given we assume the contact has a valid Gmail id and ! the contact is removed from the online contacts and replaced by the ! given contact. It will get a new id from Gmail. ! """ ! if CG_DEBUG: ! logging.debug("\n>>>>>>>> Function: store_address") ! logging.debug("store contact %s %s %s %s %s" % (name,addr,notes,id,ga)) ! if id and ga: ! if CG_DEBUG: logging.debug("Found id, removing original contact first") ! contacts = ga.getContacts() ! contact = contacts.getContactById(id) ! if contact: ! if not ga.removeContact(contact): ! logging.warning("Failed to remove contact %s" % contact) ! else: ! # Build the new local file with the contacts from Gmail ! import_contacts(addrfile,ga) ! # now we add the new contact to the local file ! store_address(addrfile,name,addr,notes) ! # And upload it to Gmail ! upload_local_contacts(addrfile,ga) ! # Retrieve Gmail contacts so that we have get an id for the new contact. ! import_contacts(addrfile,ga) ! # stuff is stored in a file like this: ! # name&&addr&¬es&&id ! # Contacts that are not (yet) in the Gmail contacts list have an empty ! # string as id. ! # After syncronizing the file with the contacts the id fields will be asigned. ! try: ! f = open(addrfile,'r') ! lines = f.readlines() ! f.close() ! except IOError,info: ! mesg = "Failed to check the address (IO), %s" % info ! if CG_DEBUG: logging.warning(mesg) ! return mesg ! else: ! for line in lines: ! if name in line and addr in line: ! return ! # It's a new entry ! line = "%s&&%s&&%s&&%s\n" % (name,addr,notes,id) ! if CG_DEBUG: logging.debug("Found new contact %s" % line) ! try: ! f = open(addrfile,'a') ! f.write(line) ! f.close() ! except IOError,info: ! f.close() ! mesg = "Failed to store address, %s" % info ! if CG_DEBUG: logging.warning(mesg) ! return mesg ! ! def load_addressfile(filename): ! if CG_DEBUG: logging.debug("\n>>>>>>>> Function: load_addressfile") ! try: ! f = open(filename,'r') ! lines = f.readlines() ! f.close() ! except IOError,info: ! if CG_DEBUG: logging.warning(str(info)) ! return ! if CG_DEBUG: logging.debug(str(lines)) ! newlines = [] ! for line in lines: ! newlines.append(tuple(line[:-1].split("&&"))) ! return (newlines) ! def import_contacts(addrfile,ga): ! """This gets the gmail contacts create a new local contacts list on disk.""" ! if CG_DEBUG: logging.debug("\n>>>>>>>> Function: import_contacts") ! upload_local_contacts(addrfile,ga) ! contacts = ga.getContacts().getAllContacts() ! logging.debug("Contacts imported:\n%s" % contacts) ! if contacts: ! # remove local file, we can remove it because the upload_local_contacts method will make sure ! # that the contacts are syncronized. ! logging.debug("Removing local file") ! open(addrfile,'w').close() ! else: ! return ! for obj in contacts: ! store_address(addrfile,\ ! obj.getName(),\ ! obj.getEmail(),\ ! obj.getNotes(),\ ! obj.getId()) ! return load_addressfile(addrfile) ! def export_contacts(addrfile,ga): ! """This will remove the contacts at the online contacts list and replace ! it with the local copy fom disk. ! It will return a message on any error. ! It returns None on succes.""" ! if CG_DEBUG: logging.debug("\n>>>>>>>> Function: export_contacts") ! entries = load_addressfile(addrfile) ! if len(entries) < 1: ! text = "Failed to load address file, %s" % addrfile ! if CG_DEBUG: logging.critical(text) ! return text ! try: ! contacts = ga.getContacts().getAllContacts() ! # Just to test save_contacts ! save_contacts(contacts) ! for contact in contacts: ! if CG_DEBUG: logging.debug("Removing contact %s", contact) ! ga.removeContact(contact) ! except Exception,info: ! logging.critical(str(info)) ! if contacts: ! save_contacts(contacts) ! return "An error occured, tried to save your contacts to\n%s and %s" %\ ! ('~/.GmailContacts.txt','~/.GmailContacts.pickle') ! # Now we fill the contacts list again from the local file. ! try: ! for entry in entries: ! if CG_DEBUG: logging.debug("Adding contact %s", entry) ! apply(ga.addContact,entry[:-1]) ! except Exception,info: ! logging.critical(str(info)) ! save_contacts(contacts) - def save_contacts(contacts): - # This is probably not needed anymore, if shelve turn out OK - """Save the contact in case of an error. This is an attempt to prevent - data loss in case of an error when interacting with Gmail contacts.""" - if CG_DEBUG: logging.debug("\n>>>>>>>> Function: save_contacts") - try: - f = open(os.path.expanduser('~/.GmailContacts.pickle'),'w') - pickle.dump(contacts,f) - ## XXX TODO: some way to load the pickled object and restore it - except Exception,info: - text = "Attempt to pickle the contacts %s" % str(info) - logging.critical(text) - f.close() - try: - f =open(os.path.expanduser('~/.GmailContacts.txt'),'w') - text = "#An error occured in GmailAgent and these contacts are saved\n"+\ - "#to this file in an attempt to save them\n"+\ - "#A contact is saved as follows:\n"+\ - "#GmailID Name email notes\n" - f.write(text) - for con in contacts: - name,email,notes,id = con.getName(),con.getEmail(),con.getNotes(),con.getId() - f.write("%s %s %s %s\n" % (con.getId(),\ - con.getName(),\ - con.getEmail(),\ - con.getNotes())) - f.close() - except Exception,info: - logging.critical(str(info)) - return str(info) - --- 20,96 ---- ! from qt import * ! from MainWinContacts_forms import FormMainWin ! from Observers import Observer,Observable ! ! class MainWin(FormMainWin,Observable): ! def __init__(self, parent=None, name=None, fl=0,att=[],application=None): ! FormMainWin.__init__(self,parent,name,fl) ! Observable.__init__(self) ! global Qapplication# Needed for a Qprogressdialog ! Qapplication = application ! self.show() ! self.Myobs = Observer(self.test) ! self.addObserver(self.Myobs) ! def test(self,*args): ! print "test called" ! print "args",args ! ! def editNewcontact_activated(self): ! print "FormMainWin.editNewcontact_activated(): Not implemented yet" ! def editEditcontact_activated(self): ! print "FormMainWin.editEditcontact_activated(): Not implemented yet" ! def editDeletecontact_activated(self): ! print "FormMainWin.editDeletecontact_activated(): Not implemented yet" ! ! def helpContents_activated(self): ! print "FormMainWin.helpContents_activated(): Not implemented yet" ! #This callback is used for testing purposes ! self.notifyObservers("this is data") ! ! def helpAbout_activated(self): ! print "FormMainWin.helpAbout_activated(): Not implemented yet" ! ! def pushButtonClose_clicked(self): ! print "FormMainWin.pushButtonClose_clicked(): Not implemented yet" ! ! def pushButtonCloseSave_clicked(self): ! print "FormMainWin.pushButtonCloseSave_clicked(): Not implemented yet" ! ! def listViewContacts_clicked(self,a0): ! print "FormMainWin.listViewContacts_clicked(QListViewItem*): Not implemented yet" ! ! def listViewContacts_doubleClicked(self,a0): ! print "FormMainWin.listViewContacts_doubleClicked(QListViewItem*): Not implemented yet" ! ! def contactsExportcontacts_activated(self): ! print "FormMainWin.contactsExportcontacts_activated(): Not implemented yet" ! ! def listViewContacts_pressed(self,a0): ! print "FormMainWin.listViewContacts_pressed(QListViewItem*): Not implemented yet" ! ! def listViewContacts_clicked(self,a0,a1,a2): ! print "FormMainWin.listViewContacts_clicked(QListViewItem*,const QPoint&,int): Not implemented yet" ! ! def lineEditSearchToolbar_textChanged(self,a0): ! print "FormMainWin.lineEditSearchToolbar_textChanged(const QString&): Not implemented yet" ! ! def contactsImportcontacts_activated(self): ! print "FormMainWin.contactsImportcontacts_activated(): Not implemented yet" ! ! def contactsSave_activated(self): ! print "FormMainWin.contactsSave_activated(): Not implemented yet" ! ! def contactsSaveAs_activated(self): ! print "FormMainWin.contactsSaveAs_activated(): Not implemented yet" ! ! def contactsPrintAction_activated(self): ! print "FormMainWin.contactsPrintAction_activated(): Not implemented yet" ! ! def contactsExit_activated(self): ! print "FormMainWin.contactsExit_activated(): Not implemented yet" |